Skip to content

AIR001的I2C作从机,接收主机用Wire.write发送过来的数据异常 #67

@luckycheng2017

Description

@luckycheng2017

描述一下这个bug / Describe the bug

两块板子,一块是ESP32C3,另一块是AIR001,用I2C连接,有接上拉电阻。ESP32C3作主机,AIR001作从机。ESP32C3主机用Wire.write方法发送操作多个字节的数据时,反馈结果是2,AIR001从机那边没有收到数据。之前 #34 这个bug有提过,但是没彻底解决。

复现步骤 / To Reproduce

从机先复位,然后主机复位,主机能找到从机的地址,从机没有收到主机发送过来的数据。

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

正常AIR001从机能够读取到ESP32主机发过来的数据。

截图 / Screenshots

ESP32C3主机代码:
`
#include <Wire.h>

#define I2C_slave_ADDR 0x08

uint8_t hello[] = {1, 2, 3, 4, 5, 6};
uint8_t aTxBuffer[] = "你好";
uint8_t myBuffer[10];

void setup() {
Wire.setClock(100000);
Wire.begin(4, 5);

Serial.begin(9600);

byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ ) {
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) {
Serial.print("I2C device found at address 0x");
if (address<16) {
Serial.print("0");
}
Serial.println(address,HEX);
nDevices++;
}
else if (error==4) {
Serial.print("Unknow error at address 0x");
if (address<16) {
Serial.print("0");
}
Serial.println(address,HEX);
}
}
if (nDevices == 0) {
Serial.println("No I2C devices found\n");
}
else {
Serial.println("done\n");
}
}

void loop() {
Wire.beginTransmission(I2C_slave_ADDR);
Wire.write((uint8_t *) hello, sizeof(hello));
Serial.print("发送:");
Serial.println(Wire.endTransmission());
delay(2000);
}

`

AIR001从机代码
`
#include <Wire.h>

#define I2C_ADDR 0x08

uint8_t hello[] = {1, 2, 3};
uint8_t aTxBuffer[] = "你好";

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
while(1 < Wire.available()) // loop through all but the last
{
int c = Wire.read(); // receive byte as a character
Serial.println(c); // print the character
}
int x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
}

// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent()
{
int res = Wire.write((uint8_t *) hello, sizeof(hello));
Serial.print("发送数据, res = ");
Serial.println(res);
}

void setup()
{
Serial.begin(9600); // start serial for output

Wire.setSDA(PF_0);
Wire.setSCL(PF_1);
Wire.setClock(100000);
Wire.begin((int) I2C_ADDR, false, true); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Wire.onRequest(requestEvent); // register event
}

void loop()
{
//empty loop
}
`

日志 / Logs

主机日志:
990ff76fdbc68116e70e62105a953fa

从机日志:
e955f0e6a6af9b15ba693432f75f7dc

系统 / System

Win10

PACK包版本 / Version

0.4.5

验证

  • 检查过该问题,之前没有人提过 / 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions