USART corruption

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

Newbie here,

I just finished reading a few tutorials regarding USARTs, clock and timer/counters. I wrote a small application for an ATXMEGA256A3 for grasping the different concepts.

The application basically sets the clock at 16mhz and runs a service every second. The service does nothing else than outputting debug info using the USART. USART is set at 115200 bps, 8 data bits, no parity, 1 stop bit.

Everything seems to be running fine except that some characters are not outputted correctly every now and then. What could potentially cause characters to be corrupted?

A few details...

According to the USART application notes, I set bsel_value to 31 and bscale_factor to -2.

#define USART_DRV_SET_BAUD_RATE(usart, bsel_value, bscale_factor) \
	(usart)->BAUDCTRLA = (uint8_t) bsel_value; \
	(usart)->BAUDCTRLB = (bscale_Factor << USART_BSCALE0_bp) | (bsel_value >> 8)

Normal output

../_src/engine/engine.c(67): 1 service(s) to execute.
../_src/service/metering/metering_svc.c(19): metering service executing...
../_src/service/metering/metering_svc.c(23): metering service execution terminated.

Example of corrupted output ("perminated" instead of "terminated")

../_src/engine/engine.c(67): 1 service(s) to execute.
../_src/service/metering/metering_svc.c(19): metering service executing...
../_src/service/metering/metering_svc.c(23): metering service execution perminated.

[edit] 115200 bps instead of 115000 (thanks fnadeau).

Last Edited: Tue. May 31, 2011 - 08:29 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

On an AVR running at 16Mhz, 115200(I guess you made a typo when you wrote 115000) is not recommended because of clock error is being to high. This is due to the clock divider capability. I suspect that on the XMega, same thing apply.

Try with a crystal that has a perfect divider(such has 14.7456 MHz) or try lower speed like 38400bps.

Best regards

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

Xmega has a lot more options for generating baud rate than regular AVRs. Have you looked at the xmega excel document for baud rate? It is also with the application note. With a 16mhz system clock, bscale at -2, and bsel at 31, you get a .79% error.

Try setting bscale to -7 and bsel to 983. This will result in 0.01% error which should fix any problem.

Is there anything connected to either of the Tx or Rx lines like an activity LED? Activity LEDs can cause corruption on the data lines if the resistor values are too low and they draw too much current.

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

38400bps gives good results so far. I tried setting bscale to -7 and bsel to 983 for a 0.01% error but still got corruption.

Thanks fnadeau for the tip about the 14.7456Mhz crystal.