EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

CHECKING WHETHER RS 485 IS WORKING

Started by appujohn 7 years ago8 replieslatest reply 7 years ago679 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.First time iam doing code with rs 485.

#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)
{
      FIO2SET|=(1<<2);               /*TRANSMIT MODE*/
      U0THR = 'A';
      while (!(U0LSR & 0x40));
      FIO2CLR|=(1<<2);
     while (!(U0LSR & 0x01));
      data1 =U0RBR;
}

Is my code correct,if not please help me with changes. how to know whether my code is working using hyperterminal .please provide valuable suggestions.
[ - ]
Reply by stephanebFebruary 22, 2017

May I ask why you posted the same question twice today in this forum?

[ - ]
Reply by appujohnFebruary 22, 2017

Please find the changes that I had from the previous question.In order to make my question more clear I posted it twice.

[ - ]
Reply by BEBSynthesizersFebruary 22, 2017
RS485 is half duplex in your case (you have connected /RE and DE). So you either transmit or receive, but you can't try to echo yourself to check if it works.

The only way to test the code is to have another RS485 test device on the other side sending data.

About your code : this forum is about DSP, not microcontrollers. I am afraid that you will not get a code review from here (and moreover, I have to say that the description of your problem is not clear. You probably know what you talk about, but from here, it's not clear - at least for me)

Benoit

[ - ]
Reply by stephanebFebruary 22, 2017

Hi Benoit,

the OP didn't post on DSPRelated, something weird happened with the forum platform that made the post appear on EmbeddedRelated AND DSPRelated.  Still trying to figure out the problem, fist time it happened in a year!

Stephane

[ - ]
Reply by Tim WescottFebruary 22, 2017

And here I was wondering if you'd made a cross-posting feature!

[ - ]
Reply by stephanebFebruary 22, 2017

Haha, no but I might implement this in the near future, but it will be only for highly trusted users like you to use.

[ - ]
Reply by jkvasanFebruary 22, 2017

AJ

RS485 communication is in essencee UART communucation with an enable signal. To transmit, make P2.2 high and send data through UART.

For reception, P2.2 must be low. If you have a converter on the PC side, use any terminal emulator like Docklight, Teraterm etc.

If you have further queries, you are welcome. 

Regards

jkvasan

[ - ]
Reply by Tim WescottFebruary 22, 2017

Getting a serial link up and running is always a real pain in the behind.  I've been in this embedded stuff for decades, and I still occasionally end up fumbling around for days getting one working.

Do you have an oscilloscope?  If you're going to do serial stuff, a cheap USB O-scope will be all you need and will be a tremendous help.  If that's not in your price range, I strongly suggest that you get a second RS-485 interface for your PC, and make sure you can get the two of them talking to each other.  One of the special joys of serial interfaces is to flog device A for days when the real problem is on device B.

The 2024 Embedded Online Conference