UART Receive Buffer (LPC1768)

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

UART Receive Buffer (LPC1768)

1,687 次查看
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>
标签 (1)
0 项奖励
回复
1 回复

996 次查看
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 项奖励
回复