mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
drivers/scd30: Add reset function to Sensirion scd30 sensor
This commit is contained in:
parent
d5b89a5795
commit
eb1064eef4
@ -167,6 +167,15 @@ int scd30_start_periodic_measurement(scd30_t *dev, uint16_t *interval,
|
|||||||
*/
|
*/
|
||||||
int8_t scd30_stop_measurements(const scd30_t *dev);
|
int8_t scd30_stop_measurements(const scd30_t *dev);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Soft reset sensor
|
||||||
|
*
|
||||||
|
* @param dev scd30 dev device
|
||||||
|
*
|
||||||
|
* @return SCD30_OK if soft reset successful
|
||||||
|
*/
|
||||||
|
int8_t scd30_reset(scd30_t *dev);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -44,6 +44,7 @@ extern "C" {
|
|||||||
1013.25 mBar */
|
1013.25 mBar */
|
||||||
|
|
||||||
#define SCD30_READ_WRITE_SLEEP_US (4 * US_PER_MS)
|
#define SCD30_READ_WRITE_SLEEP_US (4 * US_PER_MS)
|
||||||
|
#define SCD30_RESET_SLEEP_US (25 * US_PER_MS)
|
||||||
#define SCD30_DATA_RDY_TIMEOUT (1 * US_PER_SEC)
|
#define SCD30_DATA_RDY_TIMEOUT (1 * US_PER_SEC)
|
||||||
|
|
||||||
#define SCD30_MIN_INTERVAL 2
|
#define SCD30_MIN_INTERVAL 2
|
||||||
|
@ -45,11 +45,18 @@ static float _raw_val_to_float(const uint8_t *buffer);
|
|||||||
int8_t scd30_init(scd30_t *dev, const scd30_params_t *params)
|
int8_t scd30_init(scd30_t *dev, const scd30_params_t *params)
|
||||||
{
|
{
|
||||||
DEBUG("[scd30] init\n");
|
DEBUG("[scd30] init\n");
|
||||||
|
int ret = 0;
|
||||||
|
uint16_t version;
|
||||||
|
|
||||||
dev->params = *params;
|
dev->params = *params;
|
||||||
|
|
||||||
int ret = 0;
|
/* Soft reset sensor */
|
||||||
|
ret = scd30_reset(dev);
|
||||||
|
if (ret < 0) {
|
||||||
|
DEBUG("[scd30] Failed to reset sensor in init\n");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
uint16_t version;
|
|
||||||
ret = scd30_get_param(dev, SCD30_VERSION, &version);
|
ret = scd30_get_param(dev, SCD30_VERSION, &version);
|
||||||
DEBUG("[scd30] --- Version 0x%02x%02x\n", (version >> 8), version);
|
DEBUG("[scd30] --- Version 0x%02x%02x\n", (version >> 8), version);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
@ -237,6 +244,23 @@ int8_t scd30_stop_measurements(const scd30_t *dev)
|
|||||||
return SCD30_OK;
|
return SCD30_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int8_t scd30_reset(scd30_t *dev)
|
||||||
|
{
|
||||||
|
const uint16_t cmd = htons(SCD30_SOFT_RESET);
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
i2c_acquire(SCD30_I2C);
|
||||||
|
ret = i2c_write_bytes(SCD30_I2C, SCD30_I2C_ADDRESS, &cmd, 2, 0);
|
||||||
|
i2c_release(SCD30_I2C);
|
||||||
|
|
||||||
|
if (ret != 0) {
|
||||||
|
DEBUG("[scd30]: Error resetting sensor.\n");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
xtimer_usleep(SCD30_RESET_SLEEP_US);
|
||||||
|
return SCD30_OK;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* intern function to read data
|
* intern function to read data
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user