UART problem - help needed

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
Woody
XCore Addict
Posts: 165
Joined: Wed Feb 10, 2010 2:32 pm

Post by Woody »

Berni wrote:The USART example on the xmos website has its baud rate slightly off in the high speeds. A slightly off baudrate typically results in large chunks of data not sending properly as the clock loses sync til the end.
Can you post a link to this please? I'd like to look at it.


User avatar
Berni
Respected Member
Posts: 363
Joined: Thu Dec 10, 2009 10:17 pm

Post by Berni »

Here it is : http://www.xmos.com/applications/comms/uart-two-threads

I remember i had problems using it at 115200 baud, then i tweaked the baud rate setting (Up i think) a little and it started to work reliably.
User avatar
otitov
XCore Addict
Posts: 207
Joined: Thu Dec 10, 2009 11:00 pm
Location: Mexico

Post by otitov »

@Woody: flow control was set to NONE (re-checked), sorry for misleading you.

I have linked the Arduino's Tx to the PC directly (via FT232 serial-to-usb-virtual com port) and check that it works OK.

I will try to make an echo test as you suggest.

@Berni: could you please provide more details on what could be done to tweak baudrade?

I use:

Code: Select all

#define BIT_RATE 9600
#define BIT_TIME XS1_TIMER_HZ / BIT_RATE
and

Code: Select all

t when timerafter(time) :> void;
approach.

Should I use smaller/bigger BIT_TIME value?
User avatar
leon_heller
XCore Expert
Posts: 546
Joined: Thu Dec 10, 2009 10:41 pm
Location: St. Leonards-on-Sea, E. Sussex, UK.

Post by leon_heller »

To check the baud rate accurately you could output 'U' continuously (alternating ones and zeros) and check the frequency with a counter.

This code of mine works OK at 115k:

http://www.xmoslinkers.org/node/347

Leon
User avatar
otitov
XCore Addict
Posts: 207
Joined: Thu Dec 10, 2009 11:00 pm
Location: Mexico

Post by otitov »

I am very ashamed - multimeter is all I have right now, please, give me some time to equip my lab! ;)
User avatar
leon_heller
XCore Expert
Posts: 546
Joined: Thu Dec 10, 2009 10:41 pm
Location: St. Leonards-on-Sea, E. Sussex, UK.

Post by leon_heller »

You could use some code on a spare thread, or a different board, to check the frequency. Of course, it won't show if the crystal is off-frequency if you use the same board, but it might help.
User avatar
Berni
Respected Member
Posts: 363
Joined: Thu Dec 10, 2009 10:17 pm

Post by Berni »

Tweak the BIT_RATE define a bit and see if it helps. It might be the same problem as i had at 115200. It could be the boards clock wrong all together or the code introducing a tiny delay that ruins the timing.
User avatar
Woody
XCore Addict
Posts: 165
Joined: Wed Feb 10, 2010 2:32 pm

Post by Woody »

leon_heller wrote:To check the baud rate accurately you could output 'U' continuously (alternating ones and zeros) and check the frequency with a counter.
That's a really great suggestion! And as Leon says, looping that round into another port will allow you to time it.

If there is a problem with the clock setup it's likely to be by orders of magnitude rather than 5% out, so getting an LED to flash once a second allows you to check this with a stopwatch.
User avatar
Berni
Respected Member
Posts: 363
Joined: Thu Dec 10, 2009 10:17 pm

Post by Berni »

Well sometime il get my XLogic project done, then you will be able to turn one thread on a xmos chip in to a logic analyzer.
User avatar
Woody
XCore Addict
Posts: 165
Joined: Wed Feb 10, 2010 2:32 pm

Post by Woody »

In response to Berni's comments about the UART, I reviewed the UART code on xmos.com. I thought had rather a lot of non UART related code in it, so I've changed it. You can see the new code here http://www.xmos.com/applications/comms/uart

There are two UART implementations: a simple two thread implementation based on the example in 2.5 of 'Programming XC on XMOS Devices' (http://www.xmos.com/system/files/xcuser_en.pdf); and a single thread implementation. These are simple implementations, designed to demonstrate how a UART can be implemented. Any additional features or interface solutions should be easy to add for your application.