簡體   English   中英

WeMos D1 Mini (ESP8266) I2C 從模式不接收任何傳入數據

[英]WeMos D1 Mini (ESP8266) I2C Slave Mode does not receive any incoming data

我花了幾個小時試圖弄清楚如何讓“WeMos D1 Mini”處於從屬模式。 由於某種原因,它不確認任何傳入數據。 從我閱讀的所有論壇中,每個人都需要制作自己的“基於特殊中斷的 I2C”代碼,以使 esp8266 進入從模式,因為它不受官方支持。

所以我有一個 Arduino Nano,它是主機,它將向 WeMos D1 Mini 發送數據,但該示例無法正常工作。

這是我使用“ESP8266 core 2.7.4”從“Arduino IDE 1.8.13”使用的代碼,它是名為“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 在 I 2 C 上不能作為從機工作; 這是一個已知問題,據我所知,從未解決過,除了可能從頭開始編程之外,我不知道任何解決方法。

有關此問題的討論,請參見此處此處

您可以嘗試使用其他交換數據的方式; 2 C 並不是全部。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM