I2C_Speed
Pat Beirne edited this page 2 years ago

3. I2C Speed

optional

  • NOTE: the i2c2 pins on the microprocessor are controlled by the Linux i2c-1 device (i96 pins 15/17); the i2c3 pins on the microprocessor are controlled by the i2c-2 device (i96 pins 19/21)

The data rates on the two I2C busses seems to be a bit off. Using the current shipping build, the i2c-1 bus runs at 266kb/s, and the i2c-2 bus runs at 160k

b/s. Neither of these are frequencies called out in the I2C standard, although they will work properly with '400kB/s' I2C devices.

There may be cases where you want better control over the bus speeds, and the current Linux I2C driver does not implement hooks to allow a speed change. Use the devmem2 progam to write these words.

Bus (linux name) Pins (40 pin connector) Register Write
i2c-1 15 (scl), 17 (sda) 0x2096.0000 0xnnn.0000 then 0xnnn.0001
i2c-2 19 (scl), 21 (sda) 0x2097.0000 0xnnn.0000 then 0xnnn.0001

where 'nnn' = one of these:

  • 0x063 = 266kb/s the original setting on the i2c-1 bus
  • 0x0c6 = 166kb/s the original setting on the i2c-2 bus
  • 0x160 = 100kb/s
  • 0x050 = 400kb/s The datasheet from RDA indicates a formula (reg = f_clk / (5 * f_bus) -1) but this doesn't seem to match measured data rates.

The i2cdetect program does not seem to work well on this microprocessor. If you write your own i2c scanner, it will work ok. Try this:

#!/usr/bin/env python3

import smbus
bus = smbus.SMBus(1) # 1 indicates /dev/i2c-1

for device in range(128):
      try:
         bus.read_byte(device)
         print(hex(device))
      except: # exception if read_byte fails
         pass

The 2G-IOT board operates the same way.