Skip to content

i2c Wire库slave模式异常 #34

@xizeyoupan

Description

@xizeyoupan

描述一下这个bug / Describe the bug

两份代码,一份主机,一份从机。由于手头只有一块air001开发板,故另一板子使用esp32开发板代替。
esp32 sad:21 scl:22
air001 sda:pf0 scl:pf1 均为默认。
sad 和 scl 分别通过3k上拉到3V3。

复现步骤 / To Reproduce

主机代码:

#include <Arduino.h>
#include <Wire.h>

void setup() {
    Serial.begin(115200);

    Wire.setClock(100000);
    Wire.begin();
}

void loop() {

    for (uint8_t i = 0; i < 128; i++) {
        Wire.beginTransmission(8);
        Wire.write(i);
        int code = Wire.endTransmission();
        Serial.println(i);
        Serial.println(code);
        delay(5);
    }
}

从机代码:

#include <Arduino.h>
#include <Wire.h>

#define ADDRESS (0x08)

void receiveEvent(int numBytes) {
    uint8_t cmd;
    while (Wire.available()) {
        cmd = Wire.read();
        Serial.println(cmd);
    }
}

void setup() {
    Serial.begin(115200);

    Wire.setClock(100000);
    Wire.begin(ADDRESS);
    Wire.onReceive(receiveEvent);
}

void loop() {
    delay(1);
}

如果正常,应该是什么样 / Expected behavior

在使用air001为主机,esp32为从机时,输出正常:
1
2

但是使用air001为从机,esp32为主机时,输出每隔一个请求就会丢失:
3
4

上图截图时时间没对好,意思就是主机的endTransmission返回值为2从机air就收不到。

多次尝试依旧如此。

截图 / Screenshots

上方已给出。

日志 / Logs

没有

系统 / System

Win11

PACK包版本 / Version

0.4.0, Arduino IDE 2.1.0

验证

  • 检查该问题是否已被提过 / Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • 提供了最小可复现工程或详细的复现步骤,确保开发者可以复现 / The provided reproduction is a minimal reproducible example of the bug.
  • 已经提供了完整的报错信息、日志、截图,没有经过删减。

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions