rxdata is shared between your main() and your interupt().
May be you have to protect your code ?
Code: Select all
main()
{
INTCON.GIE = 0; // Begin critical section
// work with rxdata here
INTCON.GIE = 1; // End critical section
}
#46 Post by denisF » 06 Aug 2008 16:18
Code: Select all
main()
{
INTCON.GIE = 0; // Begin critical section
// work with rxdata here
INTCON.GIE = 1; // End critical section
}
#48 Post by Bonca » 07 Jan 2011 15:33
Code: Select all
Soft_UART_Init(&GPIO, 4, 5, 1200, 0); // receiver data rate fmax=2kHz => 1200
delay_ms(1000);
while(1){
Soft_UART_Write(0xAA); // dummy
delay_ms(10); // after 30ms receiver output goes to low (???)
Soft_UART_Write(0x55);
delay_ms(10);
Soft_UART_Write(0xAA);
delay_ms(10);
Soft_UART_Write(0x55);
delay_ms(10);
Soft_UART_Write(0x05); // start_byte
delay_ms(10);
Soft_UART_Write(0x03); // data_byte1
delay_ms(10);
Soft_UART_Write(0x04); // data_byte2
delay_ms(10);
Soft_UART_Write(0x07); // checksum_byte = data_byte1 + data_byte2
delay_ms(10);
GPIO.F2 = ~GPIO.F2; // indicates end of cycle
}
Code: Select all
UART1_Init(1200);
delay_ms(100);
while(1){
while(start_byte != 0x05){ // until 0x05 comes...
if(UART1_Data_Ready() == 1){ // start_byte
start_byte = UART1_Read();
}
}
if(UART1_Data_Ready() == 1){ // data_byte1
data_byte1 = UART1_Read();
}
if(UART1_Data_Ready() == 1){ // data_byte2
data_byte2 = UART1_Read();
}
if(UART1_Data_Ready() == 1){ // checksum_byte
checksum_byte = UART1_Read();
}
if(checksum_byte == (data_byte1 + data_byte2)){ // simple error checking
LATB.F0 = ~LATB.F0; // indicates if no error in data transfer
}
start_byte = 0;
}
#49 Post by drdoug » 07 Jan 2011 16:56
Code: Select all
if(uart1 ready)
Code: Select all
while(!uart1 ready)
#50 Post by Bonca » 07 Jan 2011 21:34