ESP32 Feather, issues with I2C

Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Locked
User avatar
LeifLundberg
 
Posts: 6
Joined: Thu Dec 23, 2021 4:28 am

ESP32 Feather, issues with I2C

Post by LeifLundberg »

I run an application on a sw-code communicating with an IMU using I2C-protocol and it works fine on Arduino Uno, Adafruit M0 and Adafruit ESP8266 but when I run my application on the ESP 32 Feather, it won´t work.
I can isolate the problem to the initialization of the sensor, that is when I want to write the sensors registers setiing sensitivity etc. Nothing works.
At the same time I don´t have a problem to read regsiters, i.e. the "WHO AM I"-register.

Anyone that can offer some ideas on what to do?
Thanks in advance.

Leif

part of the code:
Wire.begin();
Wire.beginTransmission(GYRO_addr);
Wire.write(SENSOR_CONFIG0_addr);
Wire.write (sensorconfig); // ACC xyz and GYRO xyz enabled.
Wire.endTransmission(false);

User avatar
adafruit_support_carter
 
Posts: 29150
Joined: Tue Nov 29, 2016 2:45 pm

Re: ESP32 Feather, issues with I2C

Post by adafruit_support_carter »

Which specific ESP32 based Feather are you using? There are a few. Can you link to the product page.

User avatar
LeifLundberg
 
Posts: 6
Joined: Thu Dec 23, 2021 4:28 am

Re: ESP32 Feather, issues with I2C

Post by LeifLundberg »

adafruit_support_carter wrote: Wed Oct 05, 2022 11:15 am Which specific ESP32 based Feather are you using? There are a few. Can you link to the product page.
I'm using Adafruit Feather HUZZAH32-ESP32.

User avatar
adafruit_support_carter
 
Posts: 29150
Joined: Tue Nov 29, 2016 2:45 pm

Re: ESP32 Feather, issues with I2C

Post by adafruit_support_carter »

OK, so not one of the version with low power features that can depower the whole I2C bus. So something else.

Do you know if the IMU does any clock stretching? Or has requirements for repeated starts?

User avatar
LeifLundberg
 
Posts: 6
Joined: Thu Dec 23, 2021 4:28 am

Re: ESP32 Feather, issues with I2C

Post by LeifLundberg »

There is nothing in the Invensense's datasheet about that and please note that the test code works 100% with the basic Arduino UNO.

User avatar
adafruit_support_carter
 
Posts: 29150
Joined: Tue Nov 29, 2016 2:45 pm

Re: ESP32 Feather, issues with I2C

Post by adafruit_support_carter »

It could be some ESP32 specific quirk.

It sounds like you're writing your own driver? Or are you using an existing driver?

User avatar
LeifLundberg
 
Posts: 6
Joined: Thu Dec 23, 2021 4:28 am

Re: ESP32 Feather, issues with I2C

Post by LeifLundberg »

This is my testcode working on M0, ESP8266 and UNO but not on ESP32:

Code: Select all

 // Sketch ICM-40627 test

  #include "Wire.h"
 
  uint16_t WHOAMI;
  byte PWR;  
  byte sensorconfig=0b00000000; // 0
  byte driveconfig =0b00001001; // 9
  byte pwrmgmnt0 = 0b00001111; // 15
  byte accelconfig01 = 0b00001111; // 15
  byte gyroconfig0 = 0b000100110; // 38
  byte accelconfig02 = 0b00000110; // 6

   // ICM-40627-adresses

   const int GYRO_addr = 0x68; 
   const int SENSOR_CONFIG0_addr = 0x03;
   const int DEVICE_CONFIG_addr = 0x11;
   const int DRIVE_CONFIG_addr = 0x13;
   const int INT_CONFIG_addr = 0x14;
   const int FIFO_CONFIG_addr = 0x16;  

   const uint8_t PWR_MGMNT0_addr = 0x4E;
   const uint8_t GYRO_CONFIG0_addr = 0x4F;
   const uint8_t ACCEL_CONFIG0_addr = 0x50;
   const uint8_t GYRO_CONFIG1_addr = 0x51;
   const uint8_t GYRO_ACCEL_CONFIG0_addr = 0x52; 
   const uint8_t ACCEL_CONFIG1_addr = 0x53;
   const uint8_t WHO_AM_I_addr = 0x75;

  //*******************************************************   

   void setup() {     
   Serial.begin(115200);    
   Wire.begin(); 
   Wire.beginTransmission(GYRO_addr);
   Wire.write(WHO_AM_I_addr);  // register low X-data
   Wire.endTransmission(false);
   Wire.requestFrom(GYRO_addr, 1, true);
   WHOAMI = Wire.read();
   Serial.print("WHOAMI:");
   Serial.println(WHOAMI);   
   delay(500);   
   }   
   //*******************************************************   
   void loop() {    
   delay(500);   
   Init_ICM40627();    
   delay(500);
   }  

void Init_ICM40627(){
    Wire.begin();
    Wire.beginTransmission(GYRO_addr);
    Wire.write(SENSOR_CONFIG0_addr);
    Wire.write (sensorconfig); // ACC xyz and GYRO xyz enabled.
    Wire.endTransmission(false);   
    
    Wire.beginTransmission(GYRO_addr);
    Wire.write(SENSOR_CONFIG0_addr);
    Wire.endTransmission(false);
    Wire.requestFrom(GYRO_addr, 1, true);
    PWR = Wire.read();
    
    Serial.print("SENSOR CONFIG:");
    Serial.println(PWR);

  
    
    Wire.begin();
    Wire.beginTransmission(GYRO_addr);
    Wire.write(DRIVE_CONFIG_addr);
    Wire.write (driveconfig); // bits 5:3=1, bits 2:0 = 1
    Wire.endTransmission(false);   

    Wire.beginTransmission(GYRO_addr);
    Wire.write(DRIVE_CONFIG_addr);
    Wire.endTransmission(false);
    Wire.requestFrom(GYRO_addr, 1, true);
    PWR = Wire.read();

    Serial.print("DRIVE CONFIG:");
    Serial.println(PWR);

   
    
    Wire.begin();
    Wire.beginTransmission(GYRO_addr);
    Wire.write(PWR_MGMNT0_addr);
    Wire.write (pwrmgmnt0); // both gyro and accelerometer in low noise mode. Temperature sensor enabled.
    Wire.endTransmission(false);   

    Wire.beginTransmission(GYRO_addr);
    Wire.write(PWR_MGMNT0_addr);
    Wire.endTransmission(false);
    Wire.requestFrom(GYRO_addr, 1, true);
    PWR = Wire.read();

    Serial.print("PWR_MGMNT0:");
    Serial.println(PWR);

    

    Wire.begin();
    Wire.beginTransmission(GYRO_addr);
    Wire.write(ACCEL_CONFIG0_addr);
    Wire.write (accelconfig01); // bit 7-5: 00x which means +/- 16G, bit 3-0: 1111 which means 500 Hz ODR
    Wire.endTransmission(false);   

    Wire.beginTransmission(GYRO_addr);
    Wire.write(ACCEL_CONFIG0_addr);
    Wire.endTransmission(false);
    Wire.requestFrom(GYRO_addr, 1, true);
    PWR = Wire.read();

    Serial.print("ACCEL CONFIG0:");
    Serial.println(PWR);

   
    
    Wire.begin();
    Wire.beginTransmission(GYRO_addr);
    Wire.write(GYRO_CONFIG0_addr);
    Wire.write (gyroconfig0); // bit 7-5: 0001 which means 1000 dps sensitivity, bit 4 reserved,  bit 3-0: 0110 which means 1000 Hz ODR
    Wire.endTransmission(false);
    
    Wire.beginTransmission(GYRO_addr);
    Wire.write(GYRO_CONFIG0_addr);
    Wire.endTransmission(false);
    Wire.requestFrom(GYRO_addr, 1, true);
    PWR = Wire.read();

    Serial.print("GYRO CONFIG0:");
    Serial.println(PWR);

   
    
    Wire.begin();
    Wire.beginTransmission(GYRO_addr);
    Wire.write(ACCEL_CONFIG0_addr);
    Wire.write (accelconfig02); // bit 7-5: 000 which means +/- 16G sensitivity, bit 3-0: 0110 which means 1000 Hz ODR
    Wire.endTransmission(false);    

    Wire.beginTransmission(GYRO_addr);
    Wire.write(ACCEL_CONFIG0_addr);
    Wire.endTransmission(false);
    Wire.requestFrom(GYRO_addr, 1, true);
    PWR = Wire.read();
    
    Serial.print("ACCEL CONFIG0:");
    Serial.println(PWR);}
Last edited by adafruit_support_carter on Thu Oct 06, 2022 11:19 am, edited 1 time in total.

User avatar
adafruit_support_carter
 
Posts: 29150
Joined: Tue Nov 29, 2016 2:45 pm

Re: ESP32 Feather, issues with I2C

Post by adafruit_support_carter »

Wire.begin() should only be called once. Try removing the extra calls.

Locked
Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.

Return to “Internet of Things: Adafruit IO and Wippersnapper”