@@ -39,7 +39,7 @@ def _send(self, data):
3939 self .uart .write (bytes (data ))
4040
4141 def _start (self ):
42- self .uart .sendbreak (11 )
42+ self .uart .sendbreak (20 )
4343 self ._send ([0x55 ])
4444
4545 def _magic (self , address , and_val , or_val , xor_val , expected = None ):
@@ -48,7 +48,8 @@ def _magic(self, address, and_val, or_val, xor_val, expected=None):
4848 if expected is None :
4949 return self .uart .read ()
5050 else :
51- return self .uart .read (expected )
51+ if expected > 0 :
52+ return self .uart .read (expected )
5253
5354 def _add_to_pin_mask (self , mask , pin ):
5455 if pin == 'P10' or pin == 'G17' :
@@ -95,15 +96,17 @@ def calibrate(self):
9596 The idea is to measure the real life duration of periods marked with *
9697 and substract them. That will remove any errors common to both measurements
9798 The result is 7 ms as generated by the PIC LF clock.
98- It can be used to scale any future sleep value."""
99+ It can be used to scale any future sleep value. """
99100
100101 # setbits, but limit the number of received bytes to avoid confusion with pattern
101- self ._magic (CTRL_0_ADDR , 0xFF , 1 << 2 , 0 , 7 )
102+ self ._magic (CTRL_0_ADDR , 0xFF , 1 << 2 , 0 , 0 )
102103 self .uart .deinit ()
103- Pin (COMM_PIN , mode = Pin .IN )
104- pulses = pycom .pulses_get (COMM_PIN , 50000 )
104+ self ._pulses = pycom .pulses_get (COMM_PIN , 50 )
105105 self .uart = UART (1 , baudrate = 10000 , pins = (COMM_PIN , ))
106- self .clk_cal_factor = (pulses [3 ][1 ] - pulses [1 ][1 ]) / EXP_RTC_PERIOD
106+ try :
107+ self .clk_cal_factor = (self ._pulses [4 ][1 ] - self ._pulses [1 ][1 ]) / EXP_RTC_PERIOD
108+ except :
109+ pass
107110 if self .clk_cal_factor > 1.25 or self .clk_cal_factor < 0.75 :
108111 self .clk_cal_factor = 1
109112
0 commit comments