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.
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
My_Write_Func(unsigned char *transBuf,Len)
{
fnWrite(MyPort2,transBuf,Len);
}
Then read is done by serial callback function
//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