I am trying to get data over UART serial on PC from Silicon Labs C8051f320
I usually program in Java so correct me if i am wrong somewhere with C language or MCUs understanding.
Here is my code that handles UART Interrupts
Unsigned char Byte;
unsigned char TX_Ready =1;
void UART0_Interrupt (void) interrupt 4{
if (RI0 == 1)// Check if Rec flag is set
{
// Do nothing
}
if (TI0 == 1) { // Check if transmit flag is set
SBUF0 = Byte; // copy the character from Byte to Buffer
TI0 = 0; // Set Transmit flag to 0
}
}
Here is my Method for Sending the Data
void SendData(){
unsigned char incoming_str[] = {'d','s','a','\r'}; //array of chars to send
TX_Ready = 0;
for(i=0;i<sizeof(incoming_str);i++) {
Byte = incoming_str[i];
TI0=1;
}
}
First Problem i am getting the data in reversed order (is it normal). Second Problem i am getting characters in wrong data
Here is an output sample:
a s d
a s d
a s d
a s s
a a d
a s d
a s d
a s d
a s d
a s d
a s s
a a d
a s d
a s d
a s d
a s d
a s d
a s s
a a d
a s d
a s d
a s d
a s