Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/i2c Read the datasheet more closely and put in some ...



details:   https://anonhg.NetBSD.org/src/rev/939e271db41b
branches:  trunk
changeset: 372407:939e271db41b
user:      brad <brad%NetBSD.org@localhost>
date:      Tue Nov 22 19:40:31 2022 +0000

description:
Read the datasheet more closely and put in some delays.  The chip will
just return junk if the wait is not long enough to allow a measurement
to start.

diffstat:

 sys/dev/i2c/bmx280.c |  16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)

diffs (58 lines):

diff -r df5a2553fc9b -r 939e271db41b sys/dev/i2c/bmx280.c
--- a/sys/dev/i2c/bmx280.c      Tue Nov 22 17:35:45 2022 +0000
+++ b/sys/dev/i2c/bmx280.c      Tue Nov 22 19:40:31 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bmx280.c,v 1.1 2022/11/21 21:24:01 brad Exp $  */
+/*     $NetBSD: bmx280.c,v 1.2 2022/11/22 19:40:31 brad Exp $  */
 
 /*
  * Copyright (c) 2022 Brad Spencer <brad%anduin.eldar.org@localhost>
@@ -17,7 +17,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bmx280.c,v 1.1 2022/11/21 21:24:01 brad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bmx280.c,v 1.2 2022/11/22 19:40:31 brad Exp $");
 
 /*
   Driver for the Bosch BMP280/BME280 temperature, humidity (sometimes) and
@@ -501,7 +501,7 @@
                    error);
        }
 
-       delay(100);
+       delay(30000);
 
        reg = BMX280_REGISTER_ID;
        error = bmx280_read_register(sc->sc_tag, sc->sc_addr, &reg, &chip_id, 1);
@@ -510,7 +510,7 @@
                    error);
        }
 
-       delay(100);
+       delay(1000);
 
        DPRINTF(sc, 2, ("%s: read ID value: %02x\n",
            device_xname(sc->sc_dev), chip_id));
@@ -718,6 +718,12 @@
                error = EINVAL;
        }
 
+       /* Hmm... this delay is not documented well..  mostly just a guess...
+        * If it is too short, you will get junk returned as it is possible to try
+        * to ask for the data before the chip has even started... it seems...
+        */
+       delay(35000);
+
        return error;
 }
 
@@ -731,7 +737,7 @@
 
        reg = BMX280_REGISTER_STATUS;
        do {
-               delay(10);
+               delay(1000);
                ierror = bmx280_read_register(sc->sc_tag, sc->sc_addr, &reg, &running, 1);
                if (ierror) {
                        DPRINTF(sc, 2, ("%s: Refresh failed to read back status: %d\n",



Home | Main Index | Thread Index | Old Index