I can’t find an emoticon for begging but this problem is driving me nuts;
So I have this board http://www.sparkfun.com/products/29, which I got after I thought my poor breadboard skills were creating the problem.
I’m using an atmega328p and running the code below in the hope that I can get some serial communication between the board and my PC, using the FTDI Basic Breakout (5V). The idea is that when I press a character on the keyboard the same character will be echoed in the terminal, currently this “kind of happens”. When I type say “v” I get “7”, though granted it is consistently wrong, vvvvvv = 777777.
#include <avr/io.h>
#define FOSC 8000000
#define BAUD 9600
#define BAUD_PRESCALE FOSC/16/BAUD-1
int main (void)
{
char ReceivedByte;
UCSR0B |= (1 << RXEN0) | (1 << TXEN0);
UCSR0C |= (1 << USBS0) | (1 << UCSZ00) | (1 << UCSZ01);
UBRR0H = (BAUD_PRESCALE >> 8);
UBRR0L = BAUD_PRESCALE;
for (;
{
while ((UCSR0A & (1 << RXC0)) == 0) {};
ReceivedByte = UDR0;
while ((UCSR0A & (1 << UDRE0)) == 0) {};
UDR0 = ReceivedByte;
}
}
--------------------------------------------------------------------------------------------------------------------------------------------
I’m using this code to debug my board because when I completed the Beginning Embedded Electronics, tutorial 5, all I continually got was garbage printed out on the terminal.
I’m guessing I’m not using the correct clock speed, baud rate and fuse bit combination, so I’d be really grateful if someone would tell me how I should set up the fuse bits for this chip if I were to use the external crystal (which says 8.000 on the top). The terminal is set at the correct settings as far as I can tell, to match the code baud, bit rate etc.
Any help greatly appreciated as this is driving me insane.