diff --git a/sw/airborne/peripherals/hmc5843.c b/sw/airborne/peripherals/hmc5843.c index 3f5c63f9f3..71050c442c 100644 --- a/sw/airborne/peripherals/hmc5843.c +++ b/sw/airborne/peripherals/hmc5843.c @@ -46,11 +46,11 @@ void hmc5843_idle_task(void) { if (hmc5843.initialized && hmc5843.ready_for_read && (hmc5843.i2c_trans.status == I2CTransSuccess || hmc5843.i2c_trans.status == I2CTransFailed)) { if (i2c2.status == I2CIdle && i2c_idle(&i2c2)) { + hmc5843.ready_for_read = FALSE; hmc5843.i2c_trans.type = I2CTransRx; hmc5843.i2c_trans.len_r = 7; i2c_submit(&i2c2, &hmc5843.i2c_trans); hmc5843.reading = TRUE; - hmc5843.ready_for_read = FALSE; } } @@ -70,8 +70,10 @@ void hmc5843_periodic(void) if (!hmc5843.initialized) { send_config(); hmc5843.initialized = TRUE; - } else if (hmc5843.timeout++ > HMC5843_TIMEOUT) { + } else if (hmc5843.timeout++ > HMC5843_TIMEOUT && i2c2.status == I2CIdle && i2c_idle(&i2c2)){ +#ifdef USE_HMC59843_ARCH_RESET hmc5843_arch_reset(); +#endif hmc5843.i2c_trans.type = I2CTransRx; hmc5843.i2c_trans.len_r = 7; i2c_submit(&i2c2, &hmc5843.i2c_trans);