2024-03-06 06:09:49 +08:00
|
|
|
// I2C设置
|
|
|
|
#define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
|
|
|
|
#define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
|
2024-03-07 05:21:06 +08:00
|
|
|
#define I2C0_PORT 0
|
2024-03-06 06:09:49 +08:00
|
|
|
#define I2C0_SCL_IO 42
|
|
|
|
#define I2C0_SDA_IO 41
|
|
|
|
#define I2C0_FREQ_HZ 40000
|
|
|
|
#define I2C_MASTER_TIMEOUT_MS 14000
|
|
|
|
|
2024-03-07 05:21:06 +08:00
|
|
|
#include "driver/i2c_master.h"
|
2024-03-06 06:09:49 +08:00
|
|
|
#include "esp_log.h"
|
2024-03-08 01:45:59 +08:00
|
|
|
#include <sw7203.h>
|
2024-03-06 06:09:49 +08:00
|
|
|
|
2024-03-07 05:21:06 +08:00
|
|
|
i2c_master_bus_config_t i2c0_mst_config_1 = {
|
|
|
|
.clk_source = I2C_CLK_SRC_DEFAULT,
|
|
|
|
.i2c_port = I2C0_PORT,
|
|
|
|
.scl_io_num = I2C0_SCL_IO,
|
|
|
|
.sda_io_num = I2C0_SDA_IO,
|
|
|
|
.glitch_ignore_cnt = 7,
|
|
|
|
.flags.enable_internal_pullup = true,
|
|
|
|
};
|
|
|
|
i2c_master_bus_handle_t I2C0_bus_handle;
|
|
|
|
|
|
|
|
void app_main()
|
|
|
|
{
|
|
|
|
ESP_ERROR_CHECK(i2c_new_master_bus(&i2c0_mst_config_1, &I2C0_bus_handle));
|
|
|
|
ESP_ERROR_CHECK(i2c_master_probe(I2C0_bus_handle, 0x22, -1));
|
|
|
|
ESP_ERROR_CHECK(i2c_del_master_bus(I2C0_bus_handle));
|
|
|
|
}
|