52
52
_BME680_REG_SOFTRESET = const (0xE0 )
53
53
_BME680_REG_CTRL_GAS = const (0x71 )
54
54
_BME680_REG_CTRL_HUM = const (0x72 )
55
- _BME280_REG_STATUS = const (0xF3 )
55
+ _BME680_REG_STATUS = const (0x73 )
56
56
_BME680_REG_CTRL_MEAS = const (0x74 )
57
57
_BME680_REG_CONFIG = const (0x75 )
58
58
59
- _BME680_REG_STATUS = const (0x1D )
59
+ _BME680_REG_MEAS_STATUS = const (0x1D )
60
60
_BME680_REG_PDATA = const (0x1F )
61
61
_BME680_REG_TDATA = const (0x22 )
62
62
_BME680_REG_HDATA = const (0x25 )
@@ -266,7 +266,7 @@ def _perform_reading(self):
266
266
self ._write (_BME680_REG_CTRL_MEAS , [ctrl ])
267
267
new_data = False
268
268
while not new_data :
269
- data = self ._read (_BME680_REG_STATUS , 15 )
269
+ data = self ._read (_BME680_REG_MEAS_STATUS , 15 )
270
270
new_data = data [0 ] & 0x80 != 0
271
271
time .sleep (0.005 )
272
272
self ._last_reading = time .monotonic ()
@@ -368,6 +368,11 @@ def __init__(self, spi, cs, baudrate=100000, debug=False, *, refresh_rate=10):
368
368
super ().__init__ (refresh_rate = refresh_rate )
369
369
370
370
def _read (self , register , length ):
371
+ if register != _BME680_REG_STATUS :
372
+ #_BME680_REG_STATUS exists in both SPI memory pages
373
+ #For all other registers, we must set the correct memory page
374
+ self ._set_spi_mem_page (register )
375
+
371
376
register = (register | 0x80 ) & 0xFF # Read single, bit 7 high.
372
377
with self ._spi as spi :
373
378
spi .write (bytearray ([register ])) #pylint: disable=no-member
@@ -378,6 +383,10 @@ def _read(self, register, length):
378
383
return result
379
384
380
385
def _write (self , register , values ):
386
+ if register != _BME680_REG_STATUS :
387
+ #_BME680_REG_STATUS exists in both SPI memory pages
388
+ #For all other registers, we must set the correct memory page
389
+ self ._set_spi_mem_page (register )
381
390
register &= 0x7F # Write, bit 7 low.
382
391
with self ._spi as spi :
383
392
buffer = bytearray (2 * len (values ))
@@ -387,3 +396,9 @@ def _write(self, register, values):
387
396
spi .write (buffer ) #pylint: disable=no-member
388
397
if self ._debug :
389
398
print ("\t $%02X <= %s" % (values [0 ], [hex (i ) for i in values [1 :]]))
399
+
400
+ def _set_spi_mem_page (self , register ):
401
+ spi_mem_page = 0x00
402
+ if register < 0x80 :
403
+ spi_mem_page = 0x10
404
+ self ._write (_BME680_REG_STATUS , spi_mem_page )
0 commit comments