簡體   English   中英

ESP8266 I2C 從機不確認數據

[英]ESP8266 I2C slave does not acknowledge data

我有一個 TM4C123 處理器充當 I2C 主設備和一個 ESP8266 作為從設備。 對於 ESP,我使用 Arduino IDE 和 ESP8266 支持安裝在版本 2.5.2,它應該支持 I2C 從模式。 但是,我無法讓它工作。 即使使用 Arduino slave_receiver 示例,從設備也不會確認(ACK)我在示波器上顯示的主設備的請求。

為了確保我至少使用了一次正確的地址,我在主服務器上實施了地址掃描。 為了確保我在 ESP 上使用了正確的引腳,我首先在 ESP 上實現了主模式,並使用 I2C 從設備進行了引腳掃描。 所以我相當肯定這兩個都不是問題。

我正在使用 Olimex Mod-wifi 板,帶有 SDA 引腳 12 和 SCL 引腳 13( 此處為示意圖

有人可以幫我嗎? 這是我的代碼:

// 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²C 工作頻率從 100kHz 降低到大約 20kHz。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM