Master sends a stream (i can see it and I2C decode by oscilloscope) but the slave seems doesn't receive nothing. For double check, i tried inputs and also i tried to start a I2C master communication on the slave one, only for check the hardware, and all seems work and the pins are correctly configured. The micros are near (the distance is about 10cm). I don't use external pullups, but i enable pullups in both the microcontrollers. I also tried to place an external pullup but nothing seems change. Another thing, the device was able to communicate until a pair of days ago. In last, the slave address is the same on both the devices, it's a 7 bit address as I2C need, and i use i2c_master_write_read_device method on the master and i2c_slave_read_buffer and i2c_slave_write_buffer routines on the slave.
About the software, i took ispiration from here: https://esp32tutorials.com/esp32-i2c-co ... l-esp-idf/.
From the oscilloscope seems that the slave doesn't send acknowledge, but in reality the slave doesn't receive anything.
The slave initialization is this:
Code: Select all
memset(&I2CCfg, 0, sizeof(i2c_config_t));
I2CCfg.sda_io_num = I2CSLAVE_SDA;
I2CCfg.sda_pullup_en = GPIO_PULLUP_ENABLE;
I2CCfg.scl_io_num = I2CSLAVE_SCL;
I2CCfg.scl_pullup_en = GPIO_PULLUP_ENABLE;
I2CCfg.mode = I2C_MODE_SLAVE;
I2CCfg.slave.addr_10bit_en = 0;
I2CCfg.slave.slave_addr = OIDA_SLAVE_ADDRESS;
I2CCfg.clk_flags = 0;
esp_err_t res = i2c_param_config(channelI2C, &I2CCfg);
if (res != ESP_OK) {
return res;
}
res = i2c_driver_install(channelI2C, I2C_MODE_SLAVE, I2C_SLAVE_RX_BUF_LEN, I2C_SLAVE_TX_BUF_LEN, 0);
if (res != ESP_OK) {
ESP_LOGE(TAG, "Error i2c_driver_install");
}
Code: Select all
LoadBufTx(BufTx); // here i load my tx buffer
size_t rxLen = i2c_slave_read_buffer(channelI2C, BufRx, I2C_SLAVE_RX_BUF_LEN, pdMS_TO_TICKS(1000));
i2c_reset_rx_fifo(channelI2C);
if (rxLen == 12) {
uint16_t respCRC = crc16(0xFFFF, BufRx, 10);
uint16_t rxCRC = BufRx[10] | (BufRx[11] << 8);
if (respCRC != rxCRC) {
ESP_LOGE(TAG, "CRC Error: %04X - %04X", respCRC, rxCRC);
}
else {
ESP_LOGI(TAG, "CRC OK: %04X - %04X", respCRC, rxCRC);
GetFromBufRx(BufRx); // here i want load my rx buffer
i2c_slave_write_buffer(channelI2C, BufTx, 90, pdMS_TO_TICKS(2000));
}
}
else {
ESP_LOGI(TAG, "Char in buf : %d -> RESET", rxLen);
}
Thanks for all that will help me!