|
21 | 21 | #include "esp_log.h" |
22 | 22 | #include "cryptoauthlib.h" |
23 | 23 | #include "esp_idf_version.h" |
| 24 | +#include "esp_rom_sys.h" |
24 | 25 |
|
25 | 26 | #if defined(CONFIG_ATCA_I2C_USE_LEGACY_DRIVER) |
26 | 27 | #include <driver/i2c.h> |
@@ -387,6 +388,7 @@ ATCA_STATUS hal_i2c_init(ATCAIface iface, ATCAIfaceCfg *cfg) |
387 | 388 | .device_address = i2c_hal_data[bus].device_address, |
388 | 389 | .scl_speed_hz = i2c_hal_data[bus].speed, |
389 | 390 | .scl_wait_us = 0, |
| 391 | + .flags.disable_ack_check = true, |
390 | 392 | }; |
391 | 393 |
|
392 | 394 | 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 |
503 | 505 | return ATCA_BAD_PARAM; |
504 | 506 | } |
505 | 507 |
|
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 | + |
507 | 527 | if (ESP_OK == rc) { |
508 | 528 | status = ATCA_SUCCESS; |
509 | 529 | } |
|
0 commit comments