Add some delay between consecutive access to the sensors to prevent I2C busy conditions.
authorNathael Pajani <nathael.pajani@ed3l.fr>
Tue, 13 Sep 2016 23:24:05 +0000 (01:24 +0200)
committerNathael Pajani <nathael.pajani@ed3l.fr>
Fri, 10 Feb 2023 18:02:59 +0000 (19:02 +0100)
extdrv/tsl256x_light_sensor.c
extdrv/veml6070_uv_sensor.c

index 967613b..a460078 100644 (file)
@@ -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;
index abb6337..21d56f3 100644 (file)
 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;
     }