ESP-C3 I2C读温度传感器,下载后提示时间选择错误

怀揣少年梦1128
Posts: 5
Joined: Thu Jun 17, 2021 12:31 am

ESP-C3 I2C读温度传感器,下载后提示时间选择错误

Postby 怀揣少年梦1128 » Sat Jul 10, 2021 8:03 am

ESP-C3 I2C读温度传感器,下载后串口提示i2c_param_config(645): i2c clock choice is invalid, please check flag and frequency,意思是说时钟无效,我不知道时为什么?请教

ESP_Gargamel
Posts: 786
Joined: Wed Nov 14, 2018 8:45 am

Re: ESP-C3 I2C读温度传感器,下载后提示时间选择错误

Postby ESP_Gargamel » Mon Jul 12, 2021 2:52 am

估计你 clk 没配对,提供下你的 i2c_config_t 设置。

怀揣少年梦1128
Posts: 5
Joined: Thu Jun 17, 2021 12:31 am

Re: ESP-C3 I2C读温度传感器,下载后提示时间选择错误

Postby 怀揣少年梦1128 » Mon Jul 12, 2021 3:37 am

我的i2c配置如下,但是这样没有问题啊

static esp_err_t i2c_master_init(void)
{
int i2c_master_port = IIC_CTRL_NUM;
i2c_config_t conf;
conf.mode = I2C_MODE_MASTER;
conf.sda_io_num = SDA_PIN_NUM;
conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
conf.scl_io_num = SCL_PIN_NUM;
conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
conf.master.clk_speed = 100000; /* 标准模式(100 kbit/s) */
i2c_param_config(i2c_master_port, &conf);
return i2c_driver_install(i2c_master_port, conf.mode, 0, 0, 0);
}

ESP_Gargamel
Posts: 786
Joined: Wed Nov 14, 2018 8:45 am

Re: ESP-C3 I2C读温度传感器,下载后提示时间选择错误

Postby ESP_Gargamel » Mon Jul 12, 2021 5:51 am

你这样写会导致 conf 有成员未初始化,因为 conf 是函数内的局部变量,会从 stack 里分配内存空间,值未知。
你可以把 conf.clk_flags 读出来看看,是否是个奇怪的值,这会导致后面 i2c_param_config 内的一些条件判断错误。
使用以下方式做初始化:

Code: Select all

i2c_config_t conf= {
conf.mode = I2C_MODE_MASTER,
conf.sda_io_num = SDA_PIN_NUM,
conf.sda_pullup_en = GPIO_PULLUP_ENABLE,
conf.scl_io_num = SCL_PIN_NUM,
conf.scl_pullup_en = GPIO_PULLUP_ENABLE,
conf.master.clk_speed = 100000, /* 标准模式(100 kbit/s) */
}

怀揣少年梦1128
Posts: 5
Joined: Thu Jun 17, 2021 12:31 am

Re: ESP-C3 I2C读温度传感器,下载后提示时间选择错误

Postby 怀揣少年梦1128 » Tue Jul 13, 2021 6:32 am

好的,我试试。多谢

Who is online

Users browsing this forum: No registered users and 49 guests