@@ -668,7 +668,7 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
668
668
ret = HAL_I2C_Master_Sequential_Receive_IT (handle , address , (uint8_t * ) data , length , obj_s -> XferOperation );
669
669
670
670
if (ret == HAL_OK ) {
671
- timeout = BYTE_TIMEOUT_US * length ;
671
+ timeout = BYTE_TIMEOUT_US * ( length + 1 ) ;
672
672
/* transfer started : wait completion or timeout */
673
673
while (!(obj_s -> event & I2C_EVENT_ALL ) && (-- timeout != 0 )) {
674
674
wait_us (1 );
@@ -724,7 +724,7 @@ int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
724
724
ret = HAL_I2C_Master_Sequential_Transmit_IT (handle , address , (uint8_t * ) data , length , obj_s -> XferOperation );
725
725
726
726
if (ret == HAL_OK ) {
727
- timeout = BYTE_TIMEOUT_US * length ;
727
+ timeout = BYTE_TIMEOUT_US * ( length + 1 ) ;
728
728
/* transfer started : wait completion or timeout */
729
729
while (!(obj_s -> event & I2C_EVENT_ALL ) && (-- timeout != 0 )) {
730
730
wait_us (1 );
@@ -903,7 +903,7 @@ int i2c_slave_read(i2c_t *obj, char *data, int length) {
903
903
ret = HAL_I2C_Slave_Sequential_Receive_IT (handle , (uint8_t * ) data , length , I2C_NEXT_FRAME );
904
904
905
905
if (ret == HAL_OK ) {
906
- timeout = BYTE_TIMEOUT_US * length ;
906
+ timeout = BYTE_TIMEOUT_US * ( length + 1 ) ;
907
907
while (obj_s -> pending_slave_rx_maxter_tx && (-- timeout != 0 )) {
908
908
wait_us (1 );
909
909
}
@@ -928,7 +928,7 @@ int i2c_slave_write(i2c_t *obj, const char *data, int length) {
928
928
ret = HAL_I2C_Slave_Sequential_Transmit_IT (handle , (uint8_t * ) data , length , I2C_NEXT_FRAME );
929
929
930
930
if (ret == HAL_OK ) {
931
- timeout = BYTE_TIMEOUT_US * length ;
931
+ timeout = BYTE_TIMEOUT_US * ( length + 1 ) ;
932
932
while (obj_s -> pending_slave_tx_master_rx && (-- timeout != 0 )) {
933
933
wait_us (1 );
934
934
}
0 commit comments