I am working on a simple data streaming. The problem is on the receiver side. I connected a led to be indicated if two data bytes and their checksum are ok. I have checked the digital signal on receiver side and the picture shows that incoming signals are ok too. Yellow is the transmitter digital input, blue is the receiver digital output. This is the transmitter code (12F683):
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;
}
The problem is that receiver led always changes its state, no matter if error checking good or not. What is wrong with the code? I use mikroC PRO for PIC 4.60. Any help appreciated.I think you are just moving through your code and not reading any new data. Change yourToCode: Select all
if(uart1 ready)
This will create a blocking code but can be a next step in your project. There are still other issues to resolve as well. Ultimately it will be better to use interrupts.Code: Select all
while(!uart1 ready)
Bonca