spi interface with eeprom

Status
Not open for further replies.

krish121

Newbie level 4
Joined
Jan 29, 2013
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,315
hi! i am interafcing eeprom with spi pic 18f . i am using following setting but my code doesn’t work.. i m using 25AA040 eeprom ..
SSPSTAT =0×40; // SPI MASTER MODE, spi clock select bit CKE=1
SSPCON1=0X30; // ckp=1

then spi write command

unsigned char spi_write(char c)
{
SSPBUF=c;
while(!SSPSTATbits.BF);
return SSPBUF;
}

i follow sequence in datasheet of 25aa040 to write data but when i read data it always zero result please help me.

to write data

CS = 0;
command for write enable
cs=1;
cs=0;
command for write instruction
command for lower address
send data
command for write disable
cs=1;

to read data

cs= 0;
command for read instruction
command for lower addreaa
data=SSPBUF; // read data
cs=1;

read data is at same location where i write data…. please help me..
 

Your SPI setup refers to SPI mode 2 which doesn't work with SPI EEPROMS. They require mode 0 or 3.
 
hi! i am using with mode 0 ckp & cke are 0 but still when i read at eeprom i always get result 0.so please help me ... guide me.....
 
Last edited:

hi! i am using with mode 0 ckp & cke are 0 but still when i read at eeprom i always get result 0.
Wrong once more. ckp = 0 and cke = 0 sets mode 1 with PIC SPI interface. Please refer to the waveform in the datasheet.

By setting CKP = 0, CKE = 1, you get mode 0.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…