This commit is contained in:
2024-06-16 09:03:21 +03:00
parent 92a6e4362a
commit f6bafc6fe3

View File

@ -40,7 +40,7 @@ esp_err_t zh_bh1750_init(zh_bh1750_init_config_t *config)
.scl_speed_hz = 100000,
};
ESP_ERROR_CHECK(i2c_master_bus_add_device(_init_config.i2c_handle, &bh1750_config, &_bh1750_handle));
ESP_ERROR_CHECK(i2c_master_probe(_init_config.i2c_handle, _init_config.i2c_address, -1));
ESP_ERROR_CHECK(i2c_master_probe(_init_config.i2c_handle, _init_config.i2c_address, 1000 / portTICK_PERIOD_MS));
switch (_init_config.operation_mode)
{
case LOW_RESOLUTION:;
@ -118,15 +118,16 @@ READ:
// ESP_LOGE(TAG, "BH1750 read fail. I2C driver error.");
// return esp_err;
// }
ESP_ERROR_CHECK(i2c_master_receive(_bh1750_handle, &sensor_data_high, 8, -1));
ESP_ERROR_CHECK(i2c_master_receive(_bh1750_handle, &sensor_data_low, 8, -1));
uint8_t temp[2] = {0};
ESP_ERROR_CHECK(i2c_master_receive(_bh1750_handle, &temp, 2, -1));
// ESP_ERROR_CHECK(i2c_master_receive(_bh1750_handle, &sensor_data_low, 1, -1));
if (_init_config.operation_mode == HIGH_RESOLUTION_2)
{
*data = (sensor_data_high << 8 | sensor_data_low) * (1 / 1.2 * (69.0 / _sensivity) / 2);
*data = (temp[0] << 8 |temp[1]) * (1 / 1.2 * (69.0 / _sensivity) / 2);
}
else
{
*data = (sensor_data_high << 8 | sensor_data_low) * (1 / 1.2 * (69.0 / _sensivity));
*data = (temp[0] << 8 | temp[1]) * (1 / 1.2 * (69.0 / _sensivity));
}
ESP_LOGI(TAG, "BH1750 read success.");
return ESP_OK;