Hi Dear,
I m trying to run a simple UART program on EZ USB FX2. This program continously transmits the char 'A'. This is compiling fine in Keil. But when I run it and see it on oscilloscope, the data rate is not exact what i have set it to 9600 baud. Moreover, the data bits and start stop bits are inverted . So I have to send inverted data (A xor 0xff) to get actual character A.
The program is as follows:
#define ALLOCATE_EXTERN
#include <fx2.h>
#include <fx2regs.h>
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 at
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