Browse Source

HAL_ChibiOS: I2C timeout should be send+recv, not MAX(send,recv)

MAX() is right for SPI, not I2C
mission-4.1.18
Andrew Tridgell 6 years ago
parent
commit
aeb58cede1
  1. 2
      libraries/AP_HAL_ChibiOS/I2CDevice.cpp

2
libraries/AP_HAL_ChibiOS/I2CDevice.cpp

@ -248,7 +248,7 @@ bool I2CDevice::_transfer(const uint8_t *send, uint32_t send_len, @@ -248,7 +248,7 @@ bool I2CDevice::_transfer(const uint8_t *send, uint32_t send_len,
for(uint8_t i=0 ; i <= _retries; i++) {
int ret;
// calculate a timeout as twice the expected transfer time, and set as min of 4ms
uint32_t timeout_ms = 1+2*(((8*1000000UL/bus.busclock)*MAX(send_len, recv_len))/1000);
uint32_t timeout_ms = 1+2*(((8*1000000UL/bus.busclock)*(send_len+recv_len))/1000);
timeout_ms = MAX(timeout_ms, _timeout_ms);
// we get the lock and start the bus inside the retry loop to

Loading…
Cancel
Save