ESP32s3 I2c0 SCL一直高电平,没有时钟输出,SDA也是一直高电平
日志显示初始化成功
I (4197) driver-codec: i2s driver init success
I (9197) driver-codec: I2C_MASTER_NUM=0,mode=1,speed=100000
I (9197) driver-codec: I2C ini
tialized successfully
I (9207) driver-codec: i2c_read cnt = 0, error = -1
代码如下:
#define I2C0_MASTER_SCL_IO 18 /*!< GPIO number used for I2C master clock */
#define I2C0_MASTER_SDA_IO 17 /*!< GPIO number used for I2C master data */
static esp_err_t i2c_master_init(void)
{
int i2c_master_port = I2C_MASTER_NUM;
i2c_config_t conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = I2C0_MASTER_SDA_IO,
.scl_io_num = I2C0_MASTER_SCL_IO,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = I2C_MASTER_FREQ_HZ,
.clk_flags = 0,
};
esp_err_t err = i2c_param_config(i2c_master_port, &conf);
if (err != ESP_OK) {
return err;
}
ESP_LOGI(TAG, "I2C_MASTER_NUM=%d,mode=%d,speed=%d",i2c_master_port,conf.mode,conf.master.clk_speed);
return i2c_driver_install(i2c_master_port, conf.mode, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0);
}
uint16_t AW88266A_i2c_read(unsigned char reg_addr)
{
int ret;
uint8_t cnt = 0;
uint8_t data_buff[2] = {0};
uint16_t data = 0;
while (cnt < I2C_RETRY_TIMES)
{
ret = i2c_master_write_read_device(I2C_MASTER_NUM, AW88266A_CODEC_ADDR, ®_addr, 1, data_buff, 2, I2C_MASTER_TIMEOUT_MS / portTICK_PERIOD_MS);
if (ret != 0)
ESP_LOGI(TAG, "i2c_read cnt = %d, error = %dn", cnt, ret);
else
break;
cnt++;
}
data = (((data_buff[0] << 8) & 0xff00) | (data_buff[1] & 0x00ff));
ESP_LOGI(TAG, "i2c_read data = %dn", data);
return data;
}