ESP8266 I2C 从机不确认数据 [英] ESP8266 I2C slave does not acknowledge data

查看:81
本文介绍了ESP8266 I2C 从机不确认数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a TM4C123 processor acting as a I2C master and a ESP8266 as a slave. 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. 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.

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

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. So I am fairly certain neither of this can be the problem.

我使用的是 Olimex Mod-wifi 板,带有 SDA 引脚 12 和 SCL 引脚 13 (这里有原理图)

I am using the Olimex Mod-wifi board, with SDA Pin 12 and SCL Pin 13 (Schematic here)

有人可以帮助我吗?这是我的代码:

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
}

推荐答案

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

I had a compareable issue with the ESP8266. It was no problem sending data between the Arduino Nano (Slave) to the ESP8266 (Master) via I²C. But when I switch the modes (Arduino Nano = Master and ESP8266 = Slave) the Wire example doesn't work.

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

My workaround for this issue was to reduce the I²C working frequence from 100kHz to about 20kHz.

这篇关于ESP8266 I2C 从机不确认数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆