Now I am checking out the signal waveforms at the EEPROM side.
EePromCommandWriteLatchEnable = 0x06
# *** Enable Write Enable Latch ***
while True:
spiEeprom.xfer2([EePromCommandWriteLatchEnable])
def Test25Lc256():
PrintDoubleSpaceLine("*** Start testing 25LC256 ***")
# *** Set up SPI channel ***
# import spidev # WiringPi Python wrapper
# spidev.max_speed_hz = 10000 # seems no effect, clock always 2 MHz !!!
spiEeprom = spidev.SpiDev()
spiEeprom.open(0, 0)
# *** 25LC256 instructions ***
EepromCommandWriteStatusRegister = 0x01
EepromcCommandWrite = 0x02
EePromCommandRead = 0x03
EepromCommandWriteLatchDisable = 0x04
EepromCommandReadStatusRegister = 0x05
EePromCommandWriteLatchEnable = 0x06
# *** 25LC256 addresses ***
#EepromStartAddress0= 0x0000
#EepromStartAddressUpper0 = 0x00
#EepromStartAddressLower0 = 0x00
EepromStartAddress1= 0x0300
EepromStartAddressUpper1 = 0x03
EepromStartAddressLower1 = 0x00
# *** SPI variables and constants ***
writeSpiDataList = [0x00]
readSpiDataList = [0x00, 0x00, 0x00, 0x00, 0x00]
DummyDataByte = 0x00
TestDataByte55 = 0x55
TestDataByteAa = 0xaa
WriteProtectNone = 0x00 # -
WriteProtectUpperFourth = 0x04 # 0x6000 to 0x7fff
WriteProtectUpperHalf = 0x08 # 0x4000 to 0x7fff
WriteProtectAll = 0x0c # 0x0000 to 0x7fff
FiveMilliSeconds = 0.005
# *** Enable Write Enable Latch ***
while True:
spiEeprom.xfer2([EePromCommandWriteLatchEnable])
time.sleep(FiveMilliSeconds)
# *** Read Status Register ***
readSpiDataList = spiEeprom.xfer2([EepromCommandReadStatusRegister, DummyDataByte])
PrintDoubleSpaceLine("*** Checking WEL bit after Write Enable ***")
PrintEightBitPattern("Read back byte 0 = ", readSpiDataList[0])
PrintEightBitPattern("Read back byte 1 = ", readSpiDataList[1])
time.sleep(FiveMilliSeconds)
# *** Disable Write Enable Latch ***
spiEeprom.xfer2([EepromCommandWriteLatchDisable])
time.sleep(FiveMilliSeconds)
# *** Check WEL (Write Enable Latch) bit (Bit 1) ***
readInByteList = spiEeprom.xfer2([EepromCommandReadStatusRegister, DummyDataByte])
PrintDoubleSpaceLine("*** Checking WEL bit after Write Disable ***")
PrintEightBitPattern("Read back byte 0 = ", readInByteList[0])
PrintEightBitPattern("Read back byte 1 = ", readInByteList[1])
time.sleep(0.005)
# *** Write Enable ***
spiEeprom.xfer2([EePromCommandWriteLatchEnable])
time.sleep(0.005)
# *** Check WEL (Write Enable Latch) bit (Bit 1) ***
readInByteList = spiEeprom.xfer2([EepromCommandReadStatusRegister, DummyDataByte])
PrintDoubleSpaceLine("*** Checking WEL bit after Write Enable ***")
PrintEightBitPattern("Read back byte 0 = ", readInByteList[0])
PrintEightBitPattern("Read back byte 1 = ", readInByteList[1])
time.sleep(0.005)
# *** Write protect upper fourth ****
spiEeprom.xfer2([EepromCommandWriteStatusRegister, WriteProtectUpperFourth])
time.sleep(0.005)
# *** Check Status Register ***
readInByteList = spiEeprom.xfer2([EepromCommandReadStatusRegister, DummyDataByte])
PrintDoubleSpaceLine("*** Checking Write Protect Bits ***")
PrintEightBitPattern("Read back byte 0 = ", readInByteList[0])
PrintEightBitPattern("Read back byte 1 = ", readInByteList[1])
time.sleep(0.005)
# *** Write Enable ***
spiEeprom.xfer2([EePromCommandWriteLatchEnable])
time.sleep(0.005)
# *** Write protect none ****
spiEeprom.xfer2([EepromCommandWriteStatusRegister, WriteProtectNone])
time.sleep(0.005)
# *** Check Status Register ***
readInByteList = spiEeprom.xfer2([EepromCommandReadStatusRegister, DummyDataByte])
PrintDoubleSpaceLine("*** Checking Write Protect Bits ***")
PrintEightBitPattern("Read back byte 0 = ", readInByteList[0])
PrintEightBitPattern("Read back byte 1 = ", readInByteList[1])
time.sleep(0.005)
# *** Write Enable ***
spiEeprom.xfer2([EePromCommandWriteLatchEnable])
time.sleep(0.005)
# *** Write 2 data bytes at address 0x0000 ****
spiEeprom.xfer2([EepromcCommandWrite, EepromStartAddressUpper1, EepromStartAddressLower1, TestDataByte55, TestDataByte55])
# *** Check WIP (Write In Progress) bit (Bit 0) ***
readInByteList = spiEeprom.xfer2([EepromCommandReadStatusRegister, DummyDataByte])
PrintDoubleSpaceLine("*** Checking WIP bit immediately after writing 1 byte without waiting 5 mS ***")
PrintEightBitPattern("Read back byte 0 = ", readInByteList[0])
PrintEightBitPattern("Read back byte 1 = ", readInByteList[1])
time.sleep(0.005)
# *** Check WIP (Write In Progress) bit (Bit 0) ***
readInByteList = spiEeprom.xfer2([EepromCommandReadStatusRegister, DummyDataByte])
PrintDoubleSpaceLine("*** Checking WIP bit again, after waiting 5 mS ***")
PrintEightBitPattern("Read back byte 0 = ", readInByteList[0])
PrintEightBitPattern("Read back byte 1 = ", readInByteList[1])
# *** Enable Write Enable Latch ***
spiEeprom.xfer2([EePromCommandWriteLatchEnable])
time.sleep(FiveMilliSeconds)
# *** Read back data at address 0x0000 ***
readSpiDataList = spiEeprom.xfer2([EePromCommandRead, EepromStartAddressUpper1, EepromStartAddressLower1, DummyDataByte, DummyDataByte])
PrintDoubleSpaceLine("*** Read back data byte written ***")
PrintEightBitPattern("Read back byte 0 = ", readSpiDataList[0])
PrintEightBitPattern("Read back byte 1 = ", readSpiDataList[1])
PrintEightBitPattern("Read back byte 2 = ", readSpiDataList[2])
PrintEightBitPattern("Read back byte 3 = ", readSpiDataList[3])
PrintEightBitPattern("Read back byte 4 = ", readSpiDataList[4])
# *** Write Enable ***
spiEeprom.xfer2([EePromCommandWriteLatchEnable])
time.sleep(0.005)
# *** Write 2 data bytes at address 0x0000 ****
spiEeprom.xfer2([EepromcCommandWrite, EepromStartAddressUpper1, EepromStartAddressLower1, TestDataByteAa, TestDataByteAa])
# *** Check WIP (Write In Progress) bit (Bit 0) ***
readInByteList = spiEeprom.xfer2([EepromCommandReadStatusRegister, DummyDataByte])
PrintDoubleSpaceLine("*** Checking WIP bit immediately after writing 1 byte without waiting 5 mS ***")
PrintEightBitPattern("Read back byte 0 = ", readInByteList[0])
PrintEightBitPattern("Read back byte 1 = ", readInByteList[1])
time.sleep(0.005)
# *** Check WIP (Write In Progress) bit (Bit 0) ***
readInByteList = spiEeprom.xfer2([EepromCommandReadStatusRegister, DummyDataByte])
PrintDoubleSpaceLine("*** Checking WIP bit again, after waiting 5 mS ***")
PrintEightBitPattern("Read back byte 0 = ", readInByteList[0])
PrintEightBitPattern("Read back byte 1 = ", readInByteList[1])
# *** Enable Write Enable Latch ***
spiEeprom.xfer2([EePromCommandWriteLatchEnable])
time.sleep(FiveMilliSeconds)
# *** Read back data at address 0x0000 ***
readSpiDataList = spiEeprom.xfer2([EePromCommandRead, EepromStartAddressUpper1, EepromStartAddressLower1, DummyDataByte, DummyDataByte])
PrintDoubleSpaceLine("*** Read back data byte written ***")
PrintEightBitPattern("Read back byte 0 = ", readSpiDataList[0])
PrintEightBitPattern("Read back byte 1 = ", readSpiDataList[1])
PrintEightBitPattern("Read back byte 2 = ", readSpiDataList[2])
PrintEightBitPattern("Read back byte 3 = ", readSpiDataList[3])
PrintEightBitPattern("Read back byte 4 = ", readSpiDataList[4])
# *** Close SPI channel ***
spiEeprom.close()
#while True:
# pass
PrintDoubleSpaceLine("*** Stop testing write/read 25LC256 ***")
.END
No comments:
Post a Comment