RJ45 Serial connection to Arduino

Greetings,

Been asked by my boss to do some work, however, this work will require me to interpret serial signals carried over RJ45.

I've order an RJ45 connector breakout, however, am unsure in both software and hardware how to interpret the incoming data?
How would I go about reading the incoming data? It's wired to 4 leads, TX, RX, CTS and what I believe should be ground according to the breakout diagram I have for the plugs here.

Thanks,

Iestyn.

Been asked by my boss to do some work

What a cad, maybe you should get a new boss, personally I wouldn't tolerate such behaviour.

Meanwhile, how about some more info, for example what voltage levels are on this cable? It sounds like it will be RS-232 but could just as easily be TTL.

how to interpret the incoming data?

What is this data? What's transmitting it? Any data sheets for the transmitting device?

If you have no info and are trying to reverse engineer a protocol the first thing to find out is the voltage levels, then you can use a scope or make up an interface and use a logic analyser to have a look at the data and work it out.


Rob

Hi, thanks for the reply.

I'm not needing to entirely reverse engineer the protocol, basically, various packets are sent representing different things. Eg, a start signal, a time, etc. All I need to do is sample some incoming data for a few seconds and send that over to a contact who can tell me what each signal represents in terms of real life events in the system.
Why they couldn't just provide me with a complete list outright I don't know but hey Ho.

Anyway, idea being once I have a list of codes and what they mean, I plan to check incoming packets for data of certain types, eg start or stop, and run functions based on them.

The feed comes originally from an rs232 port on a computer, but this is passed through some junction boxes to duplicate the lines out to several network units (which is what the aim of this is, to replace the existing network units).

I've been told (with reasonable certainty) that the baud rate should be 9600 with 8 n 1.

I do have access to an oscilloscope, not a logic analyser, however. May also be worth noting I have in my possession at max232 chip (which I believe I will need for converting logic levels, although I'm not entirely sure on its implementation).

Cheers! :slight_smile:

There are a lot of variables when doing this sort of thing but it sounds like you can fix most of them.

I would firstly scope the signal to verify that it's RS-232. If so wire up the MAXS232 chip and connect an Arduino's Rx pin to it's output. If it's TTL wire directly to the Arduino. If it's something else tell us what.

Then write a small sketch that sets the port to 9600,8,N,1 and prints the bytes received to the monitor and see if the data makes sense. If not start playing with the baud rate etc, hopefully before long it will.


Rob

Hi, thanks for the reply again. Will drop in again early next week to test it. (Oscilloscope is locked up in the workshop and I don’t have a key heh).

Thanks again for your help so far.

You might use a breakout adapter in the current wired setup and attach it to another computer running a serial sniffer to possibly see what is being sent.

Hi,

time to update.

Did verify that it was RS-232 I was working with, so that’s a start.
After a week or two of messing with it, I came to the conclusion the MAX232 chip I had was dead. Replacement arrived today.

Trying to verify it’s all working before wiring it up to the RJ45 breakout adapter I had made, by using software serial to receive a signal sent from the hardware transmission line. Unfortunately however, I believe I’m missing something with the use of the software serial library…

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup()
{
  Serial.begin(9600); 
  mySerial.begin(4800);
  mySerial.print(12);
  
  delay(1000);
}

void loop()
{
  if(Serial.available())
  {
    Serial.println(Serial.read()); 
  }
  
}

I intended that this code would simply send the number 12 from pin 11 (software Tx), to pin 0 (hardware Rx), however the output in the serial monitor is simply
“6
24
120”

Why is it not just 12?

Where is the read from mySerial? That code simply echoes data from the PC back to the PC.


Rob

It was deliberate.

I'm trying to determine why when sending 12, I receive 3 bytes as opposed to 1.
As it stands, I am just running a single wire from pin 11, to pin 0; sending the number 12, but receiving three bytes. Why is that?

So I decided to go along this path instead:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX

void setup()
{
Serial.begin(9600);
mySerial.begin(4800);
Serial.write(“initialising…”);
}

void loop()
{
mySerial.write(52);
if(mySerial.available())
{
Serial.write(“Found data!”);
Serial.write(mySerial.read());
}
}

But software serial doesn’t appear to be reading any incoming data. (initialising prints, nothing else).

Well as it stands what you send is irrelevant as you aren't reading from mySerial.

As to why you get 3 bytes from the PC, no idea. It could be crap on the line after a power up. Is it the same values every time? Does it do the same after you press the reset button?


Rob

Yes. If I modify my code to send it again, the same output occurs.

I'll try with my mega tomorrow and will update. Cheers for your help thus far. :slight_smile:

Hi again,

I've made some progress here, but struggling slightly with the formating of incoming data.

I've got the MAX232 running fine, using a feedback loop. On the computer I'm using, I've installed an RS232 serial analyzer which is capable of sending data out of the RS232 port in either DEC, OCT, BIN or Ascii.
This, in turn, I've connected up to a breakout adapter, and Identified the Tx and Rx lines by looping data back to the PC.

I've hooked up the Tx line from the PC to one of the RS232 in pins on the chip, and the TTL output of that pin is being fed into the Rx2 pin on my Arduino mega (2560).

I'm using this code;

int count = 0;

void setup()
{
Serial.begin(9600);
Serial.println("Hello Computer.");
Serial3.begin(4800);
Serial2.begin(4800);
}

void loop()
{
if (Serial2.available())
Serial.println(Serial2.read());
else
{
Serial3.println(count);
count++;
delay(500);
}
}

The count integer and transmissions on Tx3 are there for debug purposes. My soldering wasn't fantastic so suffers from a loose connection on one of the wires.

Now, I'm sending the data out in Ascii ("Hi"). Serial monitor from the arduino is printing out the number "156". This is definitely coming from the PC as when disconnecting the line, I get nothing.
I assume this is a formatting issue. Any advice?

Thanks in advance.

edit: I'm a fool. Didn't change the baud rate to match pc. Sorted. :slight_smile:

Okay, next issue.

Using Portmon on the computer to monitor outgoing serial traffic which is yielding as expected of the software I'm running on it (alternates between 12 and 32 in Hex).

Trying to read the data coming in using the serial monitor with "Serial.print(Serial2.read(),HEX);", but I'm only getting groups of 3 zeroes out of it.

Any suggestions?

Yep, post the code. (in CODE tags, not QUOTE)


Rob

int count = 0;

void setup()
{
Serial.begin(9600);
Serial.println("Hello Computer.");
Serial3.begin(4800);
Serial2.begin(9600);
}

void loop()
{
if (Serial2.available())
Serial.print(Serial2.read(),HEX);
else
{
Serial3.println(count);
count++;
}
}

So just to refresh my memory you have a widget spewing data at 9600 and for the moment all you want to do is echo that to the PC?

All I can think of is that the serial format does not match what the Arduino is set for.

I've been told (with reasonable certainty) that the baud rate should be 9600 with 8 n 1.

Did you ever verify this?

Have you tried different baud rates?

Is there ever a brake in the data sent from the widget? If not it will be very easy to get out of sync and never see valid data (although I would not expect to see 0s in this case).

If you reset the Arduino 10 times do you get 000 every time? If so it really looks like a baud rate issue.


Rob

Hi, thanks for your reply again.

I was unable to verify 9600 8n1 was definitely the correct parameters. Is there a way of verifying it without just stepping through and trying every possible baud rate and format?

The program updates periodically. In it's idle state, it spits out 12 and 32 in hex every half second (alternating). IE

at t = 0; sends 12
at t = 0.5; sends 32
at t = 1; sends 12
at t = 1.5 sends 32

etc.

The issue is reproducable regardless of how many times I reset it.

I've emailed a contact of mine who may have the source code for the software running on the PC. Hoping to ascertain from him for certain the data format and baud rate.

So it sounds like it’s sending every .5 seconds and it’s constant, that’s something.

Is there a way of verifying it

Yes, use a scope or logic analyser. If you don’t have an LA they can be bought for $150 or less, get one.

stepping through and trying every possible baud rate and format?

That’s the other way. Stop bits won’t matter and you have no direct control over parity and data bits without delving into the registers, so that just leaves baud rates, 5 minutes tops to try all the standard ones.


Rob

Wrote a program to step through all the baud rates, found that the baud rate is in fact 600.

Many thanks for your help. It seems at this point we've made it to a point where the software is talking to the arduino correctly.

I thank you for your help again good sir. Would have been a far slower process without you!

Regards,
Iestyn.