【发布时间】: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 开始添加从属支持..