You can chat about native SDK questions and issues here.

User avatar
By Samoht
#82912 Hi everyone,
I'm experiencing a very weird problem when trying to port a little piece of software from ESP8266 to ESP8285.
All I want to do basically is to poll a sensor connected via I2C.
On the 8266 board the code works flawlessly and I can read out sensor registers but on the 8285 board I don't get a response from the sensor.
I already checked the wiring by loading an Arduino sketch that reads a register of the sensor and that works as well. I also double checked that I changed the pins in i2c_master.h to the actually used ones by toggling them slowly and measuring the output voltage.
I'm really out of ideas on what to try.
Below is the code I am using to test at the moment and a snippet of the i2c_master.h file.
Code: Select allvoid ICACHE_FLASH_ATTR user_init(void)
{
    gpio_init();

    uart_init(115200, 115200);

    os_delay_us(10000);
    i2c_master_gpio_init();
    os_delay_us(100);
    while(1){
     i2c_master_start();
     i2c_master_writeByte(0x68 << 1);
     if(i2c_master_checkAck() != 1){
       i2c_master_stop();
       os_printf("No ack\n");
       os_delay_us(10000);
     }
    }
}

Code: Select all#define I2C_MASTER_SDA_MUX PERIPHS_IO_MUX_GPIO4_U
#define I2C_MASTER_SCL_MUX PERIPHS_IO_MUX_GPIO5_U
#define I2C_MASTER_SDA_GPIO 4
#define I2C_MASTER_SCL_GPIO 5
#define I2C_MASTER_SDA_FUNC FUNC_GPIO4
#define I2C_MASTER_SCL_FUNC FUNC_GPIO5


And this is the working Arduino sketch:
Code: Select all#include <Wire.h>
#include <Arduino.h>
#define SDA 4
#define SCL 5
void setup()
{
  Wire.begin(SDA, SCL);

  Serial.begin(115200);
  while (!Serial);             // Leonardo: wait for serial monitor
}

void loop()
{
      const uint8_t addr = 0x68;

      Wire.beginTransmission(addr);
      Wire.write(byte(117));
      Wire.endTransmission(false);  //Send the actual data but without stop

      Wire.requestFrom(addr, 1); //Read one byte from slave

      Serial.println(Wire.read());
      delay(100);
}