Weird characters coming from UART0

mcufan wrote on Wednesday, May 01, 2013:


I am trying to use comtest.c and/or comtest_strings.c on an LPC2138 to send and receive bytes via UART0. I modified the Rx task to accept any string and receiving characters seems to work, at least when I type something in the hyperterminal the LED flashes. However if I check whether the received byte is eg. ‘A’ then toggle a LED, then it won’t light up. It means somehow it received something else than what was sent from my PC.
I think I have the same problem with the Tx task: although I set it to transmit the ‘ABC’ string it seems to transmit some garbage to my PC’s COM port: mostly the following bytes: 0xC3 and 0xBE but sometimes something else. I have 19200 baud rate, 8-N-1 configured on both my PC and in FreeRTOS.
The hardware clearly works, because when I download a demo firmware it nicely transmits strings and can even echo my typed characters back.
What do you think can cause such strange behaviour? I also have a higher priority task running: it periodically resets an external watchdog hardware. But I don’t think that would interfere as it runs only ever second.

richard_damon wrote on Thursday, May 02, 2013:

My guess is that you have the baud rate set wrong, perhaps because you have the clock rate set wrong. I bet if you look at the serial port for transmit with a scope the bit time is off.

mcufan wrote on Thursday, May 02, 2013:

Hi richard_damon,

It was indeed the frequency which was set incorrectly. I forgot to change it. I checked the XTAL frequency on the board, multiplied it by 4 (due to PLL) and set this value to configCPU_CLOCK_HZ in FreeRTOSConfig.h. Now it is working like a charm. Thank you very much for your help!