mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 00:05:33 +03:00
CC3D - Attempt MPU6000 SPI detection multiple times.
On two CC3D boards tested prior to this fix the mpu6000ReadRegister call
for the MPU6000_WHOAMI would sometimes fail on code boot and sometimes
on warm boot, randomly.
The reset added in 4db1d58aaf
helps but
didn't fix detection for good.
This commit is contained in:
parent
9a9c789c69
commit
e454e44b1e
2 changed files with 5006 additions and 4999 deletions
File diff suppressed because it is too large
Load diff
|
@ -155,7 +155,7 @@ void mpu6000SpiAccInit(void)
|
||||||
bool mpu6000SpiDetect(void)
|
bool mpu6000SpiDetect(void)
|
||||||
{
|
{
|
||||||
uint8_t in;
|
uint8_t in;
|
||||||
|
uint8_t attemptsRemaining = 5;
|
||||||
if (mpuSpi6000InitDone) {
|
if (mpuSpi6000InitDone) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -163,11 +163,18 @@ bool mpu6000SpiDetect(void)
|
||||||
spiSetDivisor(MPU6000_SPI_INSTANCE, SPI_0_5625MHZ_CLOCK_DIVIDER);
|
spiSetDivisor(MPU6000_SPI_INSTANCE, SPI_0_5625MHZ_CLOCK_DIVIDER);
|
||||||
|
|
||||||
mpu6000WriteRegister(MPU6000_PWR_MGMT_1, BIT_H_RESET);
|
mpu6000WriteRegister(MPU6000_PWR_MGMT_1, BIT_H_RESET);
|
||||||
delay(150);
|
|
||||||
|
|
||||||
mpu6000ReadRegister(MPU6000_WHOAMI, &in, 1);
|
do {
|
||||||
if (in != MPU6000_WHO_AM_I_CONST)
|
delay(150);
|
||||||
return false;
|
|
||||||
|
mpu6000ReadRegister(MPU6000_WHOAMI, &in, 1);
|
||||||
|
if (in == MPU6000_WHO_AM_I_CONST) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!attemptsRemaining) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} while (attemptsRemaining--);
|
||||||
|
|
||||||
|
|
||||||
mpu6000ReadRegister(MPU6000_PRODUCT_ID, &in, 1);
|
mpu6000ReadRegister(MPU6000_PRODUCT_ID, &in, 1);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue