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
File diff suppressed because it is too large
Load Diff
|
@ -155,7 +155,7 @@ void mpu6000SpiAccInit(void)
|
|||
bool mpu6000SpiDetect(void)
|
||||
{
|
||||
uint8_t in;
|
||||
|
||||
uint8_t attemptsRemaining = 5;
|
||||
if (mpuSpi6000InitDone) {
|
||||
return true;
|
||||
}
|
||||
|
@ -163,11 +163,18 @@ bool mpu6000SpiDetect(void)
|
|||
spiSetDivisor(MPU6000_SPI_INSTANCE, SPI_0_5625MHZ_CLOCK_DIVIDER);
|
||||
|
||||
mpu6000WriteRegister(MPU6000_PWR_MGMT_1, BIT_H_RESET);
|
||||
delay(150);
|
||||
|
||||
mpu6000ReadRegister(MPU6000_WHOAMI, &in, 1);
|
||||
if (in != MPU6000_WHO_AM_I_CONST)
|
||||
return false;
|
||||
do {
|
||||
delay(150);
|
||||
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue