【已解决】求助:ESP32C3 I2C发送数据错误
Posted: Sun Feb 20, 2022 8:06 am
- void app_main(void)
- {
- I2C_Init();
- i2c_cmd_handle_t cmd = i2c_cmd_link_create();
- i2c_master_start(cmd);
- // i2c_master_start(cmd);
- i2c_master_write_byte(cmd, ((0x06) << 1) | WRITE_BIT, ACK_CHECK_EN);
- i2c_master_write_byte(cmd, 0x09, ACK_CHECK_EN);
- i2c_master_write_byte(cmd, 0xB3, ACK_CHECK_DIS);
- i2c_master_write_byte(cmd, 0x0A, ACK_CHECK_DIS);
- i2c_master_write_byte(cmd, 0x05, ACK_CHECK_DIS);
- i2c_master_write_byte(cmd, 0x3c, ACK_CHECK_DIS);
- i2c_master_write_byte(cmd, 0x08, ACK_CHECK_DIS);
- i2c_master_stop(cmd);
- esp_err_t ret = i2c_master_cmd_begin(i2c_master_port, cmd, 1000 / portTICK_RATE_MS);
- i2c_cmd_link_delete(cmd);
- if (ret == ESP_OK)
- {
- ESP_LOGI(TAG, "Write OK");
- }
- else if (ret == ESP_ERR_TIMEOUT)
- {
- ESP_LOGW(TAG, "Bus is busy");
- }
- else
- {
- ESP_LOGW(TAG, "Write Failed");
- }
- // vTaskDelay(1000 / portTICK_PERIOD_MS);
- // I2C_Write(i2c_master_port,0x06,0x09,0xB3);
- // vTaskDelay(50 / portTICK_PERIOD_MS);
- // I2C_Write(i2c_master_port,0x06,0x09,0xB3);
- // printf("key\n");
- // I2C_Write(i2c_master_port,0x06,0x0A,0x05);
- // printf("programe\n");
- // // I2C_Write(i2c_master_port,6,0x3C,0x07);
- // //
- }
- 我使用ESP-IDF4.4 开发SP32C3的I2C,代码如上,我发现逻辑分析仪读出的数据和程序不符,想知道是为什么
- 我尝试使用官方的I2C程序后调试发现是自己的传感器寄存器操作的有问题