I am currently stuck with running I2C on an Adafruit ESP32 Feather. A simple initiation of the sensor register to define sensitivity etc. fails whilst the same code works ok on Arduino Uno, Adafruit M0 and Adafruit ESP8266. In the ESP32 configuration I can read the sensor identity but I can´t write into the registers. In fact it has all worked with the ESP32 for some months but now something has changed and I can´t understand what is going on....
Wire.begin();
Wire.beginTransmission(GYRO_addr);
Wire.write(SENSOR_CONFIG0_addr);
Wire.write (sensorconfig); // ACC xyz and GYRO xyz enabled.
Wire.endTransmission(false);
Please edit your post and take the details of the problem out of the code tags to make it easier to read
That sounds like a bus voltage issue. 5V devices work well with the Uno, but not with the 3.3V ESP. You need an I2C level shifter module.
The sensor I use, the ICM40327 has 3,3 V as logical levels!
How did you power it on the Uno?
Do you use the bare chip or a module that possibly includes a level shifter?
Which pullup resistors are involved, connected how?
Thanks for responding. Please note that the processors Adafruit Feather M0 and Adafruit Feather 8266 both are 3.3 volts and they function correctly with the same code interfacing my sensor.
Leif
Skickat från min Galaxy
-------- Originalmeddelande --------
If everything works then please ask your question. Start by editing your first message so that it is readable to everybody.
Hello again, my problem is only with the ESP32 Feather, the other processors work nicely with the same sw and hw.
Leif
Skickat från min Galaxy
-------- Originalmeddelande --------
Please post the entire code and a image of your project.
Hi, thanks, I will do later today or tomorrow morning.
All best, Leif
Skickat från min Galaxy
-------- Originalmeddelande --------
Here is my test code:
// 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);}
The hardware is just the actual processor, two pull-up resistors 5.6k on SDA/SCL-lines, short 5 cm leads and the connected IMU ICM 40627. Nothing else.
The above testcode responds with "0,9,15,15,38,6" when executed on an Arduino UNO, a Adafruit Feather M0 or an Adafruit Feather ESP8266 which are the correct values. When executed on a Adafruit ESP32 Feather the response is "0,5,0,6,6,6".
Leif
Code in code tags, please.
Show wiring.
Without code tags I see
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.