比如iic的example,以下代码直接在函数里创建了conf结构体变量,成员初值是随机的,这样写是严重的错误写法,需要将结构体变量的初始值置为0才行。
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 = I2C_MASTER_SDA_IO,
.scl_io_num = I2C_MASTER_SCL_IO,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = I2C_MASTER_FREQ_HZ,
};
i2c_param_config(i2c_master_port, &conf);
return i2c_driver_install(i2c_master_port, conf.mode, I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0);
}
官方的example里,创建结构体变量都没有进行初值置0操作,请官方注意,这是错误的写法
Who is online
Users browsing this forum: No registered users and 103 guests