Author Topic: RS 485 with LPC-23xx  (Read 17939 times)

Offline saurabh

  • Newbie
  • *
  • Posts: 10
    • View Profile
RS 485 with LPC-23xx
« on: October 05, 2009, 07:25:52 PM »
Dear All,

I am losing RS-485 based UART communication after transffering few hundred bytes...

I have RS-485 IC with my board (LPC2388) on UART -2 , Which is half duplex.
Direction selection is auto (as when we trasmit) Tx get automatically enabled, and
RX is selected as default. (Its is two line interface RX and TX only).

Rightnow I am trying to use RS485 communication driver (Port opening and send receive)
like other Rs232 based UART drivers (other UARTs (0,1,3) seemsworking well),

but i am facing issue with Rs-485 , I am losing Rs-485 communication after few Query-Responce
to/from external the 485-Device. (Baud rate I am using is 9600). Losing communication means
Only not able to transmit further but I can get bytes from RS485 network then. That is the issue.

Should i need to use the existing UART open and read write routines with any additiional
parmaters for make it work for RS-485. My curent Uart open,write,read codes are as below.

Code: [Select]
extern QUEUE_HANDLE fnOpenUART2(unsigned char ucDriverMode)
{
//TTYTABLE tInterfaceParameters;                                       // table for passing information to driver
    tInterfaceParameters2.Channel = 2;                            // set UART channel for serial use
    tInterfaceParameters2.ucSpeed = SERIAL_BAUD_9600;
    tInterfaceParameters2.Rx_tx_sizes.RxQueueSize = RTU_RX_BUFFER_SIZE;       // input buffer size
    tInterfaceParameters2.Rx_tx_sizes.TxQueueSize = RTU_TX_BUFFER_SIZE;       // output buffer size
    tInterfaceParameters2.Task_to_wake = TASK_RS485_CALLBACK;                        // wake self when messages have been received
    #ifdef SUPPORT_FLOW_HIGH_LOW
    tInterfaceParameters2.ucFlowHighWater = temp_pars->temp_parameters.ucFlowHigh;// set the flow control high and low water levels in %
    tInterfaceParameters2.ucFlowLowWater = temp_pars->temp_parameters.ucFlowLow;
    #endif
    tInterfaceParameters2.Config = temp_pars->temp_parameters.usSerialMode; // {43}
    #ifdef TEST_MSG_MODE
    tInterfaceParameters2.Config |= (MSG_MODE);
        #if defined (TEST_MSG_CNT_MODE) && defined (SUPPORT_MSG_CNT)
    tInterfaceParameters2.Config |= (MSG_MODE_RX_CNT);
        #endif
    tInterfaceParameters2.Config &= ~USE_XON_OFF;
    tInterfaceParameters2.ucMessageTerminator = '\r';
    #endif
    #ifdef SERIAL_SUPPORT_DMA
  //tInterfaceParameters.ucDMAConfig = 0;                                // disable DMA
    tInterfaceParameters2.ucDMAConfig = UART_TX_DMA;                      // activate DMA on transmission
  //tInterfaceParameters.ucDMAConfig |= (UART_RX_DMA | UART_RX_DMA_HALF_BUFFER); // test half buffer DMA reception
    #endif
    if ((SerialPortID2 = fnOpen( TYPE_TTY, ucDriverMode, &tInterfaceParameters2 )) != 0) { // open or change the channel with defined configurations (initially inactive)
        fnDriver( SerialPortID2, ( TX_ON | RX_ON ), 0 );                  // enable rx and tx
        if (tInterfaceParameters2.Config & RTS_CTS) {                     // {8}
            fnDriver( SerialPortID2, (MODIFY_INTERRUPT | ENABLE_CTS_CHANGE), 0 ); // activate CTS interrupt when working with HW flow control (this returns also the present control line states)
            fnDriver( SerialPortID2, (MODIFY_CONTROL | SET_RTS), 0 );     // activate RTS line when working with HW flow control
        }
    }
    return SerialPortID2;
}

I am writing data (Query) to rs-485 as below

Code: [Select]
My_Write_Func(unsigned char *transBuf,Len)
{
        fnWrite(MyPort2,transBuf,Len);
}


Then read is done by serial callback function

Code: [Select]
//TASK_RS485_CALLBACK
extern void fnCallBackSerialRS485(TTASKTABLE *ptrTaskTable)
{
unsigned char ucInputByte,TP[5];

while (fnRead( MyPort2, &ucInputByte, 1) != 0)
{
           memset(TP,0,5);
           sprintf(TP,"%x,",ucInputByte);
           fnDebugMsg(TP);
// SAVE DATA TO MyBUFFER
if(EMTcnt<200)
{
Mdata[EMTcnt]= ucInputByte;
EMTcnt++;
}
}
}


I have attached the image of my Rs-485 section which used UART2 of LPC2388.

What I observed is that , when I lose RS-485 communication only TX get fail, I can
still have RX line working and I am geting bytes thru the serial callback function.

I dont know why this is hapapning , as RS-485 section was working with my Old code.
I made send/recive level changes like i am using now fnWrite function to send bytes rather then
my SendChar(PortNo,Byte) function, and rather then
my old UART ISR RS485UART2 __irq ISR , rightnow I am using callnback function (as provided in demo) to get bytes form UART2. (Shown in code above).

Can anybudy help me how to get this ractify?


-Thanks in advance
Saurabh
« Last Edit: October 06, 2009, 12:54:03 PM by saurabh »

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3238
    • View Profile
    • uTasker
Re: RS 485 with LPC-23xx
« Reply #1 on: October 06, 2009, 02:58:40 PM »
Hi Saurabh

Since the Rs485 operation is automatic I don't see the need to set the interface to control RTS/CTS (these signals don't seem to be connected).

Also check that your mode is not enabling Hardware Flow Control (this is not visible in the configuration since it is a parameter) since transmission would stop if the CTS line is detected as not asserted (eg. if the line is floating it may allow transmission for a short time and then the state change to stop further transmission - as input discharges).

Regards

Mark


Offline saurabh

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: RS 485 with LPC-23xx
« Reply #2 on: October 07, 2009, 08:17:48 AM »
Thanks Mark!

yes it had issue UART configruation not with RS-485...

I have used config without handshake and HW flow then works well

Thanks...