1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-12 19:10:32 +03:00

Improve 426xx detection time using soft reset (#14414)

* Improve 426xx detection using softreset

* Update src/main/drivers/accgyro/accgyro_spi_icm426xx.c

Co-authored-by: Petr Ledvina <ledvinap@gmail.com>

* Update src/main/drivers/accgyro/accgyro_spi_icm426xx.c

Co-authored-by: Petr Ledvina <ledvinap@gmail.com>

---------

Co-authored-by: Petr Ledvina <ledvinap@gmail.com>
This commit is contained in:
Mark Haslinghuis 2025-05-30 21:47:07 +02:00 committed by GitHub
parent 31e5644b56
commit 2d81c87927
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -60,6 +60,10 @@
#define ICM426XX_CLKIN_FREQ 32000
// Soft Reset
#define ICM426XX_RA_DEVICE_CONFIG 0x17
#define DEVICE_CONFIG_SOFT_RESET_BIT (1 << 0) // Soft reset bit
#define ICM426XX_RA_REG_BANK_SEL 0x76
#define ICM426XX_BANK_SELECT0 0x00
#define ICM426XX_BANK_SELECT1 0x01
@ -249,8 +253,19 @@ static void icm426xxEnableExternalClock(const extDevice_t *dev)
}
#endif
static void icm426xxSoftReset(const extDevice_t *dev)
{
setUserBank(dev, ICM426XX_BANK_SELECT0);
spiWriteReg(dev, ICM426XX_RA_DEVICE_CONFIG, DEVICE_CONFIG_SOFT_RESET_BIT);
delay(1);
}
uint8_t icm426xxSpiDetect(const extDevice_t *dev)
{
delay(1); // power-on time
icm426xxSoftReset(dev);
spiWriteReg(dev, ICM426XX_RA_PWR_MGMT0, 0x00);
#if defined(USE_GYRO_CLKIN)
@ -260,7 +275,7 @@ uint8_t icm426xxSpiDetect(const extDevice_t *dev)
uint8_t icmDetected = MPU_NONE;
uint8_t attemptsRemaining = 20;
do {
delay(150);
delay(1);
const uint8_t whoAmI = spiReadRegMsk(dev, MPU_RA_WHO_AM_I);
switch (whoAmI) {
case ICM42605_WHO_AM_I_CONST: