drivers: sensor: tmp116: Check that a new value is available
Add a check to ensure that the conversion is complete before reading Signed-off-by: Guillaume Lager <g.lager@innoseis.com>
This commit is contained in:
parent
c40f0ec108
commit
42835a780a
2 changed files with 16 additions and 0 deletions
|
@ -77,6 +77,7 @@ static int tmp116_sample_fetch(const struct device *dev,
|
|||
{
|
||||
struct tmp116_data *drv_data = dev->data;
|
||||
uint16_t value;
|
||||
uint16_t cfg_reg = 0;
|
||||
int rc;
|
||||
|
||||
__ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL ||
|
||||
|
@ -85,6 +86,19 @@ static int tmp116_sample_fetch(const struct device *dev,
|
|||
/* clear sensor values */
|
||||
drv_data->sample = 0U;
|
||||
|
||||
/* Make sure that a data is available */
|
||||
rc = tmp116_reg_read(dev, TMP116_REG_CFGR, &cfg_reg);
|
||||
if (rc < 0) {
|
||||
LOG_ERR("%s, Failed to read from CFGR register",
|
||||
dev->name);
|
||||
return rc;
|
||||
}
|
||||
|
||||
if ((cfg_reg & TMP116_CFGR_DATA_READY) == 0) {
|
||||
LOG_DBG("%s: no data ready", dev->name);
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
/* Get the most recent temperature measurement */
|
||||
rc = tmp116_reg_read(dev, TMP116_REG_TEMP, &value);
|
||||
if (rc < 0) {
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#define TMP116_DEVICE_ID 0x1116
|
||||
#define TMP117_DEVICE_ID 0x0117
|
||||
|
||||
#define TMP116_CFGR_DATA_READY BIT(13)
|
||||
|
||||
struct tmp116_data {
|
||||
const struct device *i2c;
|
||||
uint16_t sample;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue