1

I'm using two different accelerometers with my Pi and both use I2C, so I decided to have the same python code for both. It is not very complex, I just want do periodically read all registers and dump that into a file.

Each device has a different number of registers, of course. I thought that requesting an i2c block read with more registers than existing ones would just give me the available ones, but instead it reboots my Pi. (kernel panic?)

Is that a bug? Is reading more blocks than actual registers undefined behavior, unspecified by the standard or something else? Legal or not, is there a workaround?

1

The behaviour of an I2C device is documented in its datasheet.

You can not assume that two different devices support the same interface in terms of the I2C and/or SMBus commands supported, number or range of registers, endianess, byte size, or any other feature.

I'm surprised using the interface incorrectly can cause a kernel crash though unless you are using an unsupported SMBus command.

To view unsupported commands use the i2cdetect -F option.

$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

Presumably you are using the unsupported SMBus Block Read command. Perhaps use the I2C Block Read command instead.

  • Indeed this command reported SMBus block read as not supported, but it did not give me problems unless I tried more registers than the device had. I'm using the python-smbus package. Anyway, the crash is not really the problem, but finding how much registers I should be receiving. Is there any way to scan the device for valid register addresses? – villasv Jun 22 '16 at 18:39
  • I'm using python-smbus but calling read_i2c_block_data btw – villasv Jun 22 '16 at 18:49
  • @VillasV You'll need to look at the datasheets to see if there is a safe way of telling one device from another, and then (if possible) tailor your calls according to the identified device. – joan Jun 22 '16 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.