Cluster Management Bus (i2c)
Turing Pi cluster management bus configuration, security and internal devices

Configure I2C and devices

First аdd dtoverlay
1
sudo nano /boot/config.txt
Copied!
and add the following lines
1
dtoverlay=i2c1,pins_44_45
2
dtoverlay=i2c-rtc,mcp7940x
Copied!
Enable I2C interface in sudo raspi-config -> Interfacing Options -> I2C -> enable and reboot
Check everything is fine with I2C and RTC
1
dmesg | grep i2c
2
[ 4.414436] i2c /dev entries driver # ok
3
4
ls /dev/*i2c*
5
/dev/i2c-1 # ok
6
7
dmesg | grep rtc
8
[ 6.489206] rtc-ds1307 1-006f: registered as rtc0
9
10
ls /dev/*rtc*
11
/dev/rtc /dev/rtc0
Copied!

I2C tools

Install i2c-tools
1
sudo apt-get install i2c-tools
Copied!
If the command doesn't work update your pi
1
sudo apt-get update
Copied!
Now check our I2C devices on the CMB
1
sudo i2cdetect -y 1
2
0 1 2 3 4 5 6 7 8 9 a b c d e f
3
00: -- -- -- -- -- -- -- -- -- -- -- -- --
4
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
5
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
6
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
7
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
8
50: -- -- -- -- -- -- -- 57 -- -- -- -- 5c -- -- --
9
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 6f
10
70: -- -- -- -- -- -- -- --
Copied!
You can see three I2C devices Ethernet Switch (0x5Ch), I2C expander (0x57h) and RTCC (0x6Fh).
The i2cget command is used to read a byte from a specified register on the I2C device. The format for this command is as follows
1
i2cget [-f] [-y] 1 [MODE]
Copied!
[-f] [-y] Options:
  • -f force access to the device even if the device is still busy. However, be careful. This can cause the i2cget command to return an invalid value. We recommend avoiding this option.
  • -y disable interactive mode. Using this command will skip the prompt for confirmation from the i2cget command. By default, it will wait for the confirmation from the user before interacting with the I2C device.
  • DEVICE_ADDRESS is an I2C bus address (e.g 0x04h)
  • ADDRESS is the address on the slave from which to read data (eg. 0x00h)
The optional MODE can be one of the following:
  • b – read/write a byte of data, this is the default if left blank
  • w – read/write a word of data (two bytes)
  • c – write byte/read byte transaction
Example of reading from register 0xF2h where factory default value is 0xFFh
1
sudo i2cget -y 1 0x57 0xf2
2
0xff
Copied!
Use the i2cset command to write data to an I2C device. The format of this command as follows
1
i2cset [-m mask] [-f] [-y] 1 [MODE]
Copied!
Options:
  • -f, -y, DEVICE_ADDRESS, ADDRESS as for i2cget
  • -m mask the bit mask parameter, if specified, describes which bits of value will be actually written to data-address. Bits set to 1 in the mask are taken from VALUE, while bits set to 0 will be read from ADDRESS and thus preserved by the operation
Example of writing value 0x77h to the first byte of user space SRAM (starts from 0x00h) and then reading
1
sudo i2cset -y 1 0x57 0x00 0x77
2
sudo i2cget -y 1 0x57 0x00
3
0x77
Copied!

Security

As a security precaution, system devices are not exposed by default inside Docker containers. You can expose specific devices to your container using the --device option to docker run, as in
1
docker run --device /dev/i2c-1 app-image
Copied!
or remove all restrictions with the --privileged flag
1
docker run --privileged app-image
Copied!

User space EEPROM

I2C expander and RTCC each have 64 bytes of general purpose user memory, so combined you have 128 bytes of EEPROM. On device 0x57h user space address from 0x00h to 0x3Fh and on 0x6Fh from 0x20h to 0x5Fh.

Ethernet Switch

The onboard RTL8370 integrate all the functions of a high-speed switch system; including SRAM for packet buffering, non-blocking switch fabric, and internal register management into a single CMOS device.
Device Address: 0x5Ch

I2C expander

I2C expander offers users a digitally programmable alternative to hardware jumpers and mechanical switches that are being used to control power on compute nodes.
Device Address: 0x57h
Register
Register Description
Default Value
0x00h to 3Fh
64 bytes of general-purpose user EEPROM
0x00h
0xF2h
Control Register
0xFFh
0xF8h
Status Register
0xFAh to 0xFFh
6 bytes of general-purpose user SRAM

Power Management

On/off compute module through register 0xF2h
1
# Bits : 76543210
2
# Slots : 5674321x
3
4
# Power off worker nodes 2,3,4,5,6,7
5
sudo i2cset -m 0xfc -y 1 0x57 0xf2 0x00
6
7
# Power on worker nodes
8
sudo i2cset -m 0xfc -y 1 0x57 0xf2 0xff
Copied!
On/off compute module by node number
1
2
# 0x02 : Node #1 (Master)
3
# 0x04 : Node #2 (Worker 1)
4
# 0x08 : Node #3 (Worker 2)
5
# 0x10 : Node #4 (Worker 3)
6
# 0x80 : Node #5 (Worker 4)
7
# 0x40 : Node #6 (Worker 5)
8
# 0x20 : Node #7 (Worker 6)
9
10
# Power off node #3
11
sudo i2cset -m 0x08 -y 1 0x57 0xf2 0x00
12
13
# Power on node #7
14
sudo i2cset -m 0x20 -y 1 0x57 0xf2 0xff
Copied!
Read on/off status
1
sudo i2cget -y 1 0x57 0xf2
2
0xff
Copied!

Compute Module status

Read compute module status through register 0xF8h
  • 1 = Installed in slot AND switched on
  • 0 = Not installed in slot OR switched off
1
# Bits : 76543210
2
# Slots : 5674321x
3
4
sudo i2cget -y 1 0x57 0xf8
5
0x0e # register 0xf2 = 0xff, all slots are power up but installed only three
Copied!

Real-Time Clock/Calendar

Real-Time Clock/Calendar (RTCC) tracks time using internal counters for hours, minutes, seconds, days, months, years, and day of week. Alarms can be configured on all counters up to and including months.
SRAM and timekeeping circuitry are powered from the back-up supply when main power is lost, allowing the device to maintain accurate time and the SRAM contents. The times when the device switches over to the back-up supply and when primary power returns are both logged by the power-fail time-stamp.
Device Address: 0x6Fh
Register
Register Description
Default Value
0x00h to 0x06h
Time & Date
0x07h to 0x09h
Configuration and Trimming
0x0Ah to 0x10h
Alarm 0
0x11h to 0x17h
Alarm 1
0x18h to 0x1Fh
Power-Fail/Power-Up Time-Stamps
0x20h to 0x5Fh
64 bytes of general-purpose user SRAM

Time & Date

Show time from hardware RTC
1
sudo hwclock --show
2
2019-10-26 20:21:03.005326+01:00
Copied!

External I2C port

Pinouts
1
| 1 | 2 | 3 | 4 |
2
| GND | VCC | SCL | SDA |
Copied!

Reference Links

Last modified 10mo ago