SMBUS on the RPI gives IOError: [Errno 121] Remote I/O error

与世无争的帅哥 提交于 2019-12-08 00:31:27

问题


I have tried communication between RPi3 and stm32 over I2C. First of all I have installed i2c-tools and python-smbus. All in All I have used python script on the RPI as below:

import smbus
bus = smbus.SMBus(1)
address = 0x0A
data = [1,2,3,4,5,6,7,8]
bus.write_i2c_block_data(address, 0, data)

When I run script, I can see following error:

IOError: [Errno 121] Remote I/O error

STM32 is configured as I2C slave, both device are connected correctly(SDA, SCL and GND). How do I know that? I have made program using BCM2835 library. C program worked correctly. C program sent buffer without any errors. STM32 also received buffer without any errors. Can you tell me, what I have been doing wrong?

Thank you in advance.


回答1:


I ran into the same problem. I figured out that error code 121 is stated when none of the slaves ACKs the command send by the Master. This happens if you are trying to contact a not used address or the command is not what the slaves expect.

In my case I tried to send a reset command to a TLC59116. These ICs expect the command "0xA5 0x5A" on address 0x6B.

So I tried to send with a similar snippet like yours:

import smbus
bus = smbus.SMBus(0)
address = 0x6B
data = [0xA5,0x5A]
bus.write_i2c_block_data(address, 0, data)

But in raw communication this command leads to a Msg [0x00 0xA5 0x5A], with leading start registeraddress, which these ICs did not allow and answer correct with NACK -> Error 121.

O.T.: I solved my problem with sending

bus.write_data(address,0xA5,0x5A)


来源:https://stackoverflow.com/questions/45324851/smbus-on-the-rpi-gives-ioerror-errno-121-remote-i-o-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!