lpcware

UART Receive Buffer (LPC1768)

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
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>

Outcomes