0
votes

I'm working with an ATMEGA8 chip which is part of a bigger board. I'm trying to set the correct baud rate but it seems it's not working.

The ATMEGA8 uses an external crystal oscillator of 3.6864Mhz. To sed the baud rate I use the following lines, as suggested in the datasheet:

#define F_CPU 3686400// Clock Speed
#define BAUD 19200
#define MYUBRR F_CPU/16/BAUD-1

With this configuration i measured times with an oscilloscope and I get a bitrate of 1000bps. Any suggestion?

Thanks in advance

1
How is MYUBRR used? I'd add at least parentheses in define. #define MYUBRR (F_CPU/16/BAUD-1). There is apparently also double rate flag in UART register (but it does not correspond to 19200 vs. 1000). Do you have correct fuses set - not to use internal oscillator. - TMa
what's the resulting value of MYUBRR, when you look it up in symbol table? - Deleted User
It's 11. It seems to be OK. - Aldridge1991

1 Answers

1
votes

The only way I can get your numbers to make any sense is if:

  • What you are measuring is the frame rate, and not the bit rate (10 bits in a typical frame)
  • U2X is set
  • The chip is set to use internal oscillator at factory default of 1 MHz clock

This would give baud = f / (8*(UBBR+1)) = 10^6 / (8*(11+1)) = 10417 baud, very close to 1000 frames per second.

Alernatively, it could be that you are not measuring correctly with the scope. Try to hook the chip up with an ftdi cable or similar and see if there is hole through.

I hope this can help in the troubleshooting.