UART Receive Buffer (LPC1768)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

UART Receive Buffer (LPC1768)

1,360 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by expressouser on Tue Jun 24 09:42:29 MST 2014
Hi .

Is the UART interrupt handler expected to clear the RBR register upon exit? I am trying to read out the content of the RBR register outside of the handler,but it seems like the value is already cleared by the handler. Thanks.

Here's some part of my code:

<code>
inside main():

while (1) {
while (rbr == 0);
printf ("%c\n", LPC_UART2->RBR); //this simply prints a \n, not the character from RBR.
rbr = 0;
}


interrupt handler:

void UART2_IRQHandler(void) {
uint32_t status = LPC_UART2->IIR;
if ( (status & IRQ_RDA) == IRQ_RDA) {
while ((LPC_UART2->LSR & 0x20) == 0);
rbr =1;
}
}
</code>

it works well when I am reading RBR inside the handler:

<code>
inside main:

while (1) {
while (rbr == 0);
printf ("%c\n", ch); //this is ok.
rbr = 0;
}

interrupt handler:

void UART2_IRQHandler(void) {
uint32_t status = LPC_UART2->IIR;
if ( (status & IRQ_RDA) == IRQ_RDA) {
while ((LPC_UART2->LSR & 0x20) == 0);
ch = LPC_UART2->RBR;
rbr =1;
}
}

</code>
Labels (1)
0 Kudos
1 Reply

669 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by embd02161991 on Fri Sep 12 17:07:10 MST 2014
Hi ,

The  right approach for fetching the valid pair of received byte and its status bits is first to read the content of the LSR register, and then to read a byte from the RBR. The best way is to store the value in RBR into another variable and handle that in main. Since RBR is volatile and changes , it  may not be reliable to print the register directly in main as by then the value could have changed.


Thanks

NXP Technical Support
0 Kudos