[英]ESP8266 I2C slave does not acknowledge data
I have a TM4C123 processor acting as a I2C master and a ESP8266 as a slave.我有一个 TM4C123 处理器充当 I2C 主设备和一个 ESP8266 作为从设备。 For the ESP I am using the Arduino IDE with ESP8266 support installed at version 2.5.2, which should support the I2C slave mode.
对于 ESP,我使用 Arduino IDE 和 ESP8266 支持安装在版本 2.5.2,它应该支持 I2C 从模式。 However, I can't get it to work.
但是,我无法让它工作。 Even with the Arduino slave_receiver example, the slave does not acknowledge (ACK) the master's requests which I am displaying on a scope.
即使使用 Arduino slave_receiver 示例,从设备也不会确认(ACK)我在示波器上显示的主设备的请求。
To make sure I am using the right address at least once, I implemented an address sweep on the master.为了确保我至少使用了一次正确的地址,我在主服务器上实施了地址扫描。 And to make sure I am using the right pins on the ESP I implemented the master mode on the ESP first and did a pin sweep with an I2C slave device.
为了确保我在 ESP 上使用了正确的引脚,我首先在 ESP 上实现了主模式,并使用 I2C 从设备进行了引脚扫描。 So I am fairly certain neither of this can be the problem.
所以我相当肯定这两个都不是问题。
I am using the Olimex Mod-wifi board, with SDA Pin 12 and SCL Pin 13 ( Schematic here )我正在使用 Olimex Mod-wifi 板,带有 SDA 引脚 12 和 SCL 引脚 13( 此处为示意图)
Can someone help me on this?有人可以帮我吗? Here is my code:
这是我的代码:
// 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
}
I had a compareable issue with the ESP8266.我对 ESP8266 有一个类似的问题。 It was no problem sending data between the Arduino Nano (Slave) to the ESP8266 (Master) via I²C.
通过 I²C 在 Arduino Nano(从设备)到 ESP8266(主设备)之间发送数据没有问题。 But when I switch the modes (Arduino Nano = Master and ESP8266 = Slave) the Wire example doesn't work.
但是当我切换模式(Arduino Nano = Master 和 ESP8266 = Slave)时,Wire 示例不起作用。
My workaround for this issue was to reduce the I²C working frequence from 100kHz to about 20kHz.我对此问题的解决方法是将 I²C 工作频率从 100kHz 降低到大约 20kHz。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.