How do I connect several Arduinos through RS485 with the SN75176 chip?


Hello, I want to connect several Arduinos together in a star network (1 Master, several Slaves), but they're too far apart, so I can't use I2C.

I researched a bit and found that I can use the serial protocol RS485 and that I can use the SN75176 or the MAX485 chips to do it.
Being the MAX485 more expensive than the SN75176, I bought the latter.


My problem is: now that I have the SN75176 (I have two, actually), what do I do?
I have no clue whatsoever.

I found some circuits for the MAX485, but I don't quite get how I should connect them to the Arduino.. Anyway, the chip I have is the SN75176...


The only thing I find with Google is about DMX - for lights and stuff like that -, but I'm not interested in that.

I just want several Arduinos to send data gathered from temperature and humidity sensors to another Arduino...



Thank you very much. :)



sort by: active | newest | oldest
Always start with the data sheet
http://focus.ti.com/lit/ds/symlink/sn75176b.pdf

See Figure 17.

You need THREE wires to talk RS485, RX and TX from the serial interface, and one other to set the communication direction.

RS485 can be used in two ways, a 4 wire interface and a two wire. In the 4 wire, one pair are used for transmissions, the other pair for receiving, usually point-to-point. For your topology, you want the two wire interface and you want to design a master -slave interface. All your satellite units will be slaves, and will ONLY transmit when they have been addressed by the master.

So your code in the slaves needs to read a switch which sets up an address, your slave listens for the master to say "slave x transmit" and if X is its address, it replies, after a delay of a few msecs for the bus to clear, by asserting the transmit line of the 485 driver. As SOON as the message has gone, the slave de-asserts the transmit line and shuts up. 

At the master end, the master asserts the transmit line to its 485 driver, and transmits the address it wants data from, then it immediately schanges to receive mode and waits for the maximum time that the transmission can take, or until it receives a reply, whereupon it switches back to transmit mode.

There are LOTS of wrinkles in master-slave communications There have been lots of discussions, on a different processor, in the froum at 8052.com, but the lessons about collisions, timings etc are all valid for whatever processor you use.

Steve

pedrotome (author)  steveastrouk7 years ago
"You need THREE wires to talk RS485"
"For your topology, you want the two wire interface"

Well? :)


I still have a major problem the datasheet didn't fix: how do I connect the chip to the Arduino and how do I connect the chips to themselves?

Like Arduino1_pin_D0_(RX) connects to Chip1_pin_A,
Arduino_pin_D1_(TX) connects to Chip1_pin_B.
With that the Chip1 converts the Arduino1's serial to RS485.

Now, to communicate between the Arduinos (through the Chips),
Chip1_pin_C connects to Chip2_pin_D,
Chip1_pin_E connects to Chip2_pin_F,
etc,
and THAT'S IT! JUST SEND ANYTHING FROM SERIAL AND IT'S DONE!

Why doesn't the datasheet put it that simple? :(
You need one to control the interface direction, and two signal wires. That's three.
A and B are the RS485 wires.

RX to pin 1
TX to pin 4
DIrection to 3 and 2. High on the direction pin to transmit, low to receive.

Personally I would invert the logic on there, because the processor resets high on all outputs AFAIR.

ALL your units connect in the same way whether they are slaves or the master.
pedrotome (author)  steveastrouk7 years ago
OK, I'm having some problems. I have one Arduino sending values gathered from a potentiometer to a second Arduino, which is reading them and making an LED blink according to the values received.

Here's my setup:

Arduino1 (Sender):
Chip1's pin 1 not connected (because I'm only sending).
Chip1's pin 2 connected to Chip1's pin 3, which is connected to Gnd.
Chip1's pin 4 connected to Arduino1's TX pin (pin D1).
Chip1's pin 5 connected to +5V.
Chip1's pin 6 connected to Chip2's pin 6.
Chip1's pin 7 connected to Chip2's pin 7.
Chip1's pin 8 connected to Gnd.

Arduino2 (Receiver):
Chip2's pin 1 connected to Arduino2's RX pin (pin D0).
Chip2's pin 2 connected to Chip2's pin 3, which is connected to Gnd.
Chip2's pin 4 not connected (because it's only receiving).
Chip2's pin 5 connected to +5V.
Chip2's pin 6 connected to Chip1's pin 6.
Chip2's pin 7 connected to Chip1's pin 7.
Chip2s pin 8 connected to Gnd.


Here's the code: linky!


The problem is: it's not working! The Receiver doesn't receive the values the Sender sends.
The received values are usually jumping from 48-53. It's weird.

I don't know what to do...

We are connecting two arduino's in a master slave architecture , To send strong signals without distortion to our slave we are using SN75176 ic, I am confuse that how to do coding at master and slave side ? Please help

Thank you very much

we are communicating two arduino in master slave architecture. To send strong signals to our slave which is arduino board , we are using 75176 ic , but there is a confusion that how to do coding on master and slave side? Please help!

Thank you very much

we are communicating two arduino in master slave architecture. To send strong signals to our slave which is arduino board , we are using 75176 ic , but there is a confusion that how to do coding on master and slave side? Please help!

Thank you very much

AJoao3 years ago

Hi,

How I do to make this connection:

ArduinoA -> I2C -> SN75176 -> RS485 -> SN75176 -> I2C -> ArduinoB

I was think to use the Wire and RS485_protocol libraries.

But I dont know to make this connection... someone can help me, please?

What is chip1 and chip2 ? The RS485 transceiver ?

As I see it, you have chip1 wired to always RECEIVE, since as I said High on the direction pin to transmit, low to receive.

You DO have chip2 wired to always receive  at least.

transceiver 6 and 7 should have a resistor of 100 Ohms on each each of the transmission line

Steve
pedrotome (author)  steveastrouk7 years ago
Sorry, my bad... Blame copy-pasting.
Chip1's pin 2 connected to Chip1's pin 3, which is connected to +5V.
The direction is High, so it's in Transmitting Mode.

Chip1 and Chip2 are two different SN75176 chips.
Each Arduino is connected to one SN75176 chip: one for transmitting and one for receiving.
I'm supposed to use two, right?

I added the two 100 ohm resistors. It's still not working right.
Put your oscilloscope on the lines and see what's happening. If you're getting a reply I'd suspect baud rates, or you have something crossed up.
http://www.zeitnitz.de/Christian/scope_en
pedrotome (author)  steveastrouk7 years ago
Hmm... I will try that, then. I'll just do it with a REAL oscilloscope, which will be available in about 2 weeks. I'll post something here then. Meanwhile, I'll be working on another part of this project. Thank you a LOT for your help. See you in about 2 weeks. :)
You don't need a real scope for this one, a sound-card scope will work quite nicely, since its all AC signals you're looking for. Also make sure you really, really haven't swapped A and B over on the link. Been there, done that......
pedrotome (author)  steveastrouk7 years ago

Just to be REALLY sure, is this schematic I made in Eagle 100% correct?
Might as well just ask it before researching for 100 years how to NOT blow up my soundcard due to over-voltage input. Read bellow.

Quote:
The signals for the oscilloscope can be internal to the computer (MP3 player, function generator etc.) or from external sources (line-in, microphone). For external sources care has to be taken, not to exceed the voltage range of the inputs. The range is usually only ±0.7V !! If higher voltage need to be analyzed, a voltage divider has to be used. Additional protection diodes are recommended in order to avoid any damage to the sound card and to the computer.
I'm not sure if the terminating resistors are mandatory on a short link, but they won't hurt....

And a protective network on the soundcard input wouldn't be a bad idea.....
pedrotome (author)  steveastrouk6 years ago

About the resistors.. Do you mean
Pic1
Pic2
Pic3
Pic4
???
I've seen various resistor positions in forum posts and stuff like that and they just made me confused...
Pic 1
pedrotome (author)  steveastrouk6 years ago
Thanks a lot.
I think I figured out what's wrong! YAY!

I think it's about the way the Arduino handles number types and stuff... It's got something to do with integers, bytes and all that -blam!-.

I'll say something when I finally get it done (soooon). :)


Again, thanks a lot for your help. :)
hey i want to connect several arduinos via rs-485. At the same time one of the arduinos , lets call it master arduino is feeding data to computer also via rs 232. So is there a possible way so that data between rs 232 and rs485 doesnt clash...
pedrotome (author)  ngoel15 years ago
I never tried that, but I ASSUME you'd just need to wire it in parallel to the RS485 network.

If that doesn't work, just buy another SN75176 and connect it to the computer the way you connected the Arduinos (in parallel).
Note that RS485 is only happening between the different SN75716 ICs - the Arduinos are always working with RS232, ie, RS485 is only being used for the long range, noisy trip between the SN75176 chips of each Arduino.


Think of it like this: ArduinoA -> RS232 -> SN75176 -> RS485 -> SN75176 -> RS232 -> ArduinoB
You're REALLY going to struggle to do this with a single UART. I know you can invent some horrible kludgy way, but its not worth the effort.

Hang one of these babies on the SPI bus


They're great for doing multi-protocol stuff. Now you can accept data in one format, do minimal processing on it, and squirt it out in another.
You're REALLY going to struggle to do this with a single UART. I know you can invent some horrible kludgy way, but its not worth the effort.

Hang one of these babies on the SPI bus


They're great for doing multi-protocol stuff. Now you can accept data in one format, do minimal processing on it, and squirt it out in another.
Got to be worth a best answer getting it this far ....
pedrotome (author)  steveastrouk6 years ago
Of course! I just figured that... being the ONLY answer... Anyway, it was an AWESOME answer. :p
You'll have fun with this project. Ideally you want to add some CRC checking to the string you send to make sure it arrives intact.
pedrotome (author)  steveastrouk6 years ago
OK, I've finished it!
The hardware part was fine all along. The problem was the code.
I made the code for the Transmitter and the code for the Receiver separately.

I still need to add that CRC checking, though. Will do it for another version. :p

Here's the code:
Transmitter
Receiver

Thank you A LOT. I owe you a god damn star. :)
AH ! you didn't translate to ASCII first ?
pedrotome (author)  steveastrouk6 years ago
Yeah, it was something like that lol.

One final question:
I want to connect several Arduinos to one Master Arduino.
Is this the way to do it?
I based it in the last picture of the 13th page of the MAX485 datasheet.

Then I just have to program something like.. I don't know..
assign each Slave a letter and if the first thing they read is their letter do <something>?

Like...
Master wants to collect data from Slave2, which was assigned the letter 'B'. The Master sends through Serial the letter 'B', every Slave will read the letter 'B' BUT only Slave2 will know that means the Master wants data from him, so Slave2 will be the only one to send data to the Master.

Is this correct? It seams pretty easy to accomplish... Is it compatible with my circuit above? Will the circuit even work?


Thanks! And sorry to bother you again! :p
That will work, there are "rules" about network layout, this is a star which should work fine.

The cables shouldn't be shorter than 1metre AFAIR.

Your protocol is OK, as far as it goes, but you need to write VERY carefully to make sure your slaves don't stay asserting the bus. There need to be watch-dog timers in your code that automatically reset the slave, and you need CRC to make sure that the returns are valid.
pedrotome (author)  steveastrouk6 years ago
I've been searching about CRC and can't find much: only complicated stuff not related to the Arduino. Isn't there any other more commonly used method of data integrity verification? I'm still a noob testing the waters. :/
I am having same set up as yours for communicating with RS485 and arduino with the SN75176 chip.I downloaded your code and programmed my arduino for master and slave but its not working.have u recently changed anything on the code or set up?
No, CRC is the standard technique, MD5 might be do-able, but 16 bit CRC is very easy to implement. You may have to write something. You can start with a parity check, that'll find some screwups.