EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

UART Transmitter empty Interrupt with LPC2470

Started by farhan ahmad June 24, 2012
Hello Everybody,

I am trying to interface a device with RS485 half duplex communication. So below is my algorithm.
1) Set the Master Device (DIR) into transmitting mode.
2) Send the data over the UART.
3) Set the Master Device (DIR) into receiving mode. To receive data from the device.

So when the final bit is shifted out into the UART line set the Master device into receiving mode. For this purpose I have used

DIR = 1; // set to Transmitting mode
while (! (U2LSR & (U2LSR_TEMT) // TEMT is the transmitter empty bit # 6 of the U2LSR
send_data(); // send data over the UART
while (! (U2LSR & (U2LSR_TEMT) // TEMT is the transmitter empty bit # 6 of the U2LSR

DIR = 0; // back to receiving mode

This is the polled version of UART and it is working with my application. I am more interested to use UART Interrupt version. So that means when the last bit is transmitted on the UART line and I got an interrupt and then I switch to receiving mode. In this case I dont have to wait in the above while loop.

After reading the specification of LPC2470, Ididn'tsaw any TEMT (Transmitter Empty) interrupt bit. Instead of TEMT, I have seen THRE (Transmit Holding Register Empty) Interrupt. But in actual I need TEMT (Transmitter Empty) interrupt.

As far as ATMEL AVR is concerned, there is an extra Transmitter Empty Interrupt available. In this case I can use Transmitter Empty Interrupt service routine.

Does anyone know how to tackle the above situation in LPC2470 with the interrupt service routine.

I hope to hear valuable responses from someone.

Best Regards,
Farhan Ahmad



An Engineer's Guide to the LPC2100 Series

If you know the baud rate, and when the THRE fired, you could use a timer to
generate an interrupt when the transmitter is empty. Or, you could use a
system tick interrupt to poll the TEMT flag, and respond appropriately.
Neither of these options is as elegant as having an actual interrupt, but
given that there isn't one, this may be the best you can do.

Mike
-----Original Message-----
From: l... [mailto:l...]On Behalf
Of farhan ahmad
Sent: Sunday, June 24, 2012 3:01 AM
To: l...
Subject: [lpc2000] UART Transmitter empty Interrupt with LPC2470
Hello Everybody,

I am trying to interface a device with RS485 half duplex communication. So
below is my algorithm.
1) Set the Master Device (DIR) into transmitting mode.
2) Send the data over the UART.
3) Set the Master Device (DIR) into receiving mode. To receive data from the
device.

So when the final bit is shifted out into the UART line set the Master
device into receiving mode. For this purpose I have used

DIR = 1; // set to Transmitting mode
while (! (U2LSR & (U2LSR_TEMT) // TEMT is the transmitter empty bit # 6
of the U2LSR
send_data(); // send data over the UART
while (! (U2LSR & (U2LSR_TEMT) // TEMT is the transmitter empty bit # 6
of the U2LSR

DIR = 0; // back to receiving mode

This is the polled version of UART and it is working with my application. I
am more interested to use UART Interrupt version. So that means when the
last bit is transmitted on the UART line and I got an interrupt and then I
switch to receiving mode. In this case I dont have to wait in the above
while loop.

After reading the specification of LPC2470, Ididn'tsaw any TEMT
(Transmitter Empty) interrupt bit. Instead of TEMT, I have seen THRE
(Transmit Holding Register Empty) Interrupt. But in actual I need TEMT
(Transmitter Empty) interrupt.

As far as ATMEL AVR is concerned, there is an extra Transmitter Empty
Interrupt available. In this case I can use Transmitter Empty Interrupt
service routine.

Does anyone know how to tackle the above situation in LPC2470 with the
interrupt service routine.

I hope to hear valuable responses from someone.

Best Regards,
Farhan Ahmad



If you are using RS-485 in 2-wire mode then you should be listening to what you send. As a result, even though you won't get a TEMT interrupt, you will get a byte received interrupt. In this interrupt handler, you check to see if you were the master and, if so, that what you received was what you sent. This is how you detect collisions on the bus. If you were a slave then you just process the byte.

In the multi-master 2-wire mode, you may also see framing errors in the status register when collisions occur.

In 4-wire mode, there can be just one master and multiple slaves. The slaves need to control their output driver but the master is always enabled.

Here is a multi-master RS485 project. It assumes an AVR so it doesn't directly apply. But it works:
http://bdmicro.com/code/robin/

Richard


The 2024 Embedded Online Conference