1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-26 01:35:41 +03:00

Import i2cUnstick from Inav for HAL, fixes MS5611 detection (#3972)

This commit is contained in:
sambas 2017-08-27 10:59:21 +03:00 committed by Martin Budden
parent 098f9eec60
commit d4d3711d8c

View file

@ -282,7 +282,6 @@ uint16_t i2cGetErrorCounter(void)
static void i2cUnstick(IO_t scl, IO_t sda) static void i2cUnstick(IO_t scl, IO_t sda)
{ {
int i; int i;
int timeout = 100;
IOHi(scl); IOHi(scl);
IOHi(sda); IOHi(sda);
@ -290,27 +289,31 @@ static void i2cUnstick(IO_t scl, IO_t sda)
IOConfigGPIO(scl, IOCFG_OUT_OD); IOConfigGPIO(scl, IOCFG_OUT_OD);
IOConfigGPIO(sda, IOCFG_OUT_OD); IOConfigGPIO(sda, IOCFG_OUT_OD);
for (i = 0; i < 8; i++) { // Analog Devices AN-686
// We need 9 clock pulses + STOP condition
for (i = 0; i < 9; i++) {
// Wait for any clock stretching to finish // Wait for any clock stretching to finish
int timeout = 100;
while (!IORead(scl) && timeout) { while (!IORead(scl) && timeout) {
delayMicroseconds(10); delayMicroseconds(5);
timeout--; timeout--;
} }
// Pull low // Pull low
IOLo(scl); // Set bus low IOLo(scl); // Set bus low
delayMicroseconds(10); delayMicroseconds(5);
IOHi(scl); // Set bus high IOHi(scl); // Set bus high
delayMicroseconds(10); delayMicroseconds(5);
} }
// Generate a start then stop condition // Generate a stop condition in case there was none
IOLo(sda); // Set bus data low IOLo(scl);
delayMicroseconds(10); delayMicroseconds(5);
IOLo(scl); // Set bus scl low IOLo(sda);
delayMicroseconds(10); delayMicroseconds(5);
IOHi(scl); // Set bus scl high IOHi(scl); // Set bus scl high
delayMicroseconds(10); delayMicroseconds(5);
IOHi(sda); // Set bus sda high IOHi(sda); // Set bus sda high
} }