Ending an i2c connection (something like Wire.end() )

Radu79
Posts: 29
Joined: Tue Nov 17, 2020 9:50 pm

Ending an i2c connection (something like Wire.end() )

Postby Radu79 » Thu Feb 04, 2021 11:48 pm

I have to connect an i2c light sensor to my ESp32 cam, to read the light level in order to set the proper exposure for an ov5640 sensor (the sensor has its own registries that are supposed to work, but they are unreliable).
I only need to read the light once, before the camera is initialized. My code looks like so:

Code: Select all

#define I2C_SDA 16
#define I2C_SCL 15
BH1750 lightMeter (0x23);
//TwoWire I2Clightmeter= TwoWire(1);
TwoWire *I2Clightmeter;

void setup() 
{
  int auto_mode=0;
  //WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detector

  setCpuFrequencyMhz(240);
  
  
  //setCpuFrequencyMhz(160);
  
  Serial.begin(115200);
  Serial.println();
  Serial.println("Booting... at ");
  Serial.println(millis());

  //I2Clightmeter.begin(I2C_SDA, I2C_SCL);
  //lightMeter.begin(BH1750::ONE_TIME_HIGH_RES_MODE,0x23,&I2Clightmeter);
    I2Clightmeter = new TwoWire(1);
    I2Clightmeter->begin(I2C_SDA, I2C_SCL);
    lightMeter.begin(BH1750::ONE_TIME_HIGH_RES_MODE,0x23,I2Clightmeter);
      
  delay(1000);
  uint16_t lux = lightMeter.readLightLevel();
  //delete I2Clightmeter;
The problem is, after I initialize the wire connection, the camera code crashes. I need some way to end this connection. Deleting that object doesn't work (it bootloops). If I remove the delete, I get [W][esp32-hal-i2c.c:905] i2c_isr_handler_default(): eject raw=0x2, int=0x200

So, is there any way to make the esp32 forget I2Clightmeter->begin(I2C_SDA, I2C_SCL); ?

Radu79
Posts: 29
Joined: Tue Nov 17, 2020 9:50 pm

Re: Ending an i2c connection (something like Wire.end() )

Postby Radu79 » Fri Feb 05, 2021 1:15 pm

Moving SDA on pin 14 fixed the issue.

Who is online

Users browsing this forum: themindfactory and 104 guests