Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7d9aa73

Browse files
committed
Retry the read if not successfull
1 parent 6423c99 commit 7d9aa73

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

hal/hal_cc2650_i2c_contiki.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,22 @@ ATCA_STATUS hal_i2c_send( ATCAIface iface, uint8_t* txdata, int txlength)
8181
ATCA_STATUS hal_i2c_receive( ATCAIface iface, uint8_t *rxdata, uint16_t *rxlength )
8282
{
8383
const ATCAIfaceCfg *cfg = atgetifacecfg(iface);
84+
int retries = cfg->rx_retries;
85+
bool success = false;
8486
board_i2c_select(DEFAULT_I2C_INTERFACE, cfg->atcai2c.slave_address >> 1);
85-
bool success = board_i2c_read(rxdata, *rxlength);
87+
while (retries-- > 0 && !success) {
88+
// Wait 5 ms between one read and the other
89+
atca_delay_ms(5);
90+
success = board_i2c_read(rxdata, *rxlength);
91+
}
8692
board_i2c_deselect();
87-
return success? ATCA_SUCCESS: ATCA_COMM_FAIL;
93+
if (!success) {
94+
return ATCA_COMM_FAIL;
95+
}
96+
if (atCheckCrc(rxdata) != ATCA_SUCCESS) {
97+
return ATCA_COMM_FAIL;
98+
}
99+
return ATCA_SUCCESS;
88100
}
89101

90102
ATCA_STATUS hal_i2c_wake( ATCAIface iface) {

hal/hal_cc2650_timer_contiki.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "atca_hal.h"
22
#include "rtimer.h"
3-
#include <stdio.h>
43

54
/** \defgroup hal_ Hardware abstraction layer (hal_)
65
*

0 commit comments

Comments
 (0)