swu
Posts: 2
Joined: Fri May 22, 2020 12:48 am

Interfacing SPI EEPROM (25LC512)

Fri May 22, 2020 1:29 am

Hi,
I’m new to Raspberry Pi and Python. I’m trying to write a byte to an SPI EEPROM (25LC512), but couldn’t get it to work. I’m pretty sure the connections are right. Somehow it always reads back 0xFF no matter what value I write. Can anyone take a look at my code and tell me what the problem is? Code, connection and logic analyzer captures are attached.
Datasheet is here. http://ww1.microchip.com/downloads/en/D ... 22065C.pdf

Thanks.

Code: Select all

#Writes/reads to & from 25LC512
#writes 0x33 to address 0x0001 and reads back

import spidev
import time
spi=spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz=7629

write_cmd=0x02
read_cmd=0x03
Hi_Addr=0x00
Lo_Addr=0x01
data0=0x33
dummy=0x00
write_sequence0=[write_cmd, Hi_Addr, Lo_Addr, data0]
read_sequence0=[read_cmd, Hi_Addr, Lo_Addr, dummy]

#write 0xF33 to address 0x0001
spi.writebytes(write_sequence0)

time.sleep(0.005)  #delay 5ms
#read 1 byte from 0x0001
read_data=spi.xfer2(read_sequence0)
Capture1.png
Logic analyzer capture
Capture1.png (153.35 KiB) Viewed 79 times
capture2.gif
Setup
capture2.gif (181.78 KiB) Viewed 79 times

swu
Posts: 2
Joined: Fri May 22, 2020 12:48 am

Re: Interfacing SPI EEPROM (25LC512)

Sat May 23, 2020 1:21 am

Never mind. I found the problem. The write-enable byte needs to be transmitted first.

Return to “Python”