English
Language : 

DAN-190 Datasheet, PDF (2/6 Pages) Exar Corporation – EXAR UARTS IN RS-485 APPLICATIONS
DAN190
EXAR UARTS IN RS-485 APPLICATIONS
3.1 Possible Software Solutions
3.1.1 Polling Example
The first way to do this is to poll the LSR register. Let’s assume that the RTS# signal is used to control the
direction of the RS-485 transceiver and RTS# needs to be HIGH for transmit and LOW for receive.
//Initialization
IER = 0x00;
//Interrupts are not enabled
MCR bit-1 = 1;
//Set RS-485 transceiver in RX mode
...
//Transmit Routine
MCR bit-1 = 0;
//Set RS-485 transceiver in TX mode
Write data to TX FIFO (THR);
While (LSR bit-6 == 0);
//wait until the TX FIFO + TSR is empty
MCR bit-0 = 1;
//TX completed, set RS-485 transceiver back to RX mode
However, this is not very efficient since the CPU/MCU has to wait for this routine to finish.
3.1.2 Interrupts + Polling Example
The other way is to use the TX empty interrupt. However, even when using the TX empty interrupt, the
software still needs to poll the LSR register as described in section 3.0.
//Initialization
IER = 0x02;
//TX empty interrupt enabled
MCR bit-1 = 1;
//Set RS-485 transceiver in RX mode
...
//Transmit Interrupt Service Routine
if (more data to send)
MCR bit-1 = 0;
//set or keep RTS# pin HIGH for TX mode
else {
while (LSR bit-6 == 0);
//poll until TX FIFO + TSR is empty
MCR bit-1 = 1;
//TX completed, set RS-485 transceiver back to RX mode
}
while (more data to send AND data less than FIFO size)
write data to THR;
This is more efficient than the polling example, but there is still a while loop that keeps the CPU/MCU busy
when it can be doing other tasks.
2