Revisiting RS485 setup

MrChips

Joined Oct 2, 2009
30,809
Ok, I will make things simple for you.

You have 48 outputs - 16 green, 16 red, and 16 amber.
For each output you need one opto-isolator, i.e. it takes a 12VDC signal and converts it into a microcontroller (MCU) compatible digital logic signal.
You take 16 signals, for example all green outputs and feed them into 16 digital input lines of an MCU. You send this information via RS-485 to a receiver.

Therefore you will need three transmitters and one receiver. The receiver is a MASTER controller and the transmitters are SLAVE controllers.
Each SLAVE has a unique 8-bit address. The MASTER sends a request to each SLAVE, one at a time, and receives the status of 16 LEDs. The data transmitted consists of:

[start] [slave address] [4-char hex code] [2-char checksum] [end]

a total of nine readable characters.
I choose readable text characters because it makes it easier to debug.

If you wish, you can separate the LEDs into 16 channels, i.e. sixteen SLAVE controllers.

Or you can have four channels per controller, i.e. twelve logic signals. This would require four SLAVE controllers.

Of course this would also require some MCU programming skills.
 

Thread Starter

Nick Bacon

Joined Nov 7, 2016
130
I am going to get a micro controller and programmer. I will have a play and see how I get on setting an input for on off signal and output to power an led. Once I have that sorted I can then move onto the RS485 transmission.
 

madhavdivya

Joined Jul 20, 2011
11
Before you get that micro controller Nick, can you give the Arduino Mega a thought ? It has sufficient digital input pins, UART for Tx. and with MaxHeadRoom's suggestion, you should implement the isolation module as well. At the other end, another Arduino Mega could drive the LED's directly too. Added, the Mega is also pretty inexpensive. My two pence.
 

Thread Starter

Nick Bacon

Joined Nov 7, 2016
130
Before you get that micro controller Nick, can you give the Arduino Mega a thought ? It has sufficient digital input pins, UART for Tx. and with MaxHeadRoom's suggestion, you should implement the isolation module as well. At the other end, another Arduino Mega could drive the LED's directly too. Added, the Mega is also pretty inexpensive. My two pence.
Hi, thanks for the input. For this application that type of prebuilt unit would not suit, everything has to be custom built into one complete unit, I am sure they would be easier to implement but I just cant do it.
 

MrChips

Joined Oct 2, 2009
30,809
One thing I will need to do is have an input micro-controller that gathers all the inputs and then output micro-controllers on each display, these will illuminate the LEDS as per the inputs and programming of the input controller. The controllers will communicate over RS485 (built into the controllers).

Can you give me a hint on how this is coded so one processor reads the information from the other?
Let's learn to walk before we can run.

You will need two microcontrollers (MCU) to perform this exercise. The two MCU can be the same kind or they can be different.
We will label one MCU as MASTER and the second as SLAVE.

For starters, you will write code to initialize the UART on both MCU to the same communications hardware protocol. Then you will perform a test to transmit a single 8-bit character form the MASTER to the SLAVE.

The pseudo code for the MASTER will look like this:

Initialize UART
Transmit one character

The pseudo code for the SLAVE will look like this:

Initialize UART
Receive one character
 

Thread Starter

Nick Bacon

Joined Nov 7, 2016
130
Let's learn to walk before we can run.

You will need two microcontrollers (MCU) to perform this exercise. The two MCU can be the same kind or they can be different.
We will label one MCU as MASTER and the second as SLAVE.

For starters, you will write code to initialize the UART on both MCU to the same communications hardware protocol. Then you will perform a test to transmit a single 8-bit character form the MASTER to the SLAVE.

The pseudo code for the MASTER will look like this:

Initialize UART
Transmit one character

The pseudo code for the SLAVE will look like this:

Initialize UART
Receive one character
Thanks again and yes it is a lot to take. By knowing a little about each process, I can try and understand the whole thing. I know it takes a long time to learn and I do appreciate your help.
I can understand the principal of this and I will use the same micro controller for both the master and the slaves. Likely to be the PIC16F18855 28 pin version. I have decided that I will only have 16 inputs (one per channel) I will use other means to generate the two different LED signals from the one input signal. I intend to feed the outputs from the slaves into darlington arrays and use these for led switching.

The slaves will have 17 outputs, 16 channels and 1 fault LED / RELAY.

Each channel will have the input generated through a opto coupler to get them ready for the micro controller inputs.

What I really interested to understand is, how to write to code for the master and slave, i.e for the master the code is straightforward for the input pins as they are the physical pins on that controller. On the slaves, the input pins referred to in the code are not physically on the slave but on the master. How is this coded.

MASTER
READ input pins

TRANSMIT TO SLAVES

SLAVE
Read input pins on MASTER and output to slave
 

MrChips

Joined Oct 2, 2009
30,809
I'm getting to that. Take one step at a time.

I have reversed the assignment of MASTER and SLAVE. You will see why later.
The SLAVE in this application will read the input pins.
The MASTER in this application will output to the LEDs.

The MASTER does not read the pins of the SLAVE.
The SLAVE will read the input pins and send data to the MASTER when requested.

The MASTER will prompt the SLAVE to send information and will receive this information from the SLAVE.

We will have to implement an information communications protocol as outlined in post #21. All of this will come much later.
All of this takes time to understand and program. I don't expect you to acquire all of this overnight.
I am prepared to teach you how to fish, not feed you fish. Are you ok with that approach?
 

MaxHeadRoom

Joined Jul 18, 2013
28,688
If you follow a similar method as Modbus, any communication is initiated by the Master only, all slaves receive the first byte which is the No. or address of the particular slave, all other slaves on the bus ignore any first data that is not their address.
The relevant slave then would answer in the same way with its address followed by the required byte(s) of data.
In Modbus a CRC would end the transmission.
If the number of data bytes is the same every time then you need not necessarily also send a byte packet size/length.
At first see if you can request a register value from one of the slaves, each having a register of a different value.
The RS232 HEX COM package is excellent for testing a Modbus type scenario.
Max.
 

Thread Starter

Nick Bacon

Joined Nov 7, 2016
130
I'm getting to that. Take one step at a time.

I have reversed the assignment of MASTER and SLAVE. You will see why later.
The SLAVE in this application will read the input pins.
The MASTER in this application will output to the LEDs.

The MASTER does not read the pins of the SLAVE.
The SLAVE will read the input pins and send data to the MASTER when requested.

The MASTER will prompt the SLAVE to send information and will receive this information from the SLAVE.

We will have to implement an information communications protocol as outlined in post #21. All of this will come much later.
All of this takes time to understand and program. I don't expect you to acquire all of this overnight.
I am prepared to teach you how to fish, not feed you fish. Are you ok with that approach?
I may be 47 years old but I am happy to learn. I have achieved a lot in the last year with the help of you guys. I have designed, built and had 2 electronic units EMC tested and passed with flying colours. This project will be much more intense, but I would be truly grateful for you to guide me and not do it for me.

As a note, there will be 2 or more, what were slaves and now masters, all identical in design.
 

MrChips

Joined Oct 2, 2009
30,809
I may be 47 years old but I am happy to learn. I have achieved a lot in the last year with the help of you guys. I have designed, built and had 2 electronic units EMC tested and passed with flying colours. This project will be much more intense, but I would be truly grateful for you to guide me and not do it for me.

As a note, there will be 2 or more, what were slaves and now masters, all identical in design.
It is possible to have two or more masters on a network. But before we go that route, we have to identify the need for such structure.
As far I can see from what you have described so far, we need only one master.

Let's clarify this situation before going any further.
This is called "Top-Down Design".
 

Thread Starter

Nick Bacon

Joined Nov 7, 2016
130
The situation is that 90% of the time two displays will be needed and 50% of the time 3 displays will be needed. One will always be mounted within a few feet of the main control unit. A second could be within 600 feet and the third up to 1500 feet, possibly more. All displays will be identical pcbs showing the same thing.
 

MaxHeadRoom

Joined Jul 18, 2013
28,688
If the idea is for a master to request data from any slave and the display's attached to the slaves are required to display certain data originating from the master then you need two identifiers, one for a request data from the master to the slave and one for sending display data to the slave. Usually the byte after the address byte is a data type byte, in this case either request to send or request to display command, use any identifier format you want.
IOW the master has all control and data management.
IF this is the general gist of what you need?
Max.
 
Last edited:

MrChips

Joined Oct 2, 2009
30,809
The situation is that 90% of the time two displays will be needed and 50% of the time 3 displays will be needed. One will always be mounted within a few feet of the main control unit. A second could be within 600 feet and the third up to 1500 feet, possibly more. All displays will be identical pcbs showing the same thing.
Ok, I'm with you now, I think.
It doesn't matter what percentage of the time you have which scenario. We design for all possible scenarios.
Let's relabel our units as follows:

(1) MASTER DISPLAY
(any) SLAVE DISPLAY
(any) SENSOR UNIT

There is only one MASTER on this RS-232 network.
There are any number of SLAVE displays.
There are any number of SENSOR units.

All units can be designed using the same MCU and PCB design. However, SENSOR units are capable of receiving digital logic levels on GPIO inputs. MASTER and SLAVE units are capable of activating LEDs on GPIO outputs. Both of these functions (input and output) can be designed into the same PCB.

The MASTER is always in control of the network. At any time, MASTER shall request data from SENSOR units, one at a time. SENSOR units will respond with requested data.

At any time MASTER may send data to SLAVE units to be displayed on LEDs.
 

Thread Starter

Nick Bacon

Joined Nov 7, 2016
130
Hi, that is exactly how it should work. The system is modular and 16 input is the maximum, will be anything from 8 to 16 selected by user.

The slave units interpret the data from the master and theoretically can do anything with it depending how the slave is programmed. In this case the slaves will display the data as either a green or red led for each inputs into the master.

The master will also perform the fault checking function and if a fault is present, will output to a relay locally and a fault led will illuminate on the displays.
 
Top