Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Thread

RS485

RS485

2005-09-19 by gfaurie1

Hello,

I try to develop a RS485 driver, but i have a problem.

As you know, you must stay in reception and when you have to transmit, 
you change direction to be in transmission only during transmission. 
When the last character has been transmitted you turn back in 
reception.

Problem is that i have no interruption on shift register empty. I have 
an interruption when transmitter is empty but if i change direction at 
this time, character which is in shift register is not transmitted, 
and i lose it.
The only solution that i suppose is to check state of shist register 
(LSR) in polling but i'd like to find a more real time solution

Who can help me ?

Thank

Re: RS485

2005-09-19 by Grzegorz

Hi,
one of the possible solution is to start timer on transmitter empty 
event, initiated with a bit duration times bitframe length value 
(typical x10..11). During timer reload event you can simply switch 
RS485 line to rx mode.

I use this scenario in my design with no problem.

Grzegorz
--- In lpc2000@yahoogroups.com, "gfaurie1" <gilles.faurie@p...> wrote:
> Hello,
> 
> I try to develop a RS485 driver, but i have a problem.
> 
> As you know, you must stay in reception and when you have to 
transmit, 
> you change direction to be in transmission only during 
transmission. 
> When the last character has been transmitted you turn back in 
> reception.
> 
> Problem is that i have no interruption on shift register empty. I 
have 
> an interruption when transmitter is empty but if i change direction 
at 
> this time, character which is in shift register is not transmitted, 
> and i lose it.
> The only solution that i suppose is to check state of shist 
register 
Show quoted textHide quoted text
> (LSR) in polling but i'd like to find a more real time solution
> 
> Who can help me ?
> 
> Thank

RE: [lpc2000] RS485

2005-09-19 by Yves Rondeau

Hello ,

I had the same problem on ISO7816 communication.
At the end of TX I switch back in input mode then lost the 2 last bytes.

Add those lines at the end of your TX routines

while (!(U1LSR & 0x40));   /* Wait if U1THR & U1TSR not empty */  
 

  				   /* we need to wait for the 2 Tx Buffer */
				   /* to be empty	*/
			 	   /* or we can lost the 2 bytes switching
*/ 
				   /* in input */
  PINSEL0 = 0x00040000;	   /* RX UART1	Enable -TX Disable	*/ 



Yves 
Show quoted textHide quoted text
-----Original Message-----
From: lpc2000@yahoogroups.com [mailto:lpc2000@yahoogroups.com] On Behalf Of
gfaurie1
Sent: segunda-feira, 19 de Setembro de 2005 7:44
To: lpc2000@yahoogroups.com
Subject: [lpc2000] RS485

Hello,

I try to develop a RS485 driver, but i have a problem.

As you know, you must stay in reception and when you have to transmit, 
you change direction to be in transmission only during transmission. 
When the last character has been transmitted you turn back in 
reception.

Problem is that i have no interruption on shift register empty. I have 
an interruption when transmitter is empty but if i change direction at 
this time, character which is in shift register is not transmitted, 
and i lose it.
The only solution that i suppose is to check state of shist register 
(LSR) in polling but i'd like to find a more real time solution

Who can help me ?

Thank 






 
Yahoo! Groups Links

Re: [lpc2000] RS485

2005-09-19 by Gilles FAURIE

Yes i could do that but i don't want to wait in my interruption routine 
during character transmission which could be about 1ms (at 9600 baud).


----- Original Message ----- 
Show quoted textHide quoted text
From: "Yves Rondeau" <op173039@...>
To: <lpc2000@yahoogroups.com>
Sent: Monday, September 19, 2005 11:17 AM
Subject: RE: [lpc2000] RS485


> Hello ,
>
> I had the same problem on ISO7816 communication.
> At the end of TX I switch back in input mode then lost the 2 last bytes.
>
> Add those lines at the end of your TX routines
>
> while (!(U1LSR & 0x40));   /* Wait if U1THR & U1TSR not empty */
>
>
>     /* we need to wait for the 2 Tx Buffer */
>    /* to be empty */
>    /* or we can lost the 2 bytes switching
> */
>    /* in input */
>  PINSEL0 = 0x00040000;    /* RX UART1 Enable -TX Disable */
>
>
>
> Yves
>
> -----Original Message-----
> From: lpc2000@yahoogroups.com [mailto:lpc2000@yahoogroups.com] On Behalf 
> Of
> gfaurie1
> Sent: segunda-feira, 19 de Setembro de 2005 7:44
> To: lpc2000@yahoogroups.com
> Subject: [lpc2000] RS485
>
> Hello,
>
> I try to develop a RS485 driver, but i have a problem.
>
> As you know, you must stay in reception and when you have to transmit,
> you change direction to be in transmission only during transmission.
> When the last character has been transmitted you turn back in
> reception.
>
> Problem is that i have no interruption on shift register empty. I have
> an interruption when transmitter is empty but if i change direction at
> this time, character which is in shift register is not transmitted,
> and i lose it.
> The only solution that i suppose is to check state of shist register
> (LSR) in polling but i'd like to find a more real time solution
>
> Who can help me ?
>
> Thank
>
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>

Re: [lpc2000] RS485

2005-09-19 by Peter Jakacki

Gilles,
If you don't disable the 485 receiver or the UART rx itself you can 
monitor the bytes that are transmitted. There are variations on this 
scheme but it means that you could simply turn off the 485 transmitter 
when you receive the last character that you transmitted.

Also, as Grzegorz pointed out you could use a timer, that is if you have 
one to spare.

Both of these are practical real-time solutions and easily implemented.

BTW, Yves sample code seems to be switching the PINSELs which has got to 
be totally redundant and unnecessary. Just keep the rx and tx alive and 
you only need to drive the 485's TE pin.


Gilles FAURIE wrote:
Show quoted textHide quoted text
>Yes i could do that but i don't want to wait in my interruption routine 
>during character transmission which could be about 1ms (at 9600 baud).
>
>
>----- Original Message ----- 
>From: "Yves Rondeau" <op173039@...>
>To: <lpc2000@yahoogroups.com>
>Sent: Monday, September 19, 2005 11:17 AM
>Subject: RE: [lpc2000] RS485
>
>
>
>>Hello ,
>>
>>I had the same problem on ISO7816 communication.
>>At the end of TX I switch back in input mode then lost the 2 last bytes.
>>
>>Add those lines at the end of your TX routines
>>
>>while (!(U1LSR & 0x40));   /* Wait if U1THR & U1TSR not empty */
>>
>>
>>    /* we need to wait for the 2 Tx Buffer */
>>   /* to be empty */
>>   /* or we can lost the 2 bytes switching
>>*/
>>   /* in input */
>> PINSEL0 = 0x00040000;    /* RX UART1 Enable -TX Disable */
>>
>>
>>
>>Yves
>>
>>-----Original Message-----
>>From: lpc2000@yahoogroups.com [mailto:lpc2000@yahoogroups.com] On Behalf 
>>Of
>>gfaurie1
>>Sent: segunda-feira, 19 de Setembro de 2005 7:44
>>To: lpc2000@yahoogroups.com
>>Subject: [lpc2000] RS485
>>
>>Hello,
>>
>>I try to develop a RS485 driver, but i have a problem.
>>
>>As you know, you must stay in reception and when you have to transmit,
>>you change direction to be in transmission only during transmission.
>>When the last character has been transmitted you turn back in
>>reception.
>>
>>Problem is that i have no interruption on shift register empty. I have
>>an interruption when transmitter is empty but if i change direction at
>>this time, character which is in shift register is not transmitted,
>>and i lose it.
>>The only solution that i suppose is to check state of shist register
>>(LSR) in polling but i'd like to find a more real time solution
>>
>>Who can help me ?
>>
>>Thank
>>

Re: [lpc2000] RS485

2005-09-19 by Bill Knight

Another option is to send a trailing NULL (0x00) character and allow it
to be the character that is dropped.

Regards
-Bill Knight
R O SoftWare &
http://www.theARMPatch.com
Show quoted textHide quoted text
On Mon, 19 Sep 2005 06:44:10 -0000, gfaurie1 wrote:

>Hello,

>I try to develop a RS485 driver, but i have a problem.

>As you know, you must stay in reception and when you have to transmit, 
>you change direction to be in transmission only during transmission. 
>When the last character has been transmitted you turn back in 
>reception.

>Problem is that i have no interruption on shift register empty. I have 
>an interruption when transmitter is empty but if i change direction at 
>this time, character which is in shift register is not transmitted, 
>and i lose it.
>The only solution that i suppose is to check state of shist register 
>(LSR) in polling but i'd like to find a more real time solution

>Who can help me ?

>Thank 






> 
>Yahoo! Groups Links



>

Re: [lpc2000] RS485

2005-09-19 by Sebastien Jacquemard

Hi,

I've the same pb few month aog. I do this and it's work fine. I hope this
exemple help you.

Regards,
Sebastien Jacquemard


#define EN_TXD1  0x00010000
#define EN_RXD1  0x00040000
#define SENS  0x00000400 //P0.10 = Rs485 sens
#define Txd         1       // RS485 : mode transmission
#define Rxd         0       // RS485 : mode r\ufffdception
#define TXD_BREAK 0x40 // Set TXD break


void init_rs485()
{
 IOSET0=SENS; //SENS=TXD

 PINSEL0 |= EN_RXD1 | EN_TXD1;          // Enable RxD1 and TxD1
   U1LCR = 0x8B;                          // 8 bits, Odd parity, 1 Stop bit
   U1DLL = Baud187500;
   U1LCR &= 0x7F;                         // DLAB = 0
}


void trasnmit_rs485(uchar *p)
{
 uchar n;
 uchar pause;


 IOSET0=SENS; //SENS=Txd --> rs485 in tx mode
 U1LCR|=TXD_BREAK; //break on txd1 line
 tempo(110); //tempo 90usec
 U1LCR&=~TXD_BREAK; //clear break


 n=*p++;
 do{
  while (!(U1LSR & 0x20)) watchdog(); //wait tx buffer empty
  U1THR = *p++;
 } while (--n);

 //wait buffer empty before swith in rx mode
 while ((U1LSR & 0x60)!=0x60) watchdog();
 IOCLR0=SENS; //SENS=Rxd --> rs485 in rx mode}
}

uchar receive_rs485(uchar *p)
{
 uchar n;
 uint fin;

 IOCLR0=SENS; //SENS=Rxd --> rs485 in rx mode

 n=*p;    // number of char to receive
 fin=100000;

 do{
  do{
   if (!fin)
   {
    IOSET0=SENS; //SENS=Txd --> rs485 in tx mode
    return(0);
   }
   fin--;
   watchdog();
  } while(!(U1LSR & 0x01)); //wait char
  *p++=U1RBR;   // store char
 } while(--n);

 IOSET0=SENS; //SENS=Txd --> rs485 in tx mode
 return(1);
}

Re: [lpc2000] RS485

2005-09-21 by Gilles FAURIE

Thanks everybody,

I used solution with timer. I have 2 serial link with two RS485 possible. So 
i use timer 1 with two Match Register (MR0 and MR1).

Fisrt I calculate time for one character tranmssion  (TimeCar). When my 
transmitter is empty i program MR with the value TC + TimeCar and i activate 
IT timer.

In the IT timer i turn back in reception.

void TIMER1_irq ()
{

  // Test du registre MR0 du timer1
  if ((T1IR & 0x01)==0x01)
  {
    T1IR |= 0x01;
    if ((T1MCR & 0x01) == 0x01)
    {// MR0 activé et actif
      T1MCR &= ~0x01;
     // On descend RTS
     vTransmissionRs485(0, OFF);
    }
  }

  // Test du registre MR1 du timer1
  if ((T1IR & 0x02)==0x02)
  {
    T1IR |= 0x02;
    if ((T1MCR & 0x08) == 0x08)
    {// MR1 activé et actif
      if ((U1LSR & 0x40) != 0x40)
        GEN_TraitErreur();
      T1MCR &= ~0x08;
      // On descend RTS
     vTransmissionRs485(1, OFF);
    }
  }


/* Only a part of my UART IRQ to not lose you */

      if (pSer->bRs485 != FALSE)
      {
        if ((*(pbReg + OFF_LSR) & 0x60) == 0x20)
        {// If THR Empty and Shift register not empty
          // We activate timer
          *pSer->MR = T1TC+pSer->dMatchReg;
          T1MCR |= pSer->bValItTimer;
        }
        else
          if ((*(pbReg + OFF_LSR) & 0x60) == 0x60)
           vTransmissionRs485(1, OFF);// No more transmission
      }






----- Original Message ----- 
Show quoted textHide quoted text
From: "Peter Jakacki" <peterjak@...>
To: <lpc2000@yahoogroups.com>
Sent: Monday, September 19, 2005 3:29 PM
Subject: Re: [lpc2000] RS485


> Gilles,
> If you don't disable the 485 receiver or the UART rx itself you can
> monitor the bytes that are transmitted. There are variations on this
> scheme but it means that you could simply turn off the 485 transmitter
> when you receive the last character that you transmitted.
>
> Also, as Grzegorz pointed out you could use a timer, that is if you have
> one to spare.
>
> Both of these are practical real-time solutions and easily implemented.
>
> BTW, Yves sample code seems to be switching the PINSELs which has got to
> be totally redundant and unnecessary. Just keep the rx and tx alive and
> you only need to drive the 485's TE pin.
>
>
> Gilles FAURIE wrote:
>
>>Yes i could do that but i don't want to wait in my interruption routine
>>during character transmission which could be about 1ms (at 9600 baud).
>>
>>
>>----- Original Message ----- 
>>From: "Yves Rondeau" <op173039@...>
>>To: <lpc2000@yahoogroups.com>
>>Sent: Monday, September 19, 2005 11:17 AM
>>Subject: RE: [lpc2000] RS485
>>
>>
>>
>>>Hello ,
>>>
>>>I had the same problem on ISO7816 communication.
>>>At the end of TX I switch back in input mode then lost the 2 last bytes.
>>>
>>>Add those lines at the end of your TX routines
>>>
>>>while (!(U1LSR & 0x40));   /* Wait if U1THR & U1TSR not empty */
>>>
>>>
>>>    /* we need to wait for the 2 Tx Buffer */
>>>   /* to be empty */
>>>   /* or we can lost the 2 bytes switching
>>>*/
>>>   /* in input */
>>> PINSEL0 = 0x00040000;    /* RX UART1 Enable -TX Disable */
>>>
>>>
>>>
>>>Yves
>>>
>>>-----Original Message-----
>>>From: lpc2000@yahoogroups.com [mailto:lpc2000@yahoogroups.com] On Behalf
>>>Of
>>>gfaurie1
>>>Sent: segunda-feira, 19 de Setembro de 2005 7:44
>>>To: lpc2000@yahoogroups.com
>>>Subject: [lpc2000] RS485
>>>
>>>Hello,
>>>
>>>I try to develop a RS485 driver, but i have a problem.
>>>
>>>As you know, you must stay in reception and when you have to transmit,
>>>you change direction to be in transmission only during transmission.
>>>When the last character has been transmitted you turn back in
>>>reception.
>>>
>>>Problem is that i have no interruption on shift register empty. I have
>>>an interruption when transmitter is empty but if i change direction at
>>>this time, character which is in shift register is not transmitted,
>>>and i lose it.
>>>The only solution that i suppose is to check state of shist register
>>>(LSR) in polling but i'd like to find a more real time solution
>>>
>>>Who can help me ?
>>>
>>>Thank
>>>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>

RE: [lpc2000] RS485

2005-09-21 by Lasse Madsen

Philips should be ashamed of them selves making such an obsolete uart...
Let's all complain and hope that they will change it in future chips... 

Regards
Lasse Madsen

Re: RS485

2005-09-21 by Karl Olsen

--- In lpc2000@yahoogroups.com, "Lasse Madsen" <Lasse.Madsen@E...> 
wrote:
> Philips should be ashamed of them selves making such an obsolete 
> uart... Let's all complain and hope that they will change it in
> future chips... 

I tend to agree.  They did add some handshake and baud rate generator 
features in LPC214x, but nothing to handle the age-old RS485 
transmitter problem. Atm*l has always had a much more capable UART.

Karl Olsen

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.