0

I am attempting to use my arduino uno's rx and tx pins to receive an ASCII character string from an rs485 device transmitting at 2400 BAUD with 0.100Sec between transmissions, and then parse and output certain pieces of the string to a 16x2 LCD attached to the arduino.. I am getting some data strings, as I checked with my scope, coming in on the rx pin 0-5vdc square wave. Anyone with sample code to receive rs485 ascii strings into a buffer would be helpful.

GoJo2332
  • 31
  • 2
  • 4

1 Answers1

1

RS485, RS422, and RS232 are different schemes for the hardware link layer. By that I mean, those specifications only describe what is on the wire. A transceiver chipset converts the wire signals back to the logic level signals that are connected to Arduino, or any other device. At the logic level the Arduino sees, any of the RS___ signals will look the same.

A USART converts the bit stream to a byte (this can be software or hardware). The USART does not know about the signal levels on the wire, it operates solely on the logical level bit stream. The UNO contains one USART that is available on the TxRx pins.

So your code on the microcontroller does not need to be different, RS232 or RS485. All the Serial code samples you see will function fine. You tell the Serial library baud, stop bits, and parity, and you are done. Set the serial connection to 2400, and the Arduino will start seeing characters.


Caveat

RS485 is sometimes used in half-duplex mode. This means you cannot receive and transmit at the same time. If you are wiring for half duplex, then you code must be certain you are not transmitting while some other device is still transmitting.

jdr5ca
  • 2,809
  • 14
  • 25
  • Thank you. Do you think 2400 baud is too fast? I am transmitting over a two conductor shielded cable asapproximately 60ft in length. Also, how to I go about telling the arduino that I Want to use start and stop bits and parity? Since im only using arduino as a r eceiver, is it necessary that i set it up for transmit also since we are parity checking, or is that not a handshaking method – GoJo2332 Aug 17 '13 at 12:55
  • Too fast? No, 2400 is incredibly slow. You are using RS485 because the differential signalling allows long distances with the ability to reject ground noise between transmitter and receiver. You could run 60 feet over plain RS232. You will be able to run much higher baud rates, start at least 9600. With a shielded cable and RS485, you should be able to run faster. I would expect you could run 115k over such a short distance. Pay attention to the terminator resistors and you will be fine. Don't waste effort on stop bits and parity. Just set Serial.begin(9600) and get running! – jdr5ca Aug 17 '13 at 19:43
  • Very helpful, thank you. Im new to the whole computer world, im an electrical engineeri.g student. Do you think the serial read function will yield ascii characters? – GoJo2332 Aug 18 '13 at 01:30
  • It will for sure. The RxTx pins are logic level. You would connect a transceiver chip either way, single ended RS232 or differential RS485. – jdr5ca Aug 18 '13 at 03:18