From a34ee32c743b35170777038a4c3ebbabf5686b43 Mon Sep 17 00:00:00 2001 From: Benedict Date: Mon, 16 Apr 2018 10:23:49 +0200 Subject: eeprom: control logic: define instructions layout and write out script --- eeprom_pi.py | 63 +++++++++++++++++++++++++++++------------------------------- 1 file changed, 30 insertions(+), 33 deletions(-) (limited to 'eeprom_pi.py') diff --git a/eeprom_pi.py b/eeprom_pi.py index e51f4b8..e45678b 100644 --- a/eeprom_pi.py +++ b/eeprom_pi.py @@ -32,15 +32,12 @@ def init_board(write = True): GPIO.setup(19, GPIO.OUT) GPIO.setup(10, GPIO.OUT) GPIO.setup(8, GPIO.OUT) - - # used to trigger a write GPIO.setup(5, GPIO.OUT) # used to read GPIO.setup(3, GPIO.OUT) # set the pins to high, pins are active low - GPIO.output(5, True) GPIO.output(3, True) @@ -49,22 +46,22 @@ def read_data(): GPIO.output(3, False) time.sleep(0.3) data = (GPIO.input(11)) - print(GPIO.input(11)) + #print(GPIO.input(11)) data |= (GPIO.input(12) << 0x1) - print(GPIO.input(12)) + #print(GPIO.input(12)) data |= (GPIO.input(13) << 0x2) - print(GPIO.input(13)) + #print(GPIO.input(13)) data |= (GPIO.input(15) << 0x3) - print(GPIO.input(15)) + #print(GPIO.input(15)) data |= (GPIO.input(16) << 0x4) - print(GPIO.input(16)) + #print(GPIO.input(16)) data |= (GPIO.input(18) << 0x5) - print(GPIO.input(18)) + #print(GPIO.input(18)) data |= (GPIO.input(22) << 0x6) - print(GPIO.input(22)) + #print(GPIO.input(22)) data |= (GPIO.input(7) << 0x7) - print(GPIO.input(7)) - print("read data: %s" % data) + #print(GPIO.input(7)) + #print("read data: %s" % data) time.sleep(0.3) GPIO.output(3, True) return data @@ -72,40 +69,39 @@ def read_data(): # data should be one byte def set_data(data): GPIO.output(11, (data & 0x1) > 0) - print((data & 0x1) > 0) + #print((data & 0x1) > 0) GPIO.output(12, (data & 0x2) > 0) - print((data & 0x2) > 0) + #print((data & 0x2) > 0) GPIO.output(13, (data & 0x4) > 0) - print((data & 0x4) > 0) + #print((data & 0x4) > 0) GPIO.output(15, (data & 0x8) > 0) - print((data & 0x8) > 0) + #print((data & 0x8) > 0) GPIO.output(16, (data & 0x10) > 0) - print((data & 0x10) > 0) + #print((data & 0x10) > 0) GPIO.output(18, (data & 0x20) > 0) - print((data & 0x20) > 0) + #print((data & 0x20) > 0) GPIO.output(22, (data & 0x40) > 0) - print((data & 0x40) > 0) + #print((data & 0x40) > 0) GPIO.output(7, (data & 0x80) > 0) - print((data & 0x80) > 0) + #print((data & 0x80) > 0) # address should be one byte def set_address(address): GPIO.output(26, (address & 0x1) > 0) - print((address & 0x1) > 0) + #print((address & 0x1) > 0) GPIO.output(24, (address & 0x2) > 0) - print((address & 0x2) > 0) + #print((address & 0x2) > 0) GPIO.output(23, (address & 0x4) > 0) - print((address & 0x4) > 0) + #print((address & 0x4) > 0) GPIO.output(21, (address & 0x8) > 0) - print((address & 0x8) > 0) + #print((address & 0x8) > 0) GPIO.output(19, (address & 0x10) > 0) - print((address & 0x10) > 0) + #print((address & 0x10) > 0) GPIO.output(10, (address & 0x20) > 0) - print((address & 0x20) > 0) + #print((address & 0x20) > 0) GPIO.output(8, (address & 0x40) > 0) - print((address & 0x40) > 0) - # for DEBUG use only 7 address bits to have one left for read trigger - #GPIO.output(5, (address & 0x80) > 0) + #print((address & 0x40) > 0) + GPIO.output(5, (address & 0x80) > 0) #print((address & 0x80) > 0) def write_data_at(address, data): @@ -115,10 +111,10 @@ def write_data_at(address, data): set_data(data) # wait so everythings is stable time.sleep(0.3) - # trigger write on pin 5 - GPIO.output(5, False) + # trigger write on pin 3 + GPIO.output(3, False) time.sleep(0.3) - GPIO.output(5, True) + GPIO.output(3, True) def read_data_at(address): @@ -128,4 +124,5 @@ def read_data_at(address): time.sleep(0.3) # trigger output enable data = read_data() - print("read data %s" % data) + print("read data %s, hex: %s" % (data, hex(data))) + return data -- cgit v1.2.3-70-g09d2