Multiplied the temperature by 10 to get better accuracy. NACK is making problems again after I2C transmit.
This commit is contained in:
parent
42144d74f2
commit
00811846d5
@ -88,7 +88,7 @@ int8_t scd4x_read_measurement(int * co2, int *temperature, int *relative_humidit
|
|||||||
uint32_t co2_ticks = (buffer[0] << 8) + buffer[1];
|
uint32_t co2_ticks = (buffer[0] << 8) + buffer[1];
|
||||||
uint32_t t_ticks = (buffer[3] << 8) + buffer[4];
|
uint32_t t_ticks = (buffer[3] << 8) + buffer[4];
|
||||||
uint32_t rh_ticks = (buffer[6] << 8) + buffer[7];
|
uint32_t rh_ticks = (buffer[6] << 8) + buffer[7];
|
||||||
int t_degC = -45 + 175 * t_ticks / 65535;
|
int t_degC = 10*(-45 + 175 * t_ticks / 65535);
|
||||||
int rh_pRH = 100 * rh_ticks / 65535;
|
int rh_pRH = 100 * rh_ticks / 65535;
|
||||||
if (rh_pRH > 100) {
|
if (rh_pRH > 100) {
|
||||||
rh_pRH = 100;
|
rh_pRH = 100;
|
||||||
|
@ -25,9 +25,11 @@ int8_t sht4x_measure(int *temperature, int *relative_humidity)
|
|||||||
// start measurement
|
// start measurement
|
||||||
buffer[0] = START_MEAS_HIGH_PRECISION;
|
buffer[0] = START_MEAS_HIGH_PRECISION;
|
||||||
result = i2c_transmit(SHT4X_I2C_ADDRESS<<1, buffer, 1);
|
result = i2c_transmit(SHT4X_I2C_ADDRESS<<1, buffer, 1);
|
||||||
|
// TODO: Proc to vraci NACK? Vyresit.
|
||||||
|
/*
|
||||||
if (result != I2C_OK) {
|
if (result != I2C_OK) {
|
||||||
return SHT4X_ERROR;
|
return SHT4X_ERROR;
|
||||||
}
|
}*/
|
||||||
LL_mDelay(100); // 10 ms should be enough
|
LL_mDelay(100); // 10 ms should be enough
|
||||||
// read out
|
// read out
|
||||||
result = i2c_receive(SHT4X_I2C_ADDRESS<<1, buffer, 6);
|
result = i2c_receive(SHT4X_I2C_ADDRESS<<1, buffer, 6);
|
||||||
@ -38,7 +40,7 @@ int8_t sht4x_measure(int *temperature, int *relative_humidity)
|
|||||||
// Convert to T and RH; taken directly from pseudocode in SHT4x datasheet, page 3
|
// Convert to T and RH; taken directly from pseudocode in SHT4x datasheet, page 3
|
||||||
uint32_t t_ticks = (buffer[0] << 8) + buffer[1];
|
uint32_t t_ticks = (buffer[0] << 8) + buffer[1];
|
||||||
uint32_t rh_ticks = (buffer[3] << 8) + buffer[4];
|
uint32_t rh_ticks = (buffer[3] << 8) + buffer[4];
|
||||||
int t_degC = -45 + 175 * t_ticks / 65535;
|
int t_degC = 10*(-45 + 175 * t_ticks / 65535);
|
||||||
int rh_pRH = -6 + 125 * rh_ticks / 65535;
|
int rh_pRH = -6 + 125 * rh_ticks / 65535;
|
||||||
if (rh_pRH > 100) {
|
if (rh_pRH > 100) {
|
||||||
rh_pRH = 100;
|
rh_pRH = 100;
|
||||||
|
Loading…
Reference in New Issue
Block a user