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:
parent
31e5644b56
commit
2d81c87927
1 changed files with 16 additions and 1 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue