RS-485
Here we will log the development of RS-485 interface onto BoSL sensors.
Requirements:
- Upload Code
- Sleep/Wake sensors
- 3V3 5V interoperable
- Minimum wires
- Bus operation
Uploading code is the first issue to be addressed. RS-485 is half-duplex over a single twisted pair. This presents issues during uploading as it requires full duplex operation.
The easiest solution is to move to full duplex. This would require 2 twisted pairs thus a full bus likely 8. Ideally less wires would be needed.
Another solution is to modify the uploading program and use another wire to send to the sensor whether it should be receiving or sending data. This would likely require special programmer hardware and software.
It is also possible to update the Arduino bootload to recognise when it needs to be sending and receiving data. This may be possible, but it is uncertain how reliably this would work or if it is feasible.
Additional wires could also be left exposed on the sensors so that uploading remains possible via these. This solution is is difficult as it introduces another entry point for water.
A solution which looks promising is illustrated below. It is a 6 wire system. It enables uploading of code over half duplex RS-485 by utilizing the wake line for the programmer to receive data from the sensor. This allows for the full duplex needed while uploading. It should be noted that this system may have a hard time uploading over very very long cables as the TX from the sensor will not be over RS485. The exact length is yet to be determined however is likely in the range of 10s of meters.
This solution works because the use of TX and WKE are never needed simultaneously. That is that if the sensor is sleeping TX is not being used so WKE is free to be driven high to wake the ATmega. Conversely, when the sensor is being programmed it is already awake and so WKE signals do not need to be sent, freeing the line for TX.
A full list of wires is:
- 3V3
- GND
- RST/5V
- WKE/TX
- RS-485 A
- RS-485 B
Some testing will need to be done on what is the best arrangement of these onto 3 twisted pairs but a first iteration is:
Signal | Wire |
---|---|
3V3 | Orange |
RST/5V | Half Orange |
GND | Green |
WKE/TX | Half Green |
RS-485 A | Blue |
RS-485 B | Half Blue |
The option may also be available to use RST as a 5V rail. This is possible if the ATmega reset pin is 5V tolerant. On reading the data sheet it looks like a diode may be nessesary to protect the reset pin.
https://au.element14.com/texas-instruments/sn65hvd75dgk/rs422-rs485-txrx-20mbps-3-6v-vssop/dp/3119111 This transceiver is looking promising. It has 5V tolerant inputs too!
7 June 2020
In thinking about the potential issues with the bus it was decided that and WKE/RX combination offered benefits over a WKE/TX combination. A WKE/RX combination solves the issues of having a very long cable attached to TX permanently which may cause instability or excess current draw if the TX pin needs to drive the large load of this wire. Additionally, if the cable is too long for an upload to work successfully a more powerful driver on the programmer side can be used. This will help extend the range somewhat. Since the cable is connected to RX on the programmer side, when not uploading it can be disconnected and rewired to the WKE line. This prevents the RX signals from being sent across it when not uploading*. * the RS-485 driver will still be electrically connected to the WKE line during normal operation, so a small buffer gate or diode will be needed to stop this. It remains to be tested which is the better solution.
The RS-485 Driver will also need to automatically be put in the transmit state when the upload process begins. This should be achievable through pull up resistors.
With the changes as described the new operating modes of the bus are:
An implementation of the BoSL Bus for a ATmega with complete functionality would look like this:
The SN65HVD75 is the RS-485 transceiver. Resistors R1 and R2 ensure that RE and DE are driven correctly during uploading (send data over RS-485), as when programming pins are in a floating state. When sleeping this does mean that DE will need to be pulled down, however this would draw ~8μA, which is negligible. Introducing more circuitry to reduce this would add unnecessary cost and space requirements. A potential future solution is to update the boot loader however this is not an immediate solution.
RE is also used to drive the 74LVC1G126 which is a buffer able to isolate WKE/RX. This helps during active mode as it prevents the RS-485 controller from driving unnecessary load, and makes the bus immune to the impedance state of the WKE pin. Thus, when in a Low-Z state the line is open to signals from WKE/RX, and when in a High-Z state the Arduino is free to receive data from the SN65HVD75.
Mode | DE | RE | SN65HVD75 | 74LVC1G126 |
---|---|---|---|---|
Sleep | L | H | Off | Low-Z |
Program | H | H | Send | Low-Z |
Active | H\L | H\L | Send\Receive | High-Z |
The diode on RST\5V allows the line to be used as a 5V supply while not having current leak through the reset pin due to the reserved biasing of the diode. When the line is drawn low the diode becomes forward bias and conducting, hence also drawing the line low and pulsing the reset pin. The BAT54W diode was chosen as it has a low forward voltage drop ~300 mV, this is important as the ATmega328p is only guaranteed to reset if the reset voltage goes below 0.1*Vcc, or when powered from a 3V3 supply, 330 mV.
This standard should be modifiable to work with a 5V ATmega328p. It may require switching of the voltages 3V3 and RST/5V, however the deviation should be minimal.
There is also a sketch for a design of a USART to BoSL-Bus converter in the gallery. It does not generate its own 5V supply, however it will be able to connect to a BoSL board and facilitate the communication with BoSL Bus enabled sensors.
9 July 2020
A PCB was drawn up for the BoSL Bus to USART converter. Testing needs to be done on the system however it is likely that changes will be small.
The converter is small in size ~ 40 mm by 20 mm. It connects via either header pins or header sockets to the BoSL board and via modular connector or header sockets to the BoSL Bus sensor. The changes between programming and active mode are done by connecting different pins to different ports on the BoSL board side.
21th July 2020
To get familiar with RS-485, these: https://www.altronics.com.au/p/z6364-ttl-to-rs485-breakout-module, modals were used in a simple setup. With one set to read mode (DE, RE LOW) and the other to send mode (DE, RE HIGH) data could be sent from the TX port of one arduino uno to the TX port of a USB-TTL converter. This worked quite well. The modals operated both on 5V and 3V3. The length over which data could be sent was not tested in this trial.
The same setup also worked for sending data from a BoSL board.
When a ground wire and RX were connected from the USB-TTL converter then code could be uploaded to the BoSL Board using the same method as one normally would.
It was found that the converter PCB had inbuilt pull-up resistors. Once these were removed DE and RE needed to be tied up to allow the uploading to take place. Fortunately, 1 ΜΩ resistors were sufficient to achieve this. This reduces the sleep current consumption to by 7 μA as 330 kΩ pull-up resistors were thought to be needed.
On the BoSL board the reset system does not work as intended, however it was discovered that this was an issue more with the bosl board. It was seen that when the reset button was pressed the 3V3 line dipped down to 2.7V. This is not supposed to happen and should be investigated and fixed in a future version of the BoSL board.
22nd July 2020
A schematic of the depth sensor was drawn up with the BoSL Bus incorporated. Micheal will be laying out the schematic into a PCB so some prototypes can be manufactured.