29 lines
871 B
C
29 lines
871 B
C
// 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 */
|
|
#define I2C0_PORT 0
|
|
#define I2C0_SCL_IO 42
|
|
#define I2C0_SDA_IO 41
|
|
#define I2C0_FREQ_HZ 40000
|
|
#define I2C_MASTER_TIMEOUT_MS 14000
|
|
|
|
#include "driver/i2c_master.h"
|
|
#include "esp_log.h"
|
|
|
|
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));
|
|
return 0;
|
|
} |