varuzhandanielyan wrote:
>I use UART1 to connect to RS485. For it
>I need to enable RS485 transmitter before sending
>and again desible it when sending is over.
>Below is my code:
>void Transmit1(int ch)
>{
> U32 enabled_interrupts;
> // wait for transmission completed
> while (!(U1LSR & TEMT));
>
> enabled_interrupts = VICIntEnable; //disable all interrupts
> VICIntEnClr = enabled_interrupts;
>
> U1THR = ch;
>//while (IO0PIN & Bit(15));
> T1EMR = Bit(2); // ExtMatch2 = 1
> T1MR2 = T1TC + 10*60000000/115200;
> T1EMR |= Bit(8); // ClearOnExtMatch2
>
> VICIntEnable = enabled_interrupts;
>}
>
>Problem:
>the U1THR = ch; operator does not start sending
>immediatelly. There is a random delay in range
>approximatelly from 0 to 1 bit duration.
>I made different experiments to reset the baudrate
>counter or other means but without result. Only
>way I found to solve the problem was an extra pin
>(P0.15 in my case) usage to detect the real start
>of trasmittion, this is done by commented while.
>So one needs to use an extra pin and accept, that
>interruptions could be desible by up to one bit
>duration.
>Maybe somebody knows how to force the UART1 start
>to transmit the character immediatelly after writing
>to U1THR register.
>
>
Ha! Welcome to RS485. It is a bit more complex than it looks.
I don't know why you believe that you needs such precise control over
the relationship of TXD/RXD and the DIRection? By it's very nature,
RS485 communications over twisted pair require that the line be
precharged before it can be used.
Think about it, the wire is floating electrically, any stray magnetic or
electrical field can induce a blip into the "dead" wire. By first
turning the direction to Transmit, then hold that for a few TX char
times, it allows the uart at the RX side to settle down. The uart that
the RX side may have heard a blip and is in the process of receiving a
erroneous char. Once you precharge the line, send your data, then HOLD
the carrier (direction) until the last char has been sent and then flip
the line back to RX mode.
Most of the systems I've seen / worked on have a "quiet" line floating
as the units are all listening for some other unit to speak.
TomW
--
Tom Walsh - WN3L - Embedded Systems Consultant
http://openhardware.net, http://cyberiansoftware.com
"Windows? No thanks, I have work to do..."
----------------------------------------------------Message
Re: [lpc2000] RS485 and UART1
2006-02-06 by Tom Walsh
Attachments
- No local attachments were found for this message.