Reputation: 1588
well I am trying to read temp value at deepsleep with ESP32S3 ULP Riscv coprocessor from HDC1080 sensor with I2C .At first I write the code at Arduino for testing. it works fine
double temp() {
Wire.beginTransmission((uint8_t)0x40);
Wire.write((uint8_t)0x00);
Wire.endTransmission();
delay(20);
Wire.requestFrom((uint8_t)0x40, (uint8_t)2);
byte msb = Wire.read();
byte lsb = Wire.read();
uint16_t t = msb << 8 | lsb;
return (t / pow(2, 16)) * 165.0 - 40.0;
}
Now I want to convert this code for this library ulp riscv i2c library to read value at ULP mode with ESP idf. There is a example code for bmp180 sensor how can read I2C at ULP mode. If I use bmp180 with this example code everything is working properly. But I can not not read temp value from HDC1080. How can I convert at above arduino code to ulp riscv i2c library format.
While I'm not entirely sure, but docs says the ULP RISC-V I2C library always expects a slave sub-register address, but I can't seem to find such a sub-register for reading the temperature value from the HDC1080. Could this be why I'm unable to perform the read? How can I do this, can you help me?
When I checked the document of hdc1080, there is a register table for reading temp 0x00 but how can reach of [15:02] sub register
uint8_t data_buffer[2] = {0, 0};
int a = 0;
while (1)
{
vTaskDelay(pdMS_TO_TICKS(3000));
printf("Ölçüm alınıyor...%d\n\n", a++);
ulp_riscv_i2c_master_set_slave_addr(BMP180_SENSOR_I2C_ADDR); //0x40
uint8_t cmd = BMP180_SENSOR_CMD_READ_TEMPERATURE; //0x00
ulp_riscv_i2c_master_write_to_device(&cmd, 1);
// ulp_riscv_i2c_master_write_to_device((uint8_t)0x00, 1); // gives error
vTaskDelay(pdMS_TO_TICKS(10));
ulp_riscv_i2c_master_set_slave_reg_addr(BMP180_SENSOR_CMD_READ_TEMPERATURE);
ulp_riscv_i2c_master_read_from_device(data_buffer, 2);
uint16_t xut_data = ((uint16_t)data_buffer[0] << 8) | data_buffer[1];
uint16_t temperatureValue = xut_data >> 2; // D1 ve D0'ı at ve D15:D2 arasındaki değeri kullan
printf("temperatureValue: %" PRIu16 "\n", temperatureValue);
printf("data_buffer[0]: %u\n", data_buffer[0]);
printf("data_buffer[1]: %u\n", data_buffer[1]);
// temperatureValue: HDC1080'den okunan 14 bit ham sıcaklık verisi
float realTemperature = ((float)temperatureValue / (float)(1 << 14) - 1) * 165.0 - 40.0;
printf("Real Temp: %.2f°C\n", realTemperature);
}
OUTPUT eror:
Fixaj: 04-07 15:19:26-414691 E (58576) ulp_riscv_i2c: Read Failed!
Fixaj: 04-07 15:19:26-420707 E (58576) ulp_riscv_i2c: RTC I2C Interrupt Raw Reg 0x16c
Fixaj: 04-07 15:19:26-426829 E (58576) ulp_riscv_i2c: RTC I2C Status Reg 0x65ff0000
Upvotes: 0
Views: 332
Reputation: 11
This is a known, hardware issue with the RISC-V ULP co-processor inside ESP32-S3. The driver is limited by the hardware peripheral design and the RTC I2C peripheral always expects a sub register address to be programmed.
This limitation is indeed documented also in the ESP-IDF documentation.
As of now it is not possible to write/read data using the RTC I2C peripheral without writing the reg_addr, therefore sensors not expecting it may not work.
(IDFGH-8536) #9990 tracks the task of fixing this problem.
Upvotes: 1