-
Notifications
You must be signed in to change notification settings - Fork 14
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
I2c作为从机,被主机用requestFrom读取时异常 #62
Comments
此问题似乎是HAL库的中断逻辑问题,待进一步排查 |
遇到相同问题,air001 做为从机时,确实I2C通讯不正常。同样的程序换块主板通讯就正常了,望解决.... |
这个BUG啥时候能解决,看ISSUES有人测试成功了啊,但是我AIR001做从机的时候就没正常过。 |
请问官方停止维护air-duino了么,这个bug貌似一直没解决。 |
虽然我没有正确的解决问题,但是我发现,真的可以读了呢! |
原生SDK的IIC例程我就没跑起来。。。 |
描述一下这个bug / Describe the bug
手里有一个ESP32和AIR001的板子,ESP32作主机,AIR001作为从机。ESP32用requestFrom方法,不能正常触发从机AIR001的onRequest注册的方法。但是两个ESP32分别作主机和从机,主机能够正常读取从机的数据。
复现步骤 / To Reproduce
从机先复位,然后主机复位,主机能找到从机的地址,但是不能读到从机的数据。
如果正常,应该是什么样 / Expected behavior
正常ESP32主机能够读取到AIR001从机发过来的数据。
截图 / Screenshots
ESP32主机的代码
`
#include <Wire.h>
byte i = 0;
uint8_t hello[] = "hello";
uint8_t aTxBuffer[] = "你好";
void setup() {
Wire.setClock(100000);
Wire.begin(4, 5);
Serial.begin(9600);
Serial.println("\nI2C Scanner");
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ ) {
Wire.beginTransmission(address);
// Wire.write(aTxBuffer, sizeof(aTxBuffer));
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() {
byte error;
byte address = 0x33;
int len = Wire.requestFrom((uint16_t) address, (uint8_t) 6);
if (len > 0) {
Serial.printf("接收长度:%d\n", len);
while (Wire.available() > 1) {
char c = Wire.read();
Serial.print(c);
}
char x = Wire.read();
Serial.println(x);
}
Serial.println("");
delay(2000);
}
`
AIR001从机代码
`#include <Wire.h>
#define I2C_ADDR 0x33
uint8_t hello[] = "hello";
uint8_t aTxBuffer[] = "你好";
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void myReceive(int howMany)
{
while(1 < Wire.available()) // loop through all but the last
{
char 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 myRequest()
{
Serial.println("收到请求");
Wire.write(0x01); // respond with message of 6 bytes
// as expected by master
}
void setup()
{
Serial.begin(9600); // start serial for output
Wire.setSDA(PF_0);
Wire.setSCL(PF_1);
Wire.setClock(100000);
Wire.begin(I2C_ADDR); // join i2c bus with address #4
Wire.onRequest(myRequest); // register event
Wire.onReceive(myReceive); // register event
}
void loop()
{
//empty loop
}
`
日志 / Logs
这是主机的日志
系统 / System
Win10
PACK包版本 / Version
0.4.5
验证
The text was updated successfully, but these errors were encountered: