-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AIR001的I2C作从机,接收主机用Wire.write发送过来的数据异常 #67
Comments
补充说明:差不多同一份代码,修改一下引脚,两个ESP32C3的板子之间I2C通信是正常的。 #define I2C_slave_ADDR 0x08 uint8_t hello[] = {1, 2, 3, 4, 5, 6}; void setup() { Serial.begin(9600); byte error, address; void loop() { ` ESP32C3从机代码: #define I2C_slave_ADDR 0x08 uint8_t hello[] = {1, 2, 3, 4, 5, 6}; void receiveEvent(int len) { void requestEvent() { void setup() { Serial.begin(9600); } void loop() { ` |
补充说明,ESP32C3主机用Wire.write发送单个字节的数据,AIR001才能收到,但是发送下个字节前,要操作 ESP32C3主机代码: #define I2C_slave_ADDR 0x08 uint8_t hello[] = {1, 2, 3, 4, 5, 6}; void setup() { Serial.begin(9600); byte error, address; int i = 0; void loop() { AIR001从机代码: #define I2C_ADDR 0x08 uint8_t hello[] = {1, 2, 3}; // function that executes whenever data is received from master // function that executes whenever data is requested by master void setup() Wire.setSDA(PF_0); void loop() |
AIR001作I2C从机时,比较不稳定,容易返回2,望解决这个问题。 |
用逻辑分析仪看数据, |
在主机端,暂时用这个方式来解决: 速度400k(从机不需要指定速度)
/ 处理后: |
TWI.C中的 HAL_I2C_ListenCpltCallback 回调函数不能有效触发, 也可在HAL_I2C_SlaveRxCpltCallback 函数中 |
描述一下这个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
主机日志:
从机日志:
系统 / System
Win10
PACK包版本 / Version
0.4.5
验证
The text was updated successfully, but these errors were encountered: