hi there,
I have a I2C code which is working, but I don't understand how it works. Hence, appreciate if someone able to give me a hand, please!
Here is the code.
My question is,
In I2C_master_init(), it does not create a handle. In void task_bme280_normal_mode(void *ignore), the read/write of I2C functions do not reference to any handle. Withtout the handle, how would it know what/which I2C bus it is using? assuming there are two I2C buses being used in the project. I have checked, there is no global variable storing the handle as well.
Appreciate any comments.
Thank you
vi
void I2C_master_init()
{
i2c_config_t i2c_config = {
.mode = I2C_MODE_MASTER,
.sda_io_num = SDA_PIN,
.scl_io_num = SCL_PIN,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = 1000000
};
i2c_param_config(I2C_NUM_0, &i2c_config);
i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER, 0, 0, 0);
}
void task_bme280_normal_mode(void *ignore)
{
struct bme280_t bme280 = {
.bus_write = CCS811_I2C_bus_write,
.bus_read = CCS811_I2C_bus_read,
.dev_addr = CCS811_I2C_ADDRESS,
.delay_msec = CCS811_delay_msek
};
s32 com_rslt = 0;
s32 v_uncomp_pressure_s32;
s32 v_uncomp_temperature_s32;
s32 v_uncomp_humidity_s32;
com_rslt = bme280_init(&bme280);
ESP_LOGE(TAG_CCS811, "bme280_init: %d", com_rslt);
com_rslt += bme280_set_oversamp_pressure(BME280_OVERSAMP_16X);
ESP_LOGE(TAG_CCS811, "bme280_set_oversamp_pressure BME280_OVERSAMP_16X: %d", com_rslt);
com_rslt += bme280_set_oversamp_temperature(BME280_OVERSAMP_2X);
ESP_LOGE(TAG_CCS811, "bme280_set_oversamp_temperature BME280_OVERSAMP_2X: %d", com_rslt);
com_rslt += bme280_set_oversamp_humidity(BME280_OVERSAMP_1X);
ESP_LOGE(TAG_CCS811, "bme280_set_oversamp_humidity BME280_OVERSAMP_1X: %d", com_rslt);
com_rslt += bme280_set_standby_durn(BME280_STANDBY_TIME_1_MS);
ESP_LOGE(TAG_CCS811, "bme280_set_standby_durn BME280_STANDBY_TIME_1_MS: %d", com_rslt);
com_rslt += bme280_set_filter(BME280_FILTER_COEFF_16);
ESP_LOGE(TAG_CCS811, "bme280_set_filter BME280_FILTER_COEFF_16: %d", com_rslt);
com_rslt += bme280_set_power_mode(BME280_NORMAL_MODE);
ESP_LOGE(TAG_CCS811, "bme280_set_power_mode BME280_NORMAL_MODE: %d", com_rslt);
if (com_rslt == SUCCESS) {
while(true) {
//vTaskDelay(40/portTICK_PERIOD_MS);
vTaskDelay(pdMS_TO_TICKS(1000));
if (xSemaphoreTake(resourceManager,1000)) {
com_rslt = bme280_read_uncomp_pressure_temperature_humidity(
&v_uncomp_pressure_s32, &v_uncomp_temperature_s32, &v_uncomp_humidity_s32);
if (com_rslt == SUCCESS) {
ESP_LOGI(TAG_CCS811, "%.2f degC / %.3f hPa / %.3f %%",
bme280_compensate_temperature_double(v_uncomp_temperature_s32),
bme280_compensate_pressure_double(v_uncomp_pressure_s32)/100, // Pa -> hPa
bme280_compensate_humidity_double(v_uncomp_humidity_s32));
} else {
ESP_LOGE(TAG_CCS811, "measure error. code: %d", com_rslt);
}
xSemaphoreGive(resourceManager);
}
}
} else {
ESP_LOGE(TAG_CCS811, "init or setting error. code: %d", com_rslt);
}
vTaskDelete(NULL);
}
initialize i2c device needs help
Re: initialize i2c device needs help
Probably in the source for bme280 functions
Re: initialize i2c device needs help
Well, having gone through the I2C.c, I understand what my misunderstanding was. Thanks for the comments.
Who is online
Users browsing this forum: tahseenabbas52 and 81 guests