I2C assert failed,and not work somtimes!
Posted: Thu Aug 03, 2017 8:20 am
I have two problems with I2C.
I read data from BMX055(9 axis sensor) through I2C per 20ms
1.I2C will have assert failed when the device run for a while.
This is log:
2.Another problem is that i2c not work totally.(I2C work normally at most of the time)
Sometimes,device reboot whith i2c not work totally.This situation most commonly happened when I turn on device after make erase_flash flash or mak flash.I2C will not respond,all read or write operations failed,so the code of I2C part will run very slowly and the device will not work.In this situation ,I must unplug battery to make I2C work again.Even I make erase_flash flash again,the device not working, either!
This is part of my code:
1.I init I2C at main_app().
2.I read data from sensor per 20ms in other task.
I read data from BMX055(9 axis sensor) through I2C per 20ms
1.I2C will have assert failed when the device run for a while.
This is log:
Code: Select all
C:/esp32-idf/esp-idf/components/freertos/ringbuf.c:600 (xRingbufferReceiveUpToFromISR)- assert failed!
abort() was called at PC 0x400879d5 on core 0
Guru Meditation Error: Core 0 panic'ed (abort)
Backtrace: 0x400d1408:0x3ffc0590 0x4008542c:0x3ffc05b0 0x40118908:0x3ffc05d0 0x40081f41:0x3ffc0600
Rebooting...
ets Jun 8 2016 00:22:57
rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
Sometimes,device reboot whith i2c not work totally.This situation most commonly happened when I turn on device after make erase_flash flash or mak flash.I2C will not respond,all read or write operations failed,so the code of I2C part will run very slowly and the device will not work.In this situation ,I must unplug battery to make I2C work again.Even I make erase_flash flash again,the device not working, either!
This is part of my code:
1.I init I2C at main_app().
2.I read data from sensor per 20ms in other task.
Code: Select all
#define I2C_MASTER_FREQ_HZ 400000 /*!< I2C master clock frequency */
#define I2C_PIN_SCL 13
#define I2C_PIN_SDA 14
void i2c_master_App_init(void)
{
esp_err_t err;
int i2c_master_port = I2C_NUM_0;
i2c_config_t conf;
conf.mode = I2C_MODE_MASTER;
conf.sda_io_num = I2C_PIN_SDA;
conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
conf.scl_io_num = I2C_PIN_SCL;
conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
conf.master.clk_speed = I2C_MASTER_FREQ_HZ;
err = i2c_param_config(i2c_master_port, &conf);
err = i2c_driver_install(i2c_master_port, conf.mode,
I2C_MASTER_RX_BUF_DISABLE,
I2C_MASTER_TX_BUF_DISABLE, 0);
}
esp_err_t i2c_master_read_slave(uint8_t slaveAddr,uint8_t* data_rd, size_t size)
{
esp_err_t err;
if (size == 0) {
return ESP_OK;
}
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
err = i2c_master_start(cmd);
err = i2c_master_write_byte(cmd, ( slaveAddr << 1 ) | READ_BIT, ACK_CHECK_EN);
if (size > 1) {
err = i2c_master_read(cmd, data_rd, size - 1, ACK_VAL);
}
err = i2c_master_read_byte(cmd, data_rd + size - 1, NACK_VAL);
err = i2c_master_stop(cmd);
esp_err_t ret = i2c_master_cmd_begin(I2C_NUM_0, cmd, 1000 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);
return ret;
}
esp_err_t i2c_master_write_slave(uint8_t slaveAddr,uint8_t* data_wr, size_t size)
{
esp_err_t err;
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
err = i2c_master_start(cmd);
err = i2c_master_write_byte(cmd, ( slaveAddr << 1 ) | WRITE_BIT, ACK_CHECK_EN);
err = i2c_master_write(cmd, data_wr, size, ACK_CHECK_EN);
err = i2c_master_stop(cmd);
esp_err_t ret = i2c_master_cmd_begin(I2C_NUM_0, cmd, 1000 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);
return ret;
}
esp_err_t BMX055_IIC_Write_Bytes(uint8_t Sensor_Slave_Addr,uint8_t addr,uint8_t* data_wr, size_t size)
{
uint8_t data[16];
data[0]=addr;
MEMCPY(data+1,data_wr,size);
esp_err_t err = i2c_master_write_slave(Sensor_Slave_Addr,data,size+1);//write addr+data
return err;
}
esp_err_t BMX055_IIC_Read_Bytes(uint8_t Sensor_Slave_Addr,uint8_t addr,uint8_t* data_re, size_t size)
{
uint8_t data[1];
data[0]=addr;
esp_err_t err = i2c_master_write_slave(Sensor_Slave_Addr,data,1);//write addr
if(err!=ESP_OK)return err;
err = i2c_master_read_slave(Sensor_Slave_Addr,data_re,size);//read data
return err;
}