2013-11-04

EEPROM 25LC256 SPI program in Raspberry Pi Python (2013may11)


Saturday, May 11, 2013 Miicrochip SPI EEPROM 25LC256 cannot read back problem solved!

http://fongelectronics.blogspot.hk/2013/05/miicrochip-spi-eeprom-25lc256-cannot.html

So I began doing pair/swap troubleshooting.  I first tested the 25LC256 on bread board, to make sure that the test program still could not read back what is written in. 

The test program first writes 2 bytes 0x55, 0x55 and then read back.  Then it writes 0xaa, 0xaa, and reads back.

    spiEeprom.xfer2([EepromcCommandWrite, EepromStartAddressUpper1, EepromStartAddressLower1, TestDataByte55, TestDataByte55])

    readSpiDataList = spiEeprom.xfer2([EePromCommandRead, EepromStartAddressUpper1, EepromStartAddressLower1, DummyDataByte, DummyDataByte]) 

    spiEeprom.xfer2([EepromcCommandWrite, EepromStartAddressUpper1, EepromStartAddressLower1, TestDataByteAa, TestDataByteAa]) 

    readSpiDataList = spiEeprom.xfer2([EePromCommandRead, EepromStartAddressUpper1, EepromStartAddressLower1, DummyDataByte, DummyDataByte]) 


What is read back from the 25LC256 on bread board is the following.

Read back byte 3 =  01111111
Read back byte 4 =  11111111

Read back byte 3 =  00000000

Read back byte 4 =  00000000


Then I swapped the proto board version of 25LC256 and ran the same test again.  This time, to my surprise, reads back the what is written.  So problem solved!


Read back byte 3 =  01010101
Read back byte 4 =  01010101

Read back byte 3 =  10101010
Read back byte 4 =  10101010

Before this pair troubleshooting, I did not have any confidence and my plan was that if the protoboard 25LC256 does not work, and it might take me hours to continue troubleshooting but still get no results.  I might need to suspend this project for a while.  But now it is very smooth.

Next step is to swap the two EEPROM ICs to see if the first one is faulty.


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 0x0300 ****

    # while True:
    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 ***
    
    time.sleep(1)

    #while True:
    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 ***") 



*** Start Program - 25LC256 EEPROM05 ***


*** Start testing 25LC256 ***


*** Checking WEL bit after Write Enable ***

Read back byte 0 =  00000000
Read back byte 1 =  00000010

*** Checking WEL bit after Write Disable ***

Read back byte 0 =  00000000
Read back byte 1 =  00000000

*** Checking WEL bit after Write Enable ***

Read back byte 0 =  00000000
Read back byte 1 =  00000011

*** Checking Write Protect Bits ***

Read back byte 0 =  11111111
Read back byte 1 =  00000100

*** Checking Write Protect Bits ***

Read back byte 0 =  00000000
Read back byte 1 =  00000000

*** Checking WIP bit immediately after writing 1 byte without waiting 5 mS ***

Read back byte 0 =  00000000
Read back byte 1 =  00000011

*** Checking WIP bit again, after waiting 5 mS ***

Read back byte 0 =  11111111
Read back byte 1 =  00000000

*** Read back data byte written ***

Read back byte 0 =  00000000
Read back byte 1 =  00000000
Read back byte 2 =  00000000
Read back byte 3 =  01111111
Read back byte 4 =  11111111

*** Checking WIP bit immediately after writing 1 byte without waiting 5 mS ***

Read back byte 0 =  11111111
Read back byte 1 =  00000011

*** Checking WIP bit again, after waiting 5 mS ***

Read back byte 0 =  11111111
Read back byte 1 =  00000000

*** Read back data byte written ***

Read back byte 0 =  00000000
Read back byte 1 =  00000000
Read back byte 2 =  00000000
Read back byte 3 =  00000000
Read back byte 4 =  00000000

*** Stop testing write/read 25LC256 ***


*** Stop Program ***

pi@raspberrypi ~/python_programs/test_eeprom $ sudo python fl2077.py

*** Start Program - 25LC256 EEPROM05 ***


*** Start testing 25LC256 ***


*** Checking WEL bit after Write Enable ***

Read back byte 0 =  00000000
Read back byte 1 =  00000010

*** Checking WEL bit after Write Disable ***

Read back byte 0 =  00000000
Read back byte 1 =  00000000

*** Checking WEL bit after Write Enable ***

Read back byte 0 =  00000000
Read back byte 1 =  00000010

*** Checking Write Protect Bits ***

Read back byte 0 =  00000000
Read back byte 1 =  00000100

*** Checking Write Protect Bits ***

Read back byte 0 =  00000000
Read back byte 1 =  00000000

*** Checking WIP bit immediately after writing 1 byte without waiting 5 mS ***

Read back byte 0 =  00000000
Read back byte 1 =  00000011

*** Checking WIP bit again, after waiting 5 mS ***

Read back byte 0 =  00000000
Read back byte 1 =  00000000

*** Read back data byte written ***

Read back byte 0 =  00000000
Read back byte 1 =  00000000
Read back byte 2 =  00000000
Read back byte 3 =  01010101
Read back byte 4 =  01010101

*** Checking WIP bit immediately after writing 1 byte without waiting 5 mS ***

Read back byte 0 =  11111111
Read back byte 1 =  00000011

*** Checking WIP bit again, after waiting 5 mS ***

Read back byte 0 =  00000000
Read back byte 1 =  00000000

*** Read back data byte written ***

Read back byte 0 =  00000000
Read back byte 1 =  00000000
Read back byte 2 =  00000000
Read back byte 3 =  10101010
Read back byte 4 =  10101010

*** Stop testing write/read 25LC256 ***


*** Stop Program ***

.END


No comments:

Post a Comment