【问题标题】:ESP8266 I2C slave does not acknowledge dataESP8266 I2C 从机不确认数据
【发布时间】:2019-07-26 13:18:44
【问题描述】:

我有一个 TM4C123 处理器作为 I2C 主机和一个 ESP8266 作为从机。对于 ESP,我使用的是 2.5.2 版安装了 ESP8266 支持的 Arduino IDE,它应该支持 I2C 从机模式。但是,我无法让它工作。即使使用 Arduino slave_receiver 示例,从设备也不会确认 (ACK) 我在示波器上显示的主设备的请求。

为了确保我至少使用了一次正确的地址,我在主服务器上实施了地址扫描。为了确保我在 ESP 上使用了正确的引脚,我首先在 ESP 上实现了主模式,并使用 I2C 从设备进行了引脚扫描。所以我相当肯定这两者都不是问题。

我使用的是 Olimex Mod-wifi 板,带有 SDA Pin 12 和 SCL Pin 13 (Schematic here)

有人可以帮我解决这个问题吗?这是我的代码:

// 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 12
#define SCL_PIN 13

const int16_t I2C_SLAVE = 0x12;

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() {
  delay(1000);
  Serial.println("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 从模式。您可能想看看那里是否有任何变化。
  • @stevieb 根据github.com/esp8266/Arduino/issues/3046 从 2.5.0 开始添加从属支持..

标签: c++ arduino i2c


【解决方案1】:

我对 ESP8266 有一个可比较的问题。通过 I²C 在 Arduino Nano(从)到 ESP8266(主)之间发送数据没有问题。但是当我切换模式(Arduino Nano = Master 和 ESP8266 = Slave)时,Wire 示例不起作用。

我针对此问题的解决方法是将 I²C 工作频率从 100kHz 降低到大约 20kHz。

【讨论】:

  • 如何从slave向master发送数据??
  • 确切看到,slave不可能向master发送数据。只有当主机轮询从机的数据时才有可能。但是当您查看“Wire”部分中的 Arduino 示例时,您可以找到示例“slave_sender”。我的帖子引用了 Arduino 示例的名称,具有误导性。
  • Esp 可以向从站请求数据。从站如何向主站发送数据。
猜你喜欢
  • 2010-10-30
  • 1970-01-01
  • 2018-06-01
  • 2017-07-16
  • 2021-03-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多