diff --git a/sw/airborne/peripherals/ms5611_i2c.c b/sw/airborne/peripherals/ms5611_i2c.c index c65cb19ddd..1ec14b4611 100644 --- a/sw/airborne/peripherals/ms5611_i2c.c +++ b/sw/airborne/peripherals/ms5611_i2c.c @@ -129,10 +129,16 @@ void ms5611_i2c_event(struct Ms5611_I2c *ms) { ms->data.d1 = (ms->i2c_trans.buf[0] << 16) | (ms->i2c_trans.buf[1] << 8) | ms->i2c_trans.buf[2]; - /* start D2 conversion */ - ms->i2c_trans.buf[0] = MS5611_START_CONV_D2; - i2c_transmit(ms->i2c_p, &(ms->i2c_trans), ms->i2c_trans.slave_addr, 1); - ms->status = MS5611_STATUS_CONV_D2; + if (ms->data.d1 == 0) { + /* if value is zero, it was read to soon and is invalid, back to idle */ + ms->status = MS5611_STATUS_IDLE; + } + else { + /* start D2 conversion */ + ms->i2c_trans.buf[0] = MS5611_START_CONV_D2; + i2c_transmit(ms->i2c_p, &(ms->i2c_trans), ms->i2c_trans.slave_addr, 1); + ms->status = MS5611_STATUS_CONV_D2; + } break; case MS5611_STATUS_ADC_D2: @@ -140,10 +146,16 @@ void ms5611_i2c_event(struct Ms5611_I2c *ms) { ms->data.d2 = (ms->i2c_trans.buf[0] << 16) | (ms->i2c_trans.buf[1] << 8) | ms->i2c_trans.buf[2]; - /* calculate temp and pressure from measurements */ - ms5611_calc(&(ms->data)); - ms->status = MS5611_STATUS_IDLE; - ms->data_available = TRUE; + if (ms->data.d2 == 0) { + /* if value is zero, it was read to soon and is invalid, back to idle */ + ms->status = MS5611_STATUS_IDLE; + } + else { + /* calculate temp and pressure from measurements */ + ms5611_calc(&(ms->data)); + ms->status = MS5611_STATUS_IDLE; + ms->data_available = TRUE; + } break; default: diff --git a/sw/airborne/peripherals/ms5611_spi.c b/sw/airborne/peripherals/ms5611_spi.c index 5b7e01ab78..d8e9293185 100644 --- a/sw/airborne/peripherals/ms5611_spi.c +++ b/sw/airborne/peripherals/ms5611_spi.c @@ -143,10 +143,16 @@ void ms5611_spi_event(struct Ms5611_Spi *ms) { ms->data.d1 = (ms->rx_buf[1] << 16) | (ms->rx_buf[2] << 8) | ms->rx_buf[3]; - /* start D2 conversion */ - ms->tx_buf[0] = MS5611_START_CONV_D2; - spi_submit(ms->spi_p, &(ms->spi_trans)); - ms->status = MS5611_STATUS_CONV_D2; + if (ms->data.d1 == 0) { + /* if value is zero, it was read to soon and is invalid, back to idle */ + ms->status = MS5611_STATUS_IDLE; + } + else { + /* start D2 conversion */ + ms->tx_buf[0] = MS5611_START_CONV_D2; + spi_submit(ms->spi_p, &(ms->spi_trans)); + ms->status = MS5611_STATUS_CONV_D2; + } break; case MS5611_STATUS_ADC_D2: @@ -154,10 +160,16 @@ void ms5611_spi_event(struct Ms5611_Spi *ms) { ms->data.d2 = (ms->rx_buf[1] << 16) | (ms->rx_buf[2] << 8) | ms->rx_buf[3]; - /* calculate temp and pressure from measurements */ - ms5611_calc(&(ms->data)); - ms->status = MS5611_STATUS_IDLE; - ms->data_available = TRUE; + if (ms->data.d2 == 0) { + /* if value is zero, it was read to soon and is invalid, back to idle */ + ms->status = MS5611_STATUS_IDLE; + } + else { + /* calculate temp and pressure from measurements */ + ms5611_calc(&(ms->data)); + ms->status = MS5611_STATUS_IDLE; + ms->data_available = TRUE; + } break; default: