35 lines
893 B
C++
35 lines
893 B
C++
#include "i2c.h"
|
|
#include "esp_log.h"
|
|
#include "esp_err.h"
|
|
#include "driver/i2c.h"
|
|
|
|
static const char *TAG = "i2c";
|
|
|
|
SemaphoreHandle_t i2c0_mutex;
|
|
|
|
void init_i2c() {
|
|
ESP_LOGI(TAG, "Initializing i2c...");
|
|
|
|
i2c_config_t conf = {
|
|
.mode = I2C_MODE_MASTER,
|
|
.sda_io_num = GPIO_NUM_5,
|
|
.scl_io_num = GPIO_NUM_6,
|
|
.sda_pullup_en = GPIO_PULLUP_DISABLE,
|
|
.scl_pullup_en = GPIO_PULLUP_DISABLE,
|
|
// .sda_pullup_en = GPIO_PULLUP_ENABLE,
|
|
// .scl_pullup_en = GPIO_PULLUP_ENABLE,
|
|
.master = {
|
|
.clk_speed = 100*1000,
|
|
},
|
|
.clk_flags = I2C_SCLK_SRC_FLAG_FOR_NOMAL
|
|
};
|
|
|
|
ESP_ERROR_CHECK(i2c_param_config(I2C_NUM_0, &conf));
|
|
ESP_ERROR_CHECK(i2c_driver_install(I2C_NUM_0, conf.mode, 0, 0, 0));
|
|
|
|
i2c0_mutex = xSemaphoreCreateMutex();
|
|
assert(i2c0_mutex != NULL);
|
|
|
|
ESP_LOGI(TAG, "i2c initialized!");
|
|
}
|