2

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.

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.

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
}
2
  • 1
    Last I checked (which was a while ago), the ESP8266 didn't support I2C slave mode. You might want to see if anything has changed there.
    – stevieb
    Jul 26, 2019 at 14:41
  • 1
    @stevieb according to github.com/esp8266/Arduino/issues/3046 as of 2.5.0 slave support has been added.. Jul 26, 2019 at 15:12

1 Answer 1

0

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.

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

3
  • How is it possible to send data from slave to master??
    – zhekaus
    May 14, 2020 at 21:22
  • Exactly seen, it is not possible that the slave can send data to the master. It is only possible when the master polls the data from the slave. But when you look at the Arduino examples in the "Wire" section you can find example "slave_sender". My post refers to the name of the Arduino example, which is misleading.
    – wintlef
    May 16, 2020 at 6:57
  • Esp can request data from the slave. That how slave can send data to the master.
    – zhekaus
    May 20, 2020 at 19:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.