From df1a2799437e79eae1f12d133413f9ba6709dcf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20=C5=BDaitl=C3=ADk?= Date: Sun, 9 Jan 2022 17:52:55 +0100 Subject: [PATCH] Fixed some mistakes made by copyying code. --- fw/Core/Inc/sgp4x.h | 2 +- fw/Core/Src/sgp4x.c | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/fw/Core/Inc/sgp4x.h b/fw/Core/Inc/sgp4x.h index b90b9de..acbaac7 100644 --- a/fw/Core/Inc/sgp4x.h +++ b/fw/Core/Inc/sgp4x.h @@ -20,7 +20,7 @@ */ #define SGP4X_I2C_ADDRESS 0x59 -#define SGP4X_MAX_MEAS_DURATION_MS 30 +#define SGP4X_MAX_MEAS_DURATION_MS 50 /* * Return values diff --git a/fw/Core/Src/sgp4x.c b/fw/Core/Src/sgp4x.c index 422dc18..3b9c588 100644 --- a/fw/Core/Src/sgp4x.c +++ b/fw/Core/Src/sgp4x.c @@ -30,8 +30,10 @@ int8_t sgp4x_measure_raw_signal (uint16_t * voc_ticks) int result; // start measurement - buffer[0] = SGP4X_MEASURE_RAW_SIGNAL >> 8; - buffer[1] = SGP4X_MEASURE_RAW_SIGNAL & 0x00ff; + //buffer[0] = SGP4X_MEASURE_RAW_SIGNAL >> 8; + //buffer[1] = SGP4X_MEASURE_RAW_SIGNAL & 0x00ff; + buffer[0] = 0x26; + buffer[1] = 0x0F; buffer[2] = 0x80; buffer[3] = 0x00; buffer[4] = 0xA2; @@ -105,9 +107,19 @@ int8_t sgp4x_measure_raw_signal_compensated (uint16_t * voc_ticks, uint16_t rela int8_t sgp4x_execute_self_test ( uint8_t * test_result) { uint8_t buffer[16]; + int8_t result; - scd4x_send_cmd(SGP4X_EXECUTE_SELF_TEST); - i2c_receive(SGP4X_I2C_ADDRESS << 1, buffer, 3); + result = sgp4x_send_cmd(SGP4X_EXECUTE_SELF_TEST); + if (result != I2C_OK) { + return SGP4X_ERROR; + } + + LL_mDelay(350); + + result = i2c_receive(SGP4X_I2C_ADDRESS << 1, buffer, 3); + if (result != I2C_OK) { + return SGP4X_ERROR; + } test_result = buffer[0]; uint8_t test_result_crc = buffer[2]; @@ -123,7 +135,10 @@ int8_t sgp4x_get_serial_number ( uint8_t serial[6]) { uint8_t buffer[16]; - scd4x_send_cmd(SGP4X_GET_SERIAL_NUMBER); + sgp4x_send_cmd(SGP4X_GET_SERIAL_NUMBER); + + LL_mDelay(5); + i2c_receive(SGP4X_I2C_ADDRESS << 1, buffer, 9); serial[0] = buffer[0];