ATMega16 usart @ 115200

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

hi.. can any1 help

i am not getting result when baud rate is set to 115200 or 19200
when test with realterm, a terminal program, it indicates error. But @9600 it is functioning good.
I am using AVR Studio for compiling source code.
using ATMega16 with F_CPU = 8 MHz. external crystal is selected

Last Edited: Fri. Feb 20, 2009 - 12:12 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I gather you're using the internal oscillator? If so, I'd suggest you get a crystal of ,say, 11.0592mhz.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What is F_CPU? For example at 2MHz then 9600 baud gives 0.2% error which is acceptable, while 19200 gives -7.0% and 115200 gives 8.5% which are not acceptable.

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
What is F_CPU? For example at 2MHz then 9600 baud gives 0.2% error which is acceptable, while 19200 gives -7.0% and 115200 gives 8.5% which are not acceptable.

Cliff

F_CPU is 8000000 hz and external crystal is selected

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So you look up the 8MHz baudrate table in your AVR data sheet. You will see if and how to get a satisfactory 115200 baud.

Or do the sums yourself.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

For 8MHz 9600=0.2%, 19200=0.2%, 115200=8.5%

So 115200 is never going to be achievable (not even using U2X=1 which is -3.5%)

But the mystery here is why 19200 does not work if 9600 does. My guess is that it's still on the internal oscillator and it's borderline on the 8MHz

Of course it's only ~8MHz anyway if UBRR=51 is what's delivering 9600 baud

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
For 8MHz 9600=0.2%, 19200=0.2%, 115200=8.5%

So 115200 is never going to be achievable (not even using U2X=1 which is -3.5%)

But the mystery here is why 19200 does not work if 9600 does. My guess is that it's still on the internal oscillator and it's borderline on the 8MHz

Of course it's only ~8MHz anyway if UBRR=51 is what's delivering 9600 baud

Cliff

UBRR=51 @9600 baud receive & transmit functions r working fine.
so what way 115200 baud can be achieved

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

so what way 115200 baud can be achieved

1) Don't use the internal oscillator. Use a crystal or resonator or other more accurate clock source.

2) When selecting the value (frequency) of the clock source, use a "magic frequency" for common UART baud rates such as 7.3728MHz.

3) If you insist on 8MHz, then don't use 115200bps, but rather use a non-standard speed such as 100000bps and tell the communications partner to use that as well.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am also trying to receive a 115K2 serial link running using an 8MHz extn Xtal, inconveniently that's 69.4 clocks. So not a power of 2, say 64 clks = 125K (8.5%) which won't work.

However, if you write your own 'bit blatted' serial interface, 69 clks = 115K94 (0.6%) or even 70 clks = 114K286 (-0.8%) that should be OK. It's a bit of a 'messy' solution and will take a lot of the CPU time polling the pin, but it might be a way of getting it running if you really need that speed and have CPU to spare ?

I am writing the receive routine Monday, if you think it's useful let me know and I'll post up the code early next week. Or hopefully someone else has already written this, if so I'd appreciate the code :)

<º))))><

I am only one lab accident away from becoming a super villain.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sure seems easier to me to use a proper speed crystal and a real USART. And a Mega164 with twin USARTs is less expensive than a Mega16 anyway.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
Quote:

so what way 115200 baud can be achieved

1) Don't use the internal oscillator. Use a crystal or resonator or other more accurate clock source.

2) When selecting the value (frequency) of the clock source, use a "magic frequency" for common UART baud rates such as 7.3728MHz.

3) If you insist on 8MHz, then don't use 115200bps, but rather use a non-standard speed such as 100000bps and tell the communications partner to use that as well.

Lee