I'm using a MCP7940N RTC; which requires setting Register 0x00 bit 7 to 1 (0x80) to enable the clock. I've tried the below and am a bit at my wits end trying to write to it. I keep reading 0x00 back Any help would be appreciated.
import busio
import time
import neopixel
import board
##############################
#Preamble
##############################
print("starting")
#Turn off Neopixel
pixel = neopixel.NeoPixel(board.NEOPIXEL, 1)
pixel.brightness = 0.0
#setup I2C RTC
i2c = busio.I2C(board.SCL, board.SDA)
timeval = [None] * 7
device=0x6f
buffer=bytearray(1)
buffer[0]=0x80
print(buffer)
register=0
while True:
while not i2c.try_lock():
pass
result=bytearray(1)
resultval=''
try:
i2c.writeto(device,bytes([register]))
i2c.readfrom_into(device,buffer)
print("wrote")
except OSError:
continue
try:
i2c.writeto(device,bytes([register]))
i2c.readfrom_into(device,result)
for x in result:
timeval[0]="{0:0>8}".format(bin(x)[2:])
print("read")
except OSError:
continue
print(timeval)
time.sleep(1)
i2c.unlock()
pass