@@ -67,11 +67,17 @@ def reset_device_registers(self):
6767 continue
6868 bh .write_register (register , value , byte_count = 2 )
6969
70- def configure (self , config : Ads1x1xConfig ):
70+ def configure (self , config : Ads1x1xConfig ) -> bool :
71+ # order is important!
7172 with BurstHandler (i2c_bus = self ._i2c_bus , i2c_adr = self ._i2c_adr ) as bh :
72- bh .write_register (0x01 , config .as_uint16 (), byte_count = 2 )
73+ # 1) reset to a defined state and disable alerting
74+ bh .write_register (0x01 , 0x0583 , byte_count = 2 )
75+ # 2) configure thresholds
7376 bh .write_register (0x10 , config .get_atlo (unit = UNIT .STEPS ), byte_count = 2 )
7477 bh .write_register (0x11 , config .get_athi (unit = UNIT .STEPS ), byte_count = 2 )
78+ # 3) update config register
79+ bh .write_register (0x01 , config .as_uint16 (), byte_count = 2 )
80+ return True
7581
7682 def get_ssc_measurement (self , config : Ads1x1xConfig | None = None , unit : UNIT = UNIT .MICRO ) -> int :
7783 with BurstHandler (i2c_bus = self ._i2c_bus , i2c_adr = self ._i2c_adr ) as bh :
@@ -84,19 +90,22 @@ def get_ssc_measurement(self, config: Ads1x1xConfig | None = None, unit: UNIT =
8490 config_atlo = config .get_atlo (unit = UNIT .STEPS )
8591 config_athi = config .get_athi (unit = UNIT .STEPS )
8692 if config_uint & DOM .SSM .value :
87- bh .write_register (0x01 , config_uint | SSC .START .value , byte_count = 2 )
93+ # 1) reset to a defined state and disable alerting
94+ bh .write_register (0x01 , 0x0583 , byte_count = 2 )
95+ # 2) configure thresholds
8896 if config_atlo is not None :
8997 bh .write_register (0x10 , config_atlo , byte_count = 2 )
9098 if config_athi is not None :
9199 bh .write_register (0x11 , config_athi , byte_count = 2 )
100+ # 3) update config register
101+ bh .write_register (0x01 , config_uint | SSC .START .value , byte_count = 2 )
92102 # TODO wait until measurement is ready
93103 # (0b0..._...._...._.... -> 0b1..._...._...._....)
94104 step = bh .read_register (0x00 , byte_count = 2 )
95105 if unit == UNIT .MICRO :
96106 if self ._has_pga :
97107 pga_setting = config_uint & 0b0000_1110_0000_0000
98108 for pga_mode in PGA :
99- LH .warning ("get_ssc_measurement(): %s -> %d" , pga_mode .name , pga_mode .value )
100109 if pga_setting == pga_mode .value :
101110 return convert_step_to_microvolts (step , pga_mode )
102111 else :
0 commit comments