Microcontrollers communicating with other microcontrollers over RJ45 cables... how is this done?

Thread Starter

Mahonroy

Joined Oct 21, 2014
406
Hey guys,
A quick overview of what I am trying to accomplish:
I have a microcontroller that connects to the internet via wifi, and also has an onboard RF module for non-wifi communication with other devices.
The other devices also have a microcontroller with corresponding RF modules, but no wifi.

I want to have the option so that the other devices can be plugged in via RJ45 cable to bypass the RF for a more reliable communication if this is desired.

What is a good method for microcontrollers to send small amounts of data like this over an RJ45 cable? The amount of data per device is less than 32 bytes, and it does not need to be high speed, just high reliability. In most scenarios, the cable probably won't be longer than 100 feet.

The plan is to have 1 RJ45 port per device. What if the devices could be daisy chained, so all of the other devices share the RJ45 cable in parallel? Is there another method that is better for this?

Thanks and any help/advice is greatly appreciated!
 

LesJones

Joined Jan 8, 2017
4,191
I would suggest just using serial communication using the USARTs on the microcontroller. I think you would need to use proper RS232 signal levels rater than jut 0 to 5 volts. Also keep the speed down to about 2400 bauds. (HC-12 modules would be suitable for the wireless links)

Les.
 

MaxHeadRoom

Joined Jul 18, 2013
28,702
For multi-drop applications you could use RS485.
One station is set up as a master and the slave devices have a unique address.



Max.
 

Thread Starter

Mahonroy

Joined Oct 21, 2014
406
Thanks for the info so far!

So it would work like this?:
* Slave devices all listen until they receive their serial number identification, followed by a command, at which point they will output their sensor data, and a termination character.

Couple questions I had:
1. Is there a specific communication scheme I should use?
2. I want power to be present on the RJ45 cable as well. Should I pick a twisted pair for power and ground? Or use 2x twisted pairs (e.g. a full twisted pair for power, and a full twisted pair for ground (4 wires total)).
3. For the 2 wires used for communication; would I use 2x twisted pairs, each paired with a ground?
4. What voltage should I use for the communication? Seems the higher the voltage the better?
 

kubeek

Joined Sep 20, 2005
5,795
Depends on how you imagine the communication. If there is only one master who asks all the slaves for information, like one central unit and a bunch of sensors, then I´d use RS485. If you want more masters, like a bunch of central units talking to a bunch of sensors independently, then I´d go with CAN bus.
 

MaxHeadRoom

Joined Jul 18, 2013
28,702
So it would work like this?:
* Slave devices all listen until they receive their serial number identification, followed by a command, at which point they will output their sensor data, and a termination character.

Couple questions I had:
1. Is there a specific communication scheme I should use?
2. I want power to be present on the RJ45 cable as well. Should I pick a twisted pair for power and ground? Or use 2x twisted pairs (e.g. a full twisted pair for power, and a full twisted pair for ground (4 wires total)).
3. For the 2 wires used for communication; would I use 2x twisted pairs, each paired with a ground?
4. What voltage should I use for the communication? Seems the higher the voltage the better?
1/ RS485 can use the UART module on the Pic's as @LesJones suggested, up to 8bit packets.
2/ You could use 4 conductor with 2 pair shielded.
3/ You don't really require a GND with RS485, it is optional.
4/ You can use up to 12v for the MAX485.
You can make up the protocol you like for data, for e.g. Modbus uses the first byte as the address, second byte as the Func (read/write etc) next byte the data length (1,2 or 3 bytes), followed by a pair of bytes containing the CRC.
You could make it as short or as long as you wish.
For example if all data was a couple of bytes overall, you can eliminate most of the checking etc, and keep the baud rate between 2400 and 9600.
Max.
 

John P

Joined Oct 14, 2008
2,026
If you run power through your cable, you need to worry about voltage drop. It can work, but it depends on the length of the cable, the size of the wires in it, power consumption of each unit, and obviously how many units you have. If you do this, you might send out 8V or 12V on the cable and put a 5V regulator on each board. That way you don't have to worry about lost voltage, unless it's too much. But then how do the units run when they're in radio mode? It's a complication if you have to power things two different ways.

RS485 involves a wire pair twisted with each other, not each of 2 wires twisted with ground. It doesn't matter how the power wires are arranged.

Protocol could be Modbus, or you could design your own, but there's never been a "standard" for RS485. You may find it's a little tricky to get a whole bunch of nodes communicating properly when they have to listen for instructions from the master, enable their drivers to the bus, transmit their stuff and then clear the line again. It's considerably worse if you don't know for sure which units will be on the line at any given time.
 
Top