Close

The virtues of software I2C on the Raspberry Pi

A project log for PCA9548A I2C mux device overlay for Pi gpio-I2C

Add 8 I2C buses for GPIO software I2C on Raspberry Pi with device tree overlay so programs like i2cdetect work like the hardware I2C.

carboncycleCarbonCycle 10/09/2018 at 22:410 Comments

Tested most recently with Raspbian Stretch. This is most useful for devices that are SMbus compliant ( <=100khz clock ) or have fixed addresses that prevent using more than one on the same bus. This is also a good work-around on the Raspberry Pi for the clock-stretching bug that some devices (AM2315 for instance) misbehave with the clock artifacts from the hardware ARM I2c bus. Control the clock speed by modifying the delay ( i2c_gpio_delay_us ). 

This software bus provides some additional SMbus support.


Details on SMbus functions

### I2C-ARM
        pi@raspberry:~ $ sudo i2cdetect -F 1
        Functionalities implemented by /dev/i2c-1:
        I2C                                                yes
        SMBus Quick Command              yes
        SMBus Send Byte                         yes
        SMBus Receive Byte                    yes
        SMBus Write Byte                         yes
        SMBus Read Byte                         yes
        SMBus Write Word                        yes
        SMBus Read Word                        yes
        SMBus Process Call                      yes
        SMBus Block Write                        yes
        SMBus Block Read                        no
        SMBus Block Process Call            no
        SMBus PEC                                    yes
        I2C Block Write                              yes
        I2C Block Read                              yes

### Software-I2C

         pi@raspberry:~ $ sudo i2cdetect -F 3
         Functionalities implemented by /dev/i2c-3:
         I2C                                                 yes
         SMBus Quick Command              yes
         SMBus Send Byte                         yes
         SMBus Receive Byte                    yes
         SMBus Write Byte                         yes
         SMBus Read Byte                         yes
         SMBus Write Word                        yes
         SMBus Read Word                        yes
         SMBus Process Call                      yes
         SMBus Block Write                        yes
         SMBus Block Read                        yes
         SMBus Block Process Call            yes
         SMBus PEC                                    yes
         I2C Block Write                              yes
         I2C Block Read                              yes

       Many sensor devices are not capable of using a I2C clock over 100khz or have trouble with certain limitations of the hardware implementation of I2C in the Raspberry Pi. 


       When the data sheet has SMBus or I2c_ModBus  mentioned, the device is probably going to need SW I2C.  It is sort of an indication of the age of the design.  Also mention of a maximum 100khz clock. New compliant designs clock at 400khz or better.

This app note discusses how SMBus != I2C

Discussions