繁体   English   中英

Raspberry Pi:通过I2C进行通信时出现问题

[英]Raspberry Pi: issue communicating via I2C

我正在尝试使用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脚本:

#!/usr/bin/env python3

import smbus
import time

bus = smbus.SMBus(1)

while True:
    try:
        data = bus.read_byte_data(0x8, 0)
        print(data)
    except Exception as e:
        print(e)
    time.sleep(1)

这是它的输出:

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停止工作。

有任何想法吗?

你解决了这个问题吗?

将Raspberry配置为主服务器时,我也遇到相同的问题。 我认为它们是由于缺少读写操作之间的同步所致。 也就是说,我碰巧在完成书写时可以尝试阅读。 不幸的是,如果您认为相反的话,覆盆子也会做一些事情。 这是因为raspberry是一个多线程平台,并且只有一个总线可用(据我所知)。

我通过使用树莓派上的GPIO引脚和picaxe上的GPIO引脚解决了在树莓派和picaxe之间添加同步的问题。 这样,只有在另一个系统发出确定的信号时,我才会读(写)。

我希望这种延迟在这种延迟下也能有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM