arduino - WeMos D1 Mini (ESP8266) I2C 从模式不接收任何传入数据

标签 arduino esp8266 i2c arduino-esp8266

我花了几个小时试图弄清楚如何让“WeMos D1 Mini”处于从属模式。

由于某种原因,它不确认任何传入数据。从我读到的所有论坛来看,每个人都需要编写自己的“基于特殊中断的I2C”代码,以使ESP8266进入从机模式,因为它不受官方支持。

所以我有一个 Arduino Nano,它是主设备,它将向 WeMos D1 Mini 发送数据,但该示例根本不起作用。

这是我使用“Arduino IDE 1.8.13”使用“ESP8266 core 2.7.4”的代码,它是名为“slave_receiver”的示例代码:

// Wire Slave Receiver
// by devyte
// based on the example by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this

// This example code is in the public domain.


#include <Wire.h>

#define SDA_PIN 4
#define SCL_PIN 5

const int16_t I2C_MASTER = 0x42;
const int16_t I2C_SLAVE = 0x08;

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

  Wire.begin(SDA_PIN, SCL_PIN, I2C_SLAVE); // new syntax: join i2c bus (address required for slave)
  Wire.onReceive(receiveEvent); // register event
}

void loop() {
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(size_t howMany) {

  (void) howMany;
  while (1 < Wire.available()) { // loop through all but the last
    char c = Wire.read(); // receive byte as a character
    Serial.print(c);         // print the character
  }
  int x = Wire.read();    // receive byte as an integer
  Serial.println(x);         // print the integer
}

最佳答案

ESP8266 不能作为 I2C 上的从设备工作;据我所知,这是一个已知问题,从未得到解决,除了从头开始编程之外,我不知道有任何解决方法。

参见herehere对此进行讨论。

您可以尝试使用其他方式交换数据; I2C 并不是全部。

关于arduino - WeMos D1 Mini (ESP8266) I2C 从模式不接收任何传入数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65090641/

相关文章:

python - 使用 Python 作为界面时的奇怪控件

linux - 无法在 I2C 设备上使用 write() 或 read() 调用,但 echo 和 i2c-tools 可以工作

linux - 将 32 位寄存器地址传递给 I2C_RDWR

arduino - 如何向 I2C 主机发送多个 32 字节字符串?

C++ 难以在单例类中创建类的实例

arduino - 连接 ROS 和 arduino

c - 声音字符串声明挂起 Arduino 编译器

c - 使用 CLion 开发 Arduino 库

mysql - ESP8266 和 mySQL

c++ - ESP8266WebServer 在类中设置一个值