def __init__(self, i2c=None, sda='P22', scl='P21'):
if i2c is not None:
self.i2c = i2c
else:
self.i2c = I2C(0, mode=I2C.MASTER, pins=(sda, scl))
self.sda = sda
self.scl = scl
self.clk_cal_factor = 1
self.reg = bytearray(6)
self.wake_int = False
self.wake_int_pin = False
self.wake_int_pin_rising_edge = True
try:
self.read_fw_version()
except Exception:
time.sleep_ms(2)
try:
# init the ADC for the battery measurements
self.poke_memory(ANSELC_ADDR, 1 << 2)
self.poke_memory(ADCON0_ADDR, (0x06 << _ADCON0_CHS_POSN) | _ADCON0_ADON_MASK)
self.poke_memory(ADCON1_ADDR, (0x06 << _ADCON1_ADCS_POSN))
# enable the pull-up on RA3
self.poke_memory(WPUA_ADDR, (1 << 3))
# make RC5 an input
self.set_bits_in_memory(TRISC_ADDR, 1 << 5)
# set RC6 and RC7 as outputs and enable power to the sensors and the GPS
self.mask_bits_in_memory(TRISC_ADDR, ~(1 << 6))
self.mask_bits_in_memory(TRISC_ADDR, ~(1 << 7))
if self.read_fw_version() < 6:
raise ValueError('Firmware out of date')
except Exception:
raise Exception('Board not detected')
评论列表
文章目录