Code: Select all
esp_err_t i2c_new_master_bus(const i2c_master_bus_config_t *bus_config, i2c_master_bus_handle_t *ret_bus_handle);
Log output:
Code: Select all
I (414) main_task: Started on CPU0
I (424) main_task: Calling app_main()
I (424) [BATHROOM_SENSOR]: Starting bath room app...
I (424) gpio: GPIO[5]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (434) gpio: GPIO[5]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (444) gpio: GPIO[2]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
I (454) gpio: GPIO[2]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 0| Intr:0
I (464) [App]: Setting up the app...
I (464) [App]: └── Initializing I2C master bus...
I (474) gpio: GPIO[20]| InputEn: 1| OutputEn: 1| OpenDrain: 1| Pullup: 0| Pulldo
Code: Select all
void App::setup() {
ESP_LOGI(TAG, "Setting up the app...");
esp_err_t status = ESP_OK;
status = i2c_master_init();
if (status != ESP_OK) {
ESP_LOGE(TAG, "└── Failed to initialize I2C master bus. Reason: %s", esp_err_to_name(status));
esp_deep_sleep_start();
}
ESP_LOGI(TAG, "└── Initialized I2C master bus. Status: %d", status); // <- This is not printed anymore.
// more code omitted
}
Code: Select all
esp_err_t App::i2c_master_init() {
ESP_LOGI(TAG, "└── Initializing I2C master bus...");
i2c_master_bus_config_t config = {
.i2c_port = -1, // auto select
.sda_io_num = I2C_GPIO_SDA,
.scl_io_num = I2C_GPIO_SCL,
.clk_source = I2C_CLK_SRC_DEFAULT,
.glitch_ignore_cnt = 7, // recommended
.intr_priority = 0, // auto select
.flags = {
.enable_internal_pullup = 0,
},
};
return i2c_new_master_bus(&config, &_i2c_bus_handle);
}