Raspberry Pi:通过I2C通信的问题

2024-09-30 14:35:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图创建一个简单的项目与I2C接口。为此,我在Arduino中创建了一个始终发送单字节的草图:

#include <Wire.h>

void setup() {
  Wire.begin(8);
  Wire.onRequest(requestEvent);
}

void loop() {
  delay(100);
}

void requestEvent() {
  Wire.write(0x11);
}

在Raspberry Pi上有一个Python脚本:

^{pr2}$

这是它的输出:

17
17
17
17
17
17
17
[Errno 5] Input/output error
[Errno 5] Input/output error
[Errno 5] Input/output error
[Errno 5] Input/output error
[Errno 5] Input/output error
[Errno 5] Input/output error
[Errno 5] Input/output error
[Errno 5] Input/output error
[Errno 5] Input/output error
[Errno 5] Input/output error
17
17
17
17
17
[Errno 5] Input/output error
[Errno 5] Input/output error
17
17

我想弄明白为什么在某些随机时间点,I2C返回错误而不是返回数据?硬件没有变化,RPi上没有其他东西在运行,实际上没有什么变化,但是I2C停止工作。在

有什么想法吗?在


Tags: 项目inputoutputincludesetuperrori2carduino
1条回答
网友
1楼 · 发布于 2024-09-30 14:35:28

问题解决了吗?在

我也有同样的问题,当配置树莓作为一个主。我认为这是由于读写操作之间缺少同步。一、 我碰巧在写作时可以尝试阅读。不幸的是,如果你认为相反的话,覆盆子也会起作用。这是因为raspberry是一个多线程平台,只有一个总线可用(据我所知)。在

我解决了在raspberry和picaxe之间添加同步的问题,方法是在raspberry和picaxe上使用一个GPIO引脚。这样,只有当另一个系统发出ok信号时,才会进行读(写)操作。在

我希望这个延迟对这样的延迟也有帮助。在

相关问题 更多 >