Page 12 of 13
Page 212
from gpiozero import SPIDevice
Dev=SPIDevice()
Dev.clock_mode=0
Dev.select_high=False
Dev._spi._interface.max_speed_hz=7000
words=Dev._spi.transfer([0xAA])
if words[0]==0xAA:
print("data received correctly")
Page 215
from gpiozero import SPIDevice
Dev = SPIDevice()
Dev.clock_mode = 0
Dev.select_high = False
Dev._spi._interface.max_speed_hz = 60000
words = Dev._spi.transfer([0x01, 0x80, 0x00])
data = (words[1] & 0x03) << 8 | words[2]
volts = data * 3.3 / 1023.0
print(volts)
Dev.close()
Page 220
class DS3234rtc(SPIDevice):
def __init__(self):
super(DS3234rtc, self).__init__()
self.clock_mode = 1
self.select_high = False
self._spi._interface.max_speed_hz = 5000000
def setDateTime(self, dateTime):
datetimetuple = dateTime.timetuple()
datetimetuple = (datetimetuple[0]-2000,)+datetimetuple[1:3] + \
(dateTime.isoweekday(),)+datetimetuple[3:6]
datetimetuple = datetimetuple[::-1]
for i in range(0, 7):
data = datetimetuple[i]
data = (data//10) << 4 | (data % 10)
words = self._spi.transfer([0x80+i, data])
def getDateTime(self):
datetimelist = []
for i in range(7):
words = self._spi.transfer([i, 0x00])
if i == 3:
continue
byte = words[1]
data = (byte & 0x0F)+(byte >> 4)*10
datetimelist.insert(0, data)
datetimelist[0] += 2000
return datetime(*datetimelist)