The blog of a dedicated radio amateur and electronics enthusiast

"Having fun on the air and in the workshop - communicating and creating"

17 February 2019

Adding a RS485 interface to an embedded control project

A serial connection to a pc can be used to send/receive data to/from a micro-controller unit ( MCU ) based project. Instead of using usb I have programmed a MCU's serial (E)USART ( (Enhanced) Universal Synchronous Asynchronous Receiver Transmitter ) peripheral and written my own pc software in the past for this purpose.
The USART has receive (RX), transmit (TX) and ground (GND) connections like the RS232 type serial COM ports on older pc's. For higher speeds or longer distances, however, RS485 is a better choice. [ note: RS = Recommended Standard ]. The MCUs and development boards which I use don't have RS485 interfaces. So I made one to test its capabilities. I used a 32MHz MCU clock. Therefore the maximum data rate possible ought to be 4Mbits/s ( 4Mbaud ).
As RS485 is a physical and electrical specification for the bus ( not a protocol ), the protocol used by the USART for RS485 can be the same "start-stop signalling"; i.e., one start bit ( always 0 ), 8 bits ( data byte ), one stop bit (always 1).
TX output from MCU USART. L-R: idle 1, start bit 0, 8 data bits, stop bit 1, idle 1
The image above shows, reading left-right, binary data bits 11001001, with the least significant bit ( LSB ) actually sent first from the left. Reversing the order to put the LSB in the normal position on the far right when writing the value down gives binary 10010011, which is also decimal 147. What really interested me was when I measured the duration of a data bit with the vertical cursor lines; 250nS, equivalent to a data rate of 4Mbaud.
MCU board with RS485 interface fitted - inset view from above
I made a RS485 interface on a daughter board which plugs into a MCU development board. As this uses 3.3V logic levels, ( 0 = 0V, 1 = 3.3V ), I chose the MAX3485ESA chip for the RS485 line transceiver. This chip has one receiver and one line driver; so works in half-duplex mode. Unlike RS232, the RS485 physical link is a twisted pair of wires. I already had 4.5 metres of this. The data signal I used was the voltage on the slider of a pot ( blue knob ), sampled by the MCU 10bit analogue-to-digital converter peripheral and sent to the USART. So. for example, the value 147 would equate to 474mV.
Terminal RX window showing data received from MCU at 2Mbit/s
This setup worked perfectly up to 2MBaud, as shown above, using my favourite terminal emulation software. Unfortunately the same virtual COM port could not be opened when I tried 4MBd ! In future experiments I will see if this limitation was due to the USB-RS485 converter ( not shown ) which I used to connect to a pc at the other end of the link.