I have a problem when trying to test send and receive lines on RS485 communication, anyone know what may cause a problem here? It works without interrupt but with interrupt won't work. I am working on NXP LPC1788, and trying to make an interrupt echo program for RS485 (what I send, it sends me back to terminal). Thanks in advance.
int main(void) {
uart2()
NVIC_EnableIRQ(UART2_IRQn);
while(1) {
} //while
} //main
void receive(void) {
SMR_485RECEIVE; //Receive data flow
delay_1_ms();
delay_1_ms();
receive_byte = LPC_UART2->RBR;
}
void send(void) {
SMR_485TRANSMIT; //Transmit data flow
delay_1_ms();
delay_1_ms();
LPC_UART2->THR = receive_byte;
}
void UART2_IRQHandler(void) __irq {
BYTE tip = LPC_UART2->IIR & 0x06;
if((tip == 0x04) && !(LPC_UART2->RBR == '\0')){
receive();
delay_1_ms();
send();
}
}
If I'm right before sending I need to call SMR_485TRANSMIT and then store BYTE to output data register THR, when I want to receive byte I call SMR_485RECEIVE and then store data from input data register RBR to variable receive_byte. I deleted delays of 1ms and my code looks like this right now:
void receive(void) {
SMR_485RECEIVE;
delay_1_micro();
receive_byte = LPC_UART2->RBR;
}
void send(void) {
SMR_485TRANSMIT;//Transmit data flow
delay_1_micro();
LPC_UART2->THR = receive_byte;
}
void UART2_IRQHandler(void) __irq {
BYTE tip = LPC_UART2->IIR & 0x06;
if(tip == 0x04){
receive();
delay_1_micro();
send();
}
}
But it won't work, I dont understand whats the problem in my code when switching direction of data flow?
SMR_485RECEIVE;
? And I believe you can directly read data from RBR register without any delay! \$\endgroup\$NVIC_EnableIRQ(UART2_IRQn)
5) Masked 2 bits RDR and THRE in IIR register and checking them all the time if they are set, if RDA is set go to receive function, if THRE is set go to send function and thats it. Are there steps that I forgot and that may be the reason it wont work? \$\endgroup\$