I am using ESP32 , and 2 pressure sensors.
I succeed getting the data from each sensor separately.
As they have the sam I2c address, I am trying to call I2c1 & I2c2.
When I call i2c2 - I get the error message
Guru Meditation Error: Core 1 panic'ed (StoreProhibited). Exception was unhandled.
if I delete this line: I2C2.begin(I2C2_SDA2, I2C2_SCL2,100000);
all is working great ( from one sensor)
Thanks:::
here is my code:
#include <Wire.h> // so we can use I2C communication
const int SENSORADDRESS = 0x28; // ELVH-L01D-HRRD-C-N2A4 address from the datasheet
#define I2C1_SDA1 21
#define I2C1_SCL1 22
#define I2C2_SDA2 19
#define I2C2_SCL2 18
#define SENSOR_CONTROL_REG_1 0x28
#define SENSOR_DR_STATUS 0x00 // Address of DataReady status register
#define SENSOR_OUT_P_MSB 0x01 // Starting address of Pressure Data registers
byte I2Cdata[4] = {0,0,0,0}; //buffer for sensor data 32 bits
byte I2Cdata2[4] = {0,0,0,0}; //buffer for sensor data 32 bits
TwoWire I2C1 = TwoWire(0); //I2C1 bus
TwoWire I2C2 = TwoWire(1); //I2C2 bus
void setup(){
Serial.begin(9600);
I2C1.begin(I2C1_SDA1, I2C1_SCL1, 100000); // Start I2C1 on pins 21 and 22
I2C2.begin(I2C2_SDA2, I2C2_SCL2,100000);
I2C_Write1(SENSORADDRESS, 0100000000); // put in start mode
//I2C_Write2(SENSORADDRESS, 0100000000); // put in start mode
I2C_Write1(SENSORADDRESS, 0b00111000); // set oversampling to 128
//I2C_Write2(SENSORADDRESS, 0b00111000); // set oversampling to 128
}
void loop(){
float pressure;
Read_Sensor_Data1();
//Read_Sensor_Data2();
delay(500);
}
// Read the pressure and temperature readings from the sensor
void Read_Sensor_Data1(){
I2C_Write1(SENSOR_CONTROL_REG_1, 0b00111010); //bit 1 is one shot mode
do {
// Serial.println("DO Inside read sensordata.");
I2C1.requestFrom(SENSORADDRESS,1);
} while ((I2C1.read() & 0b00000010) != 0);
//Serial.println("While Inside read sensordata.");
I2C_ReadData1(); //reads registers from the sensor
}
// Read Pressure data (4 bytes)
void I2C_ReadData1(){
byte readUnsuccessful;
//Serial.println("void I2C_ReadData!!!!");
do {
byte I=0;
byte dataStatus = 0;
I2C1.beginTransmission(SENSORADDRESS);
I2C1.write(SENSOR_OUT_P_MSB);
I2C1.endTransmission(false);
// read 4 bytes. 2 for pressure, 2 for temperature.
I2C1.requestFrom(SENSORADDRESS,4);
while(I2C1.available()) {I2Cdata[i++] = I2C1.read();
Serial.print("sensor1 = ");
Serial.println(I2Cdata[1]);
delay(100);
}
//Serial.println(readUnsuccessful);
readUnsuccessful=1;
} while (readUnsuccessful);
//Serial.println("readUnsuccessful"[I]);
}
void I2C_Write1(byte regAddr, byte value){
I2C1.beginTransmission(SENSORADDRESS);
I2C1.write(regAddr);
I2C1.write(value);
I2C1.endTransmission(true);
}