I'm trying to read data from a component via I2C
From the documentation of said component, the address of the device is 0x6B and the register address is 0x30.
The data i want to read is the voltage of a battery but it's spread across two bytes with bit 15,14,13,0 being reserved (see attachment)
Thing is, I can't read the value i want (i get 0 for both the data bytes). I'm not sure what I'm doing wrong. I just want to make sure it's not the PCB that is faulty (i'm working with custom work in progress PCBs.
I'm using esp-idf 4.2 and I can not change to another version...
Here my driver setup :
- i2c_config_t conf;
- conf.mode = I2C_MODE_MASTER;
- conf.sda_io_num = SDA;
- conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
- conf.scl_io_num = SCL;
- conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
- conf.master.clk_speed = 500000;
- i2c_param_config(I2C_NUM_0, &conf);
- i2c_driver_install(I2C_NUM_0, conf.mode, 0, 0, 0);
- void CPowerManagement::BatteryCheckI2C()
- {
- uint8_t data1;
- uint8_t data2;
- uint8_t reg= 0x30;
- uint8_t address = 0x6B;
- uint16_t extracted_data;
- i2c_cmd_handle_t cmd = i2c_cmd_link_create();
- i2c_master_start(cmd);
- i2c_master_write_byte(cmd, (address << 1) | I2C_MASTER_WRITE, 1);
- i2c_master_write_byte(cmd, reg, 1);
- i2c_master_start(cmd);
- i2c_master_write_byte(cmd, (address << 1) | I2C_MASTER_READ, 1);
- i2c_master_read_byte(cmd, &data1, I2C_MASTER_ACK);
- i2c_master_read_byte(cmd, &data2, I2C_MASTER_LAST_NACK);
- i2c_master_stop(cmd);
- i2c_master_cmd_begin(0, cmd, pdMS_TO_TICKS(3000));
- i2c_cmd_link_delete(cmd);
- // extracted_data = (data1 << 3) | (data2 >> 1);
- ESP_LOGI(TAG, "Value read from I2C battery : %d et %d", data1, data2); // i get 0 and 0
- }