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