Problem with UART

Jul 01, 2006 1 Replies

I m trying to run a simple UART program on EZ USB FX2. This progra continously transmits the char 'A'. This is compiling fine in Keil. Bu when I run it and see it on oscilloscope, the data rate is not exact wha i have set it to 9600 baud. Moreover, the data bits and start stop bit are inverted . So I have to send inverted data (A xor 0xff) to get actua character A. The program is as follows:



#define ALLOCATE_EXTERN #include #include



void init_uart(void){ SCON0 = 0x52; // 8 bit UART mode TMOD = 0x20; // Timer 1 initialized to mode 2 TH1 = 0xEC; // Reload value for 9600 baud rate a



48MHz clock T1M = 1; SMOD0 = 1; TR1 = 1; // Start the Timer 1 }

void main(void) { unsigned char a = 0x41; // Character A a = a ^ 0xff; // Invert the data init_uart(); while(1){ while(TI){ TI = 0; // Clear the overflow flag SBUF0 = a; // Put data onto tx reg } } }



Hope if someone can help me.



Thanks in advance



Best Regards Muhammad Imran



On Sat, 01 Jul 2006 10:35:16 -0500, "mimran" wrote in comp.arch.embedded:

What do you mean by inverted? Where are you looking at the signal?

On the serial data pins of the processor, a start bit is a 0, followed by the bits of the character from low to high. So 'A', 0x41, would look like this: 0100000101 | | start bit -------+ | | stop bit -----------------+

If you are looking at the signal on the other side of an RS232 driver, then it is inverted from this. The start bit will be high and the stop bit low.

What is the actual clock rate in to timer 1?

Jack Klein Home: http://JK-Technology.Com FAQs for comp.lang.c http://c-faq.com/ comp.lang.c++ http://www.parashift.com/c++-faq-lite/alt.comp.lang.learn.c-c++ http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required