From f6bafc6fe3046e004ab28080b5ce8699e9641eb9 Mon Sep 17 00:00:00 2001 From: Alexey Zholtikov Date: Sun, 16 Jun 2024 09:03:21 +0300 Subject: [PATCH] WIP --- zh_bh1750.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/zh_bh1750.c b/zh_bh1750.c index 66a6179..09eda20 100644 --- a/zh_bh1750.c +++ b/zh_bh1750.c @@ -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;