Thursday 8 June 2017

Extending RPI I2C Bus with a buffer / redriver

Summary
This blog illustrates how the I2C bus of the Raspberry PI (RPI) can be connected to an external sensor such as the Adafruit SI1145 Digital UV Index, IR, visible light sensor using a buffer/redriver. 


Raspberry PI 2 Model B
Raspberry PI 2 Model B (RPI)
Essential Reading
For the tests performed with the I2C interface on the RPI the NXP I2C specification is a solid read for those interested in the nuts and bolts of I2C operation.

At the hardware level the I2C.org site explains the gritty detail of the bus. What was helpful on the website, in addition to the specification, are the images showing various states of the bus and the associated operational issues.

Hardware - RPI
The GPIO header (J8) was utilisedI2C connections on the RPI.

The image below shows the data (SDA) and clock (SCL), Image courtesy Pinouts.xyz


RPI Pinouts for I2C
RPI Pinouts for I2C
Hardware - SI1145
To test the I2C connection, a Silicon Labs SI1145 light sensor was connected to the RPI GPIO connector. The schematic of the SI1145 board is shown below.


Adafruit SI1145 UV Sensor
Adafruit SI1145 UV Sensor

Hardware - Cable
For testing two types of cables were tried:
  1. Flat 4 core telephone cable with a quoted capacitance of 670pf/100m and
  2. CAT5e cable which is specified with a capacitance of 330pF/100m (not mutual pairs) to ground

Hardware - Buffer / Redriver
There have been similar designs, discussions in various blogs and on RaspberryPi.org relating to buffering I2C. While there is some truth to the point, as mentioned in one of the blogs, that I2C is meant for device to device communication on the same circuit board, the reliability of the signal and ultimately data, is a partially a combination of the hardware design and quality of equipment used. 

For a more robust implementation a traditional differential solution such as CAN (Controller Area Network) or even Ethernet would be considered for longer cable runs exceeding 5m.

In sourcing a manufacturer for the buffer the manufacturer NXP, whom have been developing I2C for some years, was chosen. NXP offer a PCA9600D buffer / redriver among many others. 

Specifications for the buffer were focused on the I2C bus speed and the current sink capability, which was 60mA for the PCA9600D. 

For driving long lengths of cable the buffers higher driver output current and associated lower pull up resistors were considered simultaneously.

Hardware Testing - Minimal Bus
To confirm operation of a short length I2C bus connected to the light sensor the Raspbian NOOBS Lite image was used for testing. All updates and upgrades were applied to this build. The Adafruit guide showing configuration of the I2C on the RPI was used. No other changes were made to the Raspbian build.

A pair of PCA9600D drivers were connected with 470R pullup resistors.

Raspberry PI 2 Model B to I2C Sensor (Buffered)
Raspberry PI 2 Model B to I2C Sensor (Buffered)

Using the terminal window the I2C bus was scanned using i2cdetect -y 1, to suite the model B RPI.

The light sensor was found at the correct address, 0x60. This address in detailed on page 17 of the Si1145-46-47 Silicon Labs datasheet.


Putty Capture of I2C Bus of RPI
Putty Capture of I2C Bus of RPI
To establish a baseline for the SCK and SCL signals, the oscilloscope was connected and captures taken.


Buffered SCL and SCL Lines
Buffered SCL (CH2) and SCL (CH1) Lines
The above capture was taken using 470R termination resistors on the I2C lines (SDA, SCL) using very short wires. Even increasing the pullup resistance to 10k only introduced minor rounding to the rising edges of the signals.

Hardware Testing - Telephone Cable
Before the setup was modified with 7.5m (25ft) of flat 4 core telephone cable between the two NXP drivers. Telephone cable capacitance was measured with an average capacitance between each of the unconnected pairs of 400pF.


RPI I2C with 4 Core Flat Telephone Cable
RPI I2C with 4 Core Flat Telephone Cable
Resistors were only fitted on the driver end directly connected the RPI. Three resistor value were tried, 10k, 470R and 220R.


SCL (CH2) and SDA (CH1) Lines on Telephone Cable 10k Pullups
SCL (CH2) and SDA (CH1) Lines on Telephone Cable 10k Pullups
The above capture shows that the bus, with 10k resistors, was driven with too little current for the high capacitance of the telephone cable.


SCL (CH2) and SDA (CH1) Lines on Telephone Cable 470R Pullups
SCL (CH2) and SDA (CH1) Lines on Telephone Cable 470R Pullups
The above capture shows a significant improvement in the clock and data lines after the 10k resistors were reduced to 470R. Each of the signals operate rail to rail. Visible in the capture was the crosstalk on SDA line (CH1) induced from SCK (CH2).

SCL (CH2) and SDA (CH1) Lines on Telephone Cable 220R Pullups
SCL (CH2) and SDA (CH1) Lines on Telephone Cable 220R Pullups
Driving the open collectors of the NXP driver with even more current, marginally higher than 10mA using 220R resistors, the above capture shows yet again an improved signals at the start of the transmission. Further along the transmission the crosstalk becomes emphasised so much so that requests from the sensor become corrupted.


Corrupted SCL (CH2) and SDA (CH1) Lines on Telephone Cable 220R Pullups
Corrupted SCL (CH2) and SDA (CH1) Lines on Telephone Cable 220R Pullups
To test for data corruption, sent or received, the SI1145 device register (Part_ID), which contains the model of sensor, was continuously read. The returned value should always be 0x45 for this Silicon Labs device. The frequency of corrupted data was greater than 90%.

SI1145 Part_ID Register
SI1145 Part_ID Register
For illustrative purposes the schematic below shows the connection for the telephone cable.
Schematic for Telephone Cable with Pullups
Schematic for Telephone Cable with Pullups

Hardware Testing - CAT5 cable
Again the average capacitance between each of the unconnected pairs was measured for the CAT5 cable. For 7.5m (25ft) of CAT5 cable the capacitance between different pairs was 300pF and between pairs 500pF.


RPI I2C with CAT5 Cable
RPI I2C with CAT5 Cable
Again resistors were only fitted on the driver directly connected the RPI, three resistor value were tried, 10k, 470R and 220R. For the test with the CAT5 cable the SDA line was paired with 0V and the SCL was paired with the 5V signal.

SCL (CH2) and SDA (CH1) Lines on CAT5 Cable 10k Pullups
SCL (CH2) and SDA (CH1) Lines on CAT5 Cable 10k Pullups
The above capture shows that the bus, with 10k resistors, is similar to the telephone cable.

SCL (CH2) and SDA (CH1) Lines on CAT5 Cable 220R Pullups
SCL (CH2) and SDA (CH1) Lines on CAT5 Cable 470R Pullups
As was shown with the telephone cable testing a significant improvement in the clock and data lines was seen after the 10k resistors were reduced to 470R. The resulting image above shows less crosstalk on SDA line (CH1) caused by crosstalk from SCK (CH2).

SCL (CH2) and SDA (CH1) Lines on CAT5 Cable 220R Pullups
SCL (CH2) and SDA (CH1) Lines on CAT5 Cable 220R Pullups
Testing with the 220R resistors produced much less crosstalk issues when compared to the telephone cable.


Corrupted SCL (CH2) and SDA (CH1) Lines on CAT5 Cable 220R Pullups
Corrupted SCL (CH2) and SDA (CH1) Lines on CAT5 Cable 220R Pullups
Again the SI1145 devices first register (Part_ID) was continuously read. The frequency of corrupted data was no greater than 10%. Having the SDA and SCL lines separately paired with the power 0V and 5V, significantly reduced the crosstalk.

For illustrative purposes the schematic below shows the connection for the CAT5 cable.
Schematic for CAT5 Cable with Pullups
Schematic for CAT5 Cable with Pullups
Summary
For extending the I2C bus of the Raspberry PI the use of unbalanced drivers such as the PCA9600D or a digital isolator ISO1540 should be more than suitable over short lengths of twisted pair cable. 

For transmitting I2C of distances over a few metres then balanced drivers with twisted pair cable would be highly recommended.

No comments:

Post a Comment