Skip to content

Instantly share code, notes, and snippets.

@rxseger
Last active August 29, 2016 03:53
Show Gist options
  • Select an option

  • Save rxseger/23f66415a72d9065e2a054b90c99c327 to your computer and use it in GitHub Desktop.

Select an option

Save rxseger/23f66415a72d9065e2a054b90c99c327 to your computer and use it in GitHub Desktop.
parallel memory dumping using Raspberry Pi GPIO, for AT27C080 8Mbit CMOS EPROM
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
# Data and address pins
# MSB first
# G23 G24 G10 G09 G25 G11 G08 G07 # BCM
# MOSI MISO SCK CE0 CE1 # alt functions
data_pins = [16, 18, 19, 21, 22, 23, 24, 26] # board
# O7 O6 O5 O4 O3 O2 O1 O0 # chip
# 21 20 19 18 17 15 14 13 # AT27C080
assert len(data_pins) == 8, "must have exacty 8 data pins (8 bits/byte)"
# G19 G16 G26 G20 G21 # BCM
# # alt functions
address_pins = [35, 36, 37, 38, 40] # board
# A4 A3 A2 A1 A0 # chip
# 8 9 10 11 12 # AT27C080
GPIO.setup(data_pins, GPIO.IN)
GPIO.setup(address_pins, GPIO.OUT, initial=GPIO.LOW)
def read_byte():
byte = 0
for i in range(len(data_pins)):
bit = GPIO.input(data_pins[i])
byte |= bit * 2**(len(data_pins)-1-i)
#print i,bit,data_pins[i]
return byte
def set_address(address):
assert address < 2**len(address_pins), "attempted to set address %.2x beyond %d address pins" % (address, len(address_pins))
for i in range(len(address_pins)):
bit = (address & 2**(len(address_pins)-1-i)) != 0
GPIO.output(address_pins[i], bit)
#print i,bit,address_pins[i]
for address in range(0, 2**len(address_pins)):
set_address(address)
if address % 4 == 0: print
print "%.4x =" % (address,),
#time.sleep(0.5)
#byte = read_byte()
#print "%.4x = %.2x" % (address, byte)
time.sleep(0.2)
seen = {}
for i in range(20):
byte = read_byte()
if not seen.has_key(byte): seen[byte] = 0
seen[byte] += 1
print "%.2x " % (byte,),
time.sleep(0.1)
print " ",
for saw in sorted(seen.keys()):
print (str(seen[saw]) + "x") + "%.2x=%s " % (saw, bin(saw)[2:]),
print
time.sleep(0.2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment