【问题标题】:WeMos D1 Mini (ESP8266) I2C Slave Mode does not receive any incoming dataWeMos D1 Mini (ESP8266) I2C 从模式不接收任何传入数据
【发布时间】:2021-03-13 09:11:17
【问题描述】:

我花了几个小时试图弄清楚如何让“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
}

【问题讨论】:

标签: arduino esp8266 i2c arduino-esp8266


【解决方案1】:

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

有关此问题的讨论,请参阅 herehere

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多