Mega8 USART problem

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

Hello,
I am trying to get the USART on a Mega8 to talk to my P.C. and
I'm having problems getting reliable data transmission. Sometimes
the data is correct and sometimes I get junk.

I am using a STK500 system and have the internal clock set for 3.696 MHZ
which is supposed to be a magic setting for 0% error on USART
transmission. However, when I scope the XTAL jumper I see 3.7014 MHZ
.This is about .1% error and should be OK I think.

I am using the code from AVR306 with the exception of adding the URSEL
bit for the shared register on the Mega8. I've checked the init section of
AVR303 which is targeted at the Mega8 and except for the interupt enable
bit it's the same. Since I'm using polled mode I think this should be OK too.

To go from reliable data to junk and back to reliable I cycle the power on
the STK500. About 1 out of 6 times the data is good. Scoping data bits
in both modes I see that the data rate is 19200 in both cases. I have tried
2 different P.C.'s as the data terminals with the same result.

Any ideas?

Thanks
Will

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

Magic number is 3.6864 or 7.3728 or 14.7456 Error less then a few 1/10s pct should be ok

Imagecraft compiler user

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

Sorry, that was my mistake. The STK500 value is set at 3.686 Mhz. and is putting out 3.704Mhz.
The top end of the STK500's internal Osc. is 3.686 MHz, which I assume was chosen to allow
UART comm's to be debugged on the setup. The difference is small enough that I don't think it
is my problem, but I'm still at a loss to explain why my app doesn't work every time correctly.

Have I missed a bit setting somewhere that is getting set randomly with each power on?

Will

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

Problem solved!

During debug I modified the AVR306 app note code to send a string instead of echoing typed
characters. The Mega8 turns on so fast, and tries to send the string before the UART has time
to establish a NULL time as the start bit to the P.C.'s UART.

Changing the fuse to allow for slow OSC start up helped get the good/bad ratio to about 3/5.
Adding some delay before the Mega8 UART starts transmitting fixed the problem.
Putting the code back to echoing the received characters works like a champ.

The key thing I learned here is that the programmer must allow a NULL time on the UART TX
line to establish a frame start bit.

Will