EmbeddedRelated.com
Forums

checking whether RS 485 is working

Started by appujohn 7 years ago3 replieslatest reply 7 years ago732 views

Inorder  to check my rs 485 port,i had connected my lpc2378 (rs485) with my PC through ADAM-4561(1 port isolated USB to RS 232/422 485converter).Now how to check it and where to check it?????.i am very new to microprocessor development and am still figuring out the way things work on the LPC2378 . So up front apologies for "stupid" questions.i had done the programing.

#include <LPC23xx.H>
#include <stdio.h>
int main (void)
{

PCONP |= (1<<3)                       /* power for uart 0 */
PINSEL0 |= 0x00000050;                /* Enable TxD0 *//* Enable RxD0 */
U0LCR = 0x83;                         /* 8 bits, no Parity, 1 Stop bit */
U0DLM = 0x00;
U0DLL = 0x78;                           /* 9600 Baud Rate @ 12MHz Clock */
U0FDR = 0xA3;
U0LCR = 0x03;                          /* DLAB = 0 */
U0FCR = 0x81;

while(1)
{
      U0THR = 'A';
      while (!(U0LSR & 0x40));
while (!(U0LSR & 0x01));
data1 =U0RBR;
}
[ - ]
Reply by Tim WescottFebruary 22, 2017

You're leaving lots of details out.

I assume you mean two-wire RS-485, which means that communications are all half-duplex, and you have some protocol built on top of the physical layer so that each processor knows when to transmit.

For manually checking the phy layer, you want to enable transmit on one side or the other, make sure that transmit is not enabled on the receive side, send bytes, and make sure that they are received on the other end ('A' works, but I'll often send the Gettysburg Address -- you can choose whatever speech or poem is significant to you.  English-speaking nerds the world over would probably like "One Ring to Rule them All, etc., etc.")

I see you transmitting in the above code, but I don't see you turning the transmitter on.  I also see you receiving at the same time -- but RS-485 is half-duplex; at most you should be receiving back your own data.

[ - ]
Reply by maruthi.hrFebruary 22, 2017

Hi Appujohn,

Is your LPC2378 board having a RS485 level converter (transceiver)? If yes, then you can connect USB-RS232/422/485 converter PC and use any terminal software like teraterm to check if communication is working.


All the best!

[ - ]
Reply by gobicFebruary 22, 2017

If U0THR is your transmit register make sure you set high the Enable PIN for RS485

and if U0RBR is your receive register make sure the Enable PIN for RS485 is low

I have not noticed any Tx Enable/Disable in your while (1) code.