Fixed UART interrupt disable/enable during sensor readout

This commit is contained in:
Your Name 2021-11-13 21:47:57 +01:00
parent 62cfa66b80
commit 235ca259f1
2 changed files with 10 additions and 5 deletions

View File

@ -65,7 +65,8 @@ int8_t scd4x_read_measurement(uint16_t * co2, int16_t *temperature, uint16_t *re
return SCD4X_ERROR;
}*/
// disable interrupts to prevent MODBUS/I2C conflict
uart_disable_interrupts();
// start measurement
buffer[0] = SCD4X_READ_MEASUREMENT >> 8;
buffer[1] = SCD4X_READ_MEASUREMENT & 0x00ff;
@ -75,11 +76,12 @@ int8_t scd4x_read_measurement(uint16_t * co2, int16_t *temperature, uint16_t *re
/*if (result != I2C_OK) {
return SCD4X_ERROR;
}*/
uart_disable_interrupts();
LL_mDelay(1); // 10 ms should be enough
uart_enable_interrupts();
LL_mDelay(1); // 10 ms should be enough
uart_disable_interrupts();
// read out
result = i2c_receive(SCD4X_I2C_ADDRESS<<1, buffer, 9);
uart_enable_interrupts();
if (result != I2C_OK)
{
return SCD4X_ERROR;

View File

@ -23,6 +23,8 @@ int8_t sht4x_measure(int16_t *temperature, uint16_t *relative_humidity)
uint8_t buffer[32];
int result;
// disable interrupts to prevent modbus/i2c conflict
uart_disable_interrupts();
// start measurement
buffer[0] = SHT4X_START_MEAS_HIGH_PRECISION;
result = i2c_transmit(SHT4X_I2C_ADDRESS<<1, buffer, 1);
@ -31,11 +33,12 @@ int8_t sht4x_measure(int16_t *temperature, uint16_t *relative_humidity)
if (result != I2C_OK) {
return SHT4X_ERROR;
}*/
uart_disable_interrupts();
LL_mDelay(10); // 10 ms should be enough
uart_enable_interrupts();
LL_mDelay(10); // 10 ms should be enough
uart_disable_interrupts();
// read out
result = i2c_receive(SHT4X_I2C_ADDRESS<<1, buffer, 6);
uart_enable_interrupts();
if (result != I2C_OK) {
return SHT4X_ERROR;
}