From 45f64807d150033bb5c54df6ff052eb2184da221 Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Wed, 14 Sep 2016 01:24:05 +0200 Subject: [PATCH] Add some delay between consecutive access to the sensors to prevent I2C busy conditions. --- extdrv/tsl256x_light_sensor.c | 1 + extdrv/veml6070_uv_sensor.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/extdrv/tsl256x_light_sensor.c b/extdrv/tsl256x_light_sensor.c index 967613b..a460078 100644 --- a/extdrv/tsl256x_light_sensor.c +++ b/extdrv/tsl256x_light_sensor.c @@ -159,6 +159,7 @@ int tsl256x_configure(struct tsl256x_sensor_config* conf) if (tsl256x_probe_sensor(conf) != 1) { return -ENODEV; } + msleep(1); ret = i2c_write(conf->bus_num, cmd_buf, CONF_BUF_SIZE, NULL); if (ret != CONF_BUF_SIZE) { conf->probe_ok = 0; diff --git a/extdrv/veml6070_uv_sensor.c b/extdrv/veml6070_uv_sensor.c index abb6337..21d56f3 100644 --- a/extdrv/veml6070_uv_sensor.c +++ b/extdrv/veml6070_uv_sensor.c @@ -34,10 +34,11 @@ int veml6070_probe_sensor(struct veml6070_sensor_config* conf) { char cmd_buf = (conf->addr | I2C_READ_BIT); + uint8_t dropped; /* Did we already probe the sensor ? */ if (conf->probe_ok != 1) { - conf->probe_ok = i2c_read(conf->bus_num, &cmd_buf, 1, NULL, NULL, 0); + conf->probe_ok = i2c_read(conf->bus_num, &cmd_buf, 1, NULL, &dropped, 1); } return conf->probe_ok; } @@ -62,9 +63,12 @@ int veml6070_sensor_read(struct veml6070_sensor_config* conf, uint16_t* uv_raw) char cmd_buf =0; uint8_t data = 0; - if (veml6070_probe_sensor(conf) != 1) { - return -ENODEV; - } + if (conf->probe_ok != 1) { + if (veml6070_probe_sensor(conf) != 1) { + return -ENODEV; + } + msleep(1); + } if (uv_raw == NULL) { return -EINVAL; } -- 2.43.0