Hi everyone,
I'm new to ESP32 and esp idf programming and trying to get an I2C master working using the code example from the [ESP-IDF documentation](https://docs.espressif.com/projects/esp ... s/i2c.html). Despite following the example, my code doesn't seem to work.
Here's the code I'm using:
Code: Select all
#include <stdio.h>
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/i2c_master.h"
#include "driver/i2c.h"
static const char *TAG = "MONIDAT";
void app_main(void)
{
i2c_master_bus_config_t i2c_mst_config = {
.clk_source = I2C_CLK_SRC_DEFAULT,
.i2c_port = -1,
.scl_io_num = 22,
.sda_io_num = 21,
.glitch_ignore_cnt = 7,
};
i2c_master_bus_handle_t bus_handle;
i2c_device_config_t dev_cfg = {
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
.device_address = 0x54,
.scl_speed_hz = 400000,
};
i2c_master_dev_handle_t dev_handle;
uint8_t buffer[6] = {};
ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_mst_config, &bus_handle));
ESP_ERROR_CHECK(i2c_master_probe(bus_handle, 0x54, -1));
ESP_ERROR_CHECK(i2c_del_master_bus(bus_handle));
ESP_ERROR_CHECK(i2c_new_master_bus(&i2c_mst_config, &bus_handle));
ESP_ERROR_CHECK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
i2c_master_receive(dev_handle, buffer, sizeof(buffer), -1);
for (size_t i = 0; i < sizeof(buffer); i++) {
ESP_LOGI(TAG, "bytes %d is %d/n", i, buffer[i]);
}
ESP_ERROR_CHECK(i2c_del_master_bus(bus_handle));
}
I have tons of error message but i don't understand them
the building step is going fine but once i flash the esp32 it goes completely crazy
Am I missing something? Any help or suggestions would be greatly appreciated!
Thanks!