強誘電体メモリ(FRAM)のFM18W08のライターと同様に今回もPythonで作成しました
まず初めにI2Cを有効にします
RaspberryPiのマークから設定→RaspberryPiの設定→インターフェース→I2Cを有効にします
pythonでi2cを操作できるように i2cツールをインストールします。
$ sudo apt-get install python-smbus
次に i2c-toolsをインストールします。
$ sudo apt-get install i2c-tools
製作したライターの回路確認した上で(特に電源周りのショートなど)、RaspberryPiに接続します。
i2c-toolsでアドレスを確認します。
$ sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: 20 21 -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
20番、21番の表示が出たら、OKです。
今回はpython3で作成してみました
コマンドラインは次のようになります。
python3 hex_uvprom_write.py 2764 halt.ihx
27128
2732(アダプター使用)
hexwriteでは2732と2764/27128で次に書き込みを行なっています。
2732 書き込みタイム70mSでのいっぱつ書き込み 一つしかない2732で書き込みました
必要に応じて調整する必要あります(60行目)
2764/27128 書き込みタイム 1mS刻みで0Kであれば終了、50回までくり返す
hex_uvprom_write.py で保存してください
#!/usr/bin/env python3
# i2c MCP23017 UV-PROM Prograble Writer V0.1 by pinecone 2021/05/10
#
# UV-PROM 2732 2764 27128 all Vpp 21V only
import smbus
import time
import sys
bus = smbus.SMBus(1)
# 16bit i/o i2c interface MCP23017 * 2chip
# DEVICE_ADDR MCP23017 No1
# DEVICE_DATA MCP23017 No2
DEVICE_ADDR = 0x20 #A port >low address :B port >upper address
DEVICE_DATA = 0x21 #A port >data :B port WE OE CE Vcc or Vpp on/off
# IOCON.BANK =0 (default)
IODIRA = 0x00
IODIRB = 0x01
OLATA = 0x14
OLATB = 0x15
GPIOA = 0x12
GPIOB = 0x13
GPPUA = 0x0C
GPPUB = 0x0D
# DEVICE_ADDR > setting output
bus.write_byte_data(DEVICE_ADDR,IODIRA,0x00) #address A0~A7 output mode
bus.write_byte_data(DEVICE_ADDR,IODIRB,0x00) #address A8~A15 output mode
# DEVICE_DATA > data:input PGM,OE,CE:output or Vpp5V/21V Vcc on/off
bus.write_byte_data(DEVICE_DATA,IODIRA,0xFF) #data D0~D7 input mode
bus.write_byte_data(DEVICE_DATA,IODIRB,0x00) #PGM/OE/CE or Vpp/Vcc output mode
bus.write_byte_data(DEVICE_DATA,OLATB,0x0F) #PGM/OE/CE=1 :Vpp/Vcc=0
# DEVICE_DATA > pull up
bus.write_byte_data(DEVICE_DATA,GPPUA,0xFF) #data pullup
bus.write_byte_data(DEVICE_DATA,GPPUB,0x0F) #PGM/OE/CE pullup
def hexwrite(address, data):
# B0:/PGM B4:Vpp-21V ON(1)/OFF(0)
# B1:/OE B5:Vpp-5V ON(1)/OFF(0)
# B2:/CE B6:Vcc(5V) ON(1)/OFF(0)
#
low_addr = 0xff & address
higth_addr = (0xff00 & address) >> 8
#print "Higth_addr:%02x Low_addr:%02x data:%02x" % (higth_addr, low_addr, data)
# data write
if rom_type== 0x0fff: #rom type 2732
bus.write_byte_data(DEVICE_ADDR,OLATA,low_addr)
bus.write_byte_data(DEVICE_ADDR,OLATB,higth_addr)
bus.write_byte_data(DEVICE_DATA,IODIRA,0x00) #data output mode
bus.write_byte_data(DEVICE_DATA,OLATA,data)
bus.write_byte_data(DEVICE_DATA,OLATB,0b01011010) #Vcc Vpp on CE=0 OE/vpp21v=1(write)
time.sleep(0.07)
bus.write_byte_data(DEVICE_DATA,OLATB,0b01001001) #Vcc on CE=0 OE/vpp21v=0(read)
bus.write_byte_data(DEVICE_DATA,OLATB,0b01001101) #Vcc on CE=1 OE/vpp21v=0(read)
else: #rom type not 2732
bus.write_byte_data(DEVICE_DATA,OLATB,0b01011101) #Vcc Vpp on /CE=1 OE=0 PGM=1
bus.write_byte_data(DEVICE_ADDR,OLATA,low_addr)
bus.write_byte_data(DEVICE_ADDR,OLATB,higth_addr)
bus.write_byte_data(DEVICE_DATA,IODIRA,0x00) #data output mode
bus.write_byte_data(DEVICE_DATA,OLATA,data)
for write_count in range(50):
bus.write_byte_data(DEVICE_DATA,OLATB,0b01011101) #Vcc Vpp on /CE=1 OE=0 PGM=1
bus.write_byte_data(DEVICE_DATA,OLATB,0b01011011) #Vcc Vpp on /CE=0 OE=1 PGM=1
bus.write_byte_data(DEVICE_DATA,OLATB,0b01011010) #Vcc Vpp on /CE=0 OE=1 PGM=0
time.sleep(0.001)
bus.write_byte_data(DEVICE_DATA,IODIRA,0xFF) #data input mode
bus.write_byte_data(DEVICE_DATA,OLATB,0b01011001) #Vcc Vpp on /CE=0 OE=0 PGM=1
read_data = bus.read_byte_data(DEVICE_DATA,GPIOA)
if data == read_data :
break
bus.write_byte_data(DEVICE_DATA,IODIRA,0x00) #data output mode
bus.write_byte_data(DEVICE_DATA,OLATA,data)
bus.write_byte_data(DEVICE_DATA,OLATB,0b01101001) #Vcc on Vpp off /CE=0 OE=0 PGM=1
# data read
read_data=hexread(address)
if data != read_data:
bus.write_byte_data(DEVICE_DATA,OLATB,0b00001101) #Vcc off Vpp off /CE=1 OE=0 PGM=1
sys.exit(" :Write check Error")
return read_data
def hexread(address):
# B0:/PGM B4:Vpp-21V ON(1)/OFF(0)
# B1:/OE B5:Vpp-5V ON(1)/OFF(0)
# B2:/CE B6:Vcc(5V) ON(1)/OFF(0)
#
low_addr = 0x00ff & address
higth_addr = (0xff00 & address) >> 8
if rom_type== 0x0fff: #rom type 2732
bus.write_byte_data(DEVICE_DATA,IODIRA,0xFF) #data input mode
bus.write_byte_data(DEVICE_DATA,OLATB,0b01001111) #vcc on CE=1 OE/vpp=0(read)
bus.write_byte_data(DEVICE_ADDR,OLATA,low_addr)
bus.write_byte_data(DEVICE_ADDR,OLATB,higth_addr)
bus.write_byte_data(DEVICE_DATA,OLATB,0b01001011) #vcc on CE=0 OE/vpp=0(read)
read_data = bus.read_byte_data(DEVICE_DATA,GPIOA)
bus.write_byte_data(DEVICE_DATA,OLATB,0b01001111) #vcc on CE=1 OE/vpp=0(read)
else: #rom type not 2732
bus.write_byte_data(DEVICE_DATA,IODIRA,0xFF) #data input mode
bus.write_byte_data(DEVICE_DATA,OLATB,0b01101111) #vcc Vpp5V on CE=1 OE=1
bus.write_byte_data(DEVICE_ADDR,OLATA,low_addr)
bus.write_byte_data(DEVICE_ADDR,OLATB,higth_addr)
bus.write_byte_data(DEVICE_DATA,OLATB,0b01101011) #vcc Vpp5V on CE=0 OE=1
bus.write_byte_data(DEVICE_DATA,OLATB,0b01101001) #vcc Vpp5V on CE=0 OE=0
read_data = bus.read_byte_data(DEVICE_DATA,GPIOA)
bus.write_byte_data(DEVICE_DATA,OLATB,0b01101111) #vcc Vpp5V on CE=1 OE=1
return read_data
def read_dump():
rom_type = 0xff
print ('addr +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +a +b +c +d +e +f')
for rom_addr in range(0,rom_type,0x10):
print ('{:4x} '.format(rom_addr),end='')
for addr_p in range(0x10):
read_data=hexread(rom_addr+addr_p)
print ('{:4x} '.format(rom_addr+addr_p),end='')
print (' {:2x}'.format(read_data),end='')
print(end='\n')
def blank_check(rom_type):
print('Blank Check Start: ',end='')
for rom_addr in range(0,rom_type+1):
read_data=hexread(rom_addr)
if read_data != 0xff:
print(' addr:{:4x} '.format(rom_addr),'data:{:2x}'.format(read_data))
bus.write_byte_data(DEVICE_DATA,OLATB,0b00001101) #Vcc off Vpp off /CE=1 OE=0 PGM=1
sys.exit("Stop: Blank Check Error!")
else:
print('\rBlank Check :addr={:4x}'.format(rom_addr),end='')
print(' :OK')
return True
if len(sys.argv) != 3 : #command in err
sys.exit("SyntaxError: InputFiles is [python hex_uvrom_write 2764[27128 or 2732] [Hex_file_name.hex(ihx)]")
if sys.argv[1] == "2764" :
rom_type=0x1fff
elif sys.argv[1] == "27128" :
rom_type=0x3fff
elif sys.argv[1] == "2732" :
rom_type=0x0fff
else:
sys.exit("ROM Type Error :selct 2732 or 2764 or 27128 ")
if sys.argv[2][-4:] !=".hex" and sys.argv[2][-4:] !=".ihx" : #Extension err
sys.exit("ExtensionError: InputFiles is [python hexwrite Hex_file_name.hex(ihx)]")
f= open(sys.argv[2])
D_hex = f.read()
f.close()
blank_check(rom_type)
y = D_hex.split('\n')
for i in range(len(y)):
if y[i][0] in ':' :
# print y[i]
check_sum = 0
for k in range(1,(len(y[i]) -1),2):
check_sum = check_sum + int(y[i][k] +y[i][k+1],16)
# print "check_sum= %04x " % check_sum
if (check_sum & 0x00ff) != 0x0000:
bus.write_byte_data(DEVICE_DATA,OLATB,0b00001101) #Vcc off Vpp off /CE=1 OE=0 PGM=1
sys.exit("Check Sum Error")
byte_suu=abs(int(y[i][1]+y[i][2],16))
# print byte_suu
address = int(y[i][3]+y[i][4]+y[i][5]+y[i][6],16)
# print hex(address)
record_type=int(y[i][7] + y[i][8],10)
# print record_type
if record_type == 0:
for j in range(9,9+byte_suu*2,2) :
data_byte = int(y[i][j] + y[i][j+1] ,16)
rw_address = address + ((j-9) >> 1)
# print ('\rWrite_address: {:4x}'.format(rw_address),'data:{:2x}'.format(data_byte),end='')
print ('\rWrite_address: {:4x} data:{:2x}'.format(rw_address,data_byte),end='')
hexwrite(rw_address, data_byte)
elif record_type == 1:
bus.write_byte_data(DEVICE_DATA,OLATB,0b00001101) #Vcc off Vpp off /CE=1 OE=0 PGM=1
print (" :Hex end blok")
print ("Hex Write OK")
sys.exit()
else:
# print y[i]
# print len(y[i])
# print ord(y[i][0])
if ord(y[i][0]) == 26 :
print ("Hex Write End")
bus.write_byte_data(DEVICE_DATA,OLATB,0b00001101) #Vcc off Vpp off /CE=1 OE=0 PGM=1
sys.exit()
else:
print ("NG")
hex(y[i][0])
bus.write_byte_data(DEVICE_DATA,OLATB,0b00001101) #Vcc off Vpp off /CE=1 OE=0 PGM=1
sys.exit("Error: No Hex Files")
# program end