Skip to content

Commit 836aa3e

Browse files
AdityaHPatwardhannileshkale123
authored andcommitted
I2C communication not working correctly
1 parent ebc340c commit 836aa3e

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

cryptoauthlib/third_party/hal/esp32/hal_esp32_i2c.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "esp_log.h"
2222
#include "cryptoauthlib.h"
2323
#include "esp_idf_version.h"
24+
#include "esp_rom_sys.h"
2425

2526
#if defined(CONFIG_ATCA_I2C_USE_LEGACY_DRIVER)
2627
#include <driver/i2c.h>
@@ -387,6 +388,7 @@ ATCA_STATUS hal_i2c_init(ATCAIface iface, ATCAIfaceCfg *cfg)
387388
.device_address = i2c_hal_data[bus].device_address,
388389
.scl_speed_hz = i2c_hal_data[bus].speed,
389390
.scl_wait_us = 0,
391+
.flags.disable_ack_check = true,
390392
};
391393

392394
rc = i2c_master_bus_add_device(i2c_hal_data[bus].bus_handle, &dev_cfg, &i2c_hal_data[bus].dev_handle);
@@ -503,7 +505,25 @@ ATCA_STATUS hal_i2c_receive(ATCAIface iface, uint8_t address, uint8_t *rxdata, u
503505
return ATCA_BAD_PARAM;
504506
}
505507

506-
rc = i2c_master_receive(hal_data->dev_handle, rxdata, *rxlength, 200);
508+
int retries = 3;
509+
510+
while (retries--) {
511+
rc = i2c_master_receive(hal_data->dev_handle, rxdata, *rxlength, 200);
512+
513+
// If we read 0xFF from the I2C device, typically it means that device is currently busy in
514+
// some operation. We will retry with a small delay.
515+
// This behaviour is introduced as the delay before a receive command doesnt seem to be handled by the CryptoAuthlib.
516+
517+
if (*rxlength == 1 && rxdata[0] == 0xFF) {
518+
// Device is busy/not ready, retry or continue
519+
// This is normal behavior, not an error
520+
esp_rom_delay_us(25000);
521+
continue;
522+
} else {
523+
break;
524+
}
525+
}
526+
507527
if (ESP_OK == rc) {
508528
status = ATCA_SUCCESS;
509529
}

idf_component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: "3.7.7~4"
1+
version: "3.7.7~5"
22
description: "esp-cryptoauthlib: The port of Microchip CryptoAuthentication Library for ESP-IDF"
33
url: https://github.com/espressif/esp-cryptoauthlib
44
dependencies:

0 commit comments

Comments
 (0)