mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 16:25:31 +03:00
Import i2cUnstick from Inav for HAL, fixes MS5611 detection (#3972)
This commit is contained in:
parent
098f9eec60
commit
d4d3711d8c
1 changed files with 14 additions and 11 deletions
|
@ -282,7 +282,6 @@ uint16_t i2cGetErrorCounter(void)
|
|||
static void i2cUnstick(IO_t scl, IO_t sda)
|
||||
{
|
||||
int i;
|
||||
int timeout = 100;
|
||||
|
||||
IOHi(scl);
|
||||
IOHi(sda);
|
||||
|
@ -290,27 +289,31 @@ static void i2cUnstick(IO_t scl, IO_t sda)
|
|||
IOConfigGPIO(scl, 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
|
||||
int timeout = 100;
|
||||
while (!IORead(scl) && timeout) {
|
||||
delayMicroseconds(10);
|
||||
delayMicroseconds(5);
|
||||
timeout--;
|
||||
}
|
||||
|
||||
// Pull low
|
||||
IOLo(scl); // Set bus low
|
||||
delayMicroseconds(10);
|
||||
delayMicroseconds(5);
|
||||
IOHi(scl); // Set bus high
|
||||
delayMicroseconds(10);
|
||||
delayMicroseconds(5);
|
||||
}
|
||||
|
||||
// Generate a start then stop condition
|
||||
IOLo(sda); // Set bus data low
|
||||
delayMicroseconds(10);
|
||||
IOLo(scl); // Set bus scl low
|
||||
delayMicroseconds(10);
|
||||
// Generate a stop condition in case there was none
|
||||
IOLo(scl);
|
||||
delayMicroseconds(5);
|
||||
IOLo(sda);
|
||||
delayMicroseconds(5);
|
||||
|
||||
IOHi(scl); // Set bus scl high
|
||||
delayMicroseconds(10);
|
||||
delayMicroseconds(5);
|
||||
IOHi(sda); // Set bus sda high
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue