ESP8266 I2C从站不应答数据 [英] ESP8266 I2C slave does not acknowledge data

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

问题描述

我有一个充当I2C主设备的TM4C123处理器和一个作为从设备的ESP8266.对于ESP,我使用的是Arduino IDE,并在版本2.5.2中安装了ESP8266,该版本应支持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.

我正在使用带有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天全站免登陆