RPI上的SMBUS给出IOError:[Errno 121]远程I/O错误 [英] SMBUS on the RPI gives IOError: [Errno 121] Remote I/O error
问题描述
我尝试通过I2C在RPi3和stm32之间进行通信.首先,我已经安装了i2c-tools和python-smbus.总而言之,我在RPI上使用了python脚本,如下所示:
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被配置为I2C从设备,两个设备均正确连接(SDA,SCL和GND).我怎么知道我已经使用BCM2835库制作了程序. C程序正常工作. C程序发送的缓冲区没有任何错误. STM32也收到了缓冲区,没有任何错误.你能告诉我,我做错了什么吗?
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?
谢谢.
推荐答案
我遇到了同样的问题.我发现,当所有从机都未确认主机发送的命令时,便会指出错误代码121.如果您尝试联系一个未使用的地址,或者该命令不是从站期望的,则会发生这种情况.
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.
就我而言,我尝试将重置命令发送到TLC59116.这些IC希望在地址0x6B上输入命令"0xA5 0x5A".
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)
但是在原始通信中,该命令会导致Msg [0x00 0xA5 0x5A],带有开头的起始寄存器地址,这些IC不允许这些消息,并使用NACK->错误121对其进行正确回答.
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 .: 我通过发送来解决了我的问题
O.T.: I solved my problem by sending
bus.write_byte_data(address,0xA5,0x5A)
这篇关于RPI上的SMBUS给出IOError:[Errno 121]远程I/O错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!