Forums

Can't read UART Status Registers

Started by djflexdex December 16, 2006
Hi, I'm having a problem reading the UART status reg.(UxLSR) and UART
Interrupt source reg.(UxIIR) When I enter my ISR, the regs. are set
correctly, but as soon as I read them they are cleared, therefore I
can't make sense of which type of UART interrupt (Receive Line,
Receive Data Available, Character Time-out or THRE Interrupt) caused
the interrupt, I've include my code below...please help...

void UART_Initialise(void)
{
//UART0
//RBR, THRE, Line Status Interrupts Enabled
//FIFO Enabled
//8 Bits; 1 Stop Bit; Parity Disabled
//19200kbps Baud Rate
PINSEL0 |= 0x00000005;
U0IER = 0x07;
U0FCR = 0x87;
U0LCR = 0x83;
U0SCR = 0;
U0DLL = UART_BAUD_DIV0;
U0DLM = 0;
//Disable Divisor Latch Access
U0LCR = 0x03;
return;
}
void UART_ISR(void) __irq
{
unsigned char int_status, byte;
//Check Source of Interrupt
int_status = U0IIR;
if ((int_status & 0x06) == 0x06)
{
//Receive Line Interrupt
if ((U0LSR & 0x02) == 0x02)
{
//Overrun Error
RAM.System_Error |= UART_Error;
}
else if ((U0LSR & 0x04) == 0x04)
{
//Parity Error
RAM.System_Error |= UART_Error;
}
else if ((U0LSR & 0x08) == 0x08)
{
//Framing Error
RAM.System_Error |= UART_Error;
}
else if ((U0LSR & 0x10) == 0x10)
{
//Break Interrupt
RAM.System_Error |= UART_Error;
}
else if ((U0LSR & 0x01) == 0x01)
{
//RX Data in FIFO
if (RX_Command == 0)
{
//Command Byte
RX_Command = 1;

}
byte = U0RBR;
}
}
else if ((int_status & 0x04) == 0x04)
{
//Receive Data Available Interrupt
byte = U0RBR;
}
else if ((int_status & 0x0C) == 0x0C)
{
//Character Time-out Interrupt
if (RX_Command == 0)
{
//Command Byte
RX_Command = 1;

}
byte = U0RBR;
}
else if ((int_status & 0x02) == 0x02)
{
//THRE Interrupt
}
else
{
//Error
RAM.System_Error |= UART_Error;
}
byte = U0IIR;
VICVectAddr = 0x00000000;
}

An Engineer's Guide to the LPC2100 Series

At 05:43 AM 12/16/06 +0000, djflexdex wrote:
>Hi, I'm having a problem reading the UART status reg.(UxLSR) and UART
>Interrupt source reg.(UxIIR) When I enter my ISR, the regs. are set
>correctly, but as soon as I read them they are cleared, therefore I

Various bits in the LSR register are supposed to be cleared on read (read
the user manual or the data sheet of a 'discrete' 16x50.

You have to read the value only once, then check it. Read it again only to
clear the next source.

Check any working interrupt code for this series of UART any you will see
those precautions taken.

Robert

http://www.aeolusdevelopment.com/

From the Divided by a Common Language File (Edited to protect the guilty)
ME - "I'd like to get Price and delivery for connector Part # XXXXX"
Dist./Rep - "$X.XX Lead time 37 days"
ME - "Anything we can do about lead time? 37 days seems a bit high."
Dist./Rep - "that is the lead time given because our stock is live.... we
currently have stock."
I found the problem. When you use the keil UART simulator panel, it
reads the status regs. which in turn clears them. So my program never
could read the correct values..
--- In l..., Robert Adsett wrote:
>
> At 05:43 AM 12/16/06 +0000, djflexdex wrote:
> >Hi, I'm having a problem reading the UART status reg.(UxLSR) and UART
> >Interrupt source reg.(UxIIR) When I enter my ISR, the regs. are set
> >correctly, but as soon as I read them they are cleared, therefore I
>
> Various bits in the LSR register are supposed to be cleared on read
(read
> the user manual or the data sheet of a 'discrete' 16x50.
>
> You have to read the value only once, then check it. Read it again
only to
> clear the next source.
>
> Check any working interrupt code for this series of UART any you
will see
> those precautions taken.
>
> Robert
>
> http://www.aeolusdevelopment.com/
>
> From the Divided by a Common Language File (Edited to protect the
guilty)
> ME - "I'd like to get Price and delivery for connector Part # XXXXX"
> Dist./Rep - "$X.XX Lead time 37 days"
> ME - "Anything we can do about lead time? 37 days seems a bit high."
> Dist./Rep - "that is the lead time given because our stock is
live.... we
> currently have stock."
>