Hi,
I`m having some problem with spi 25LC160 eeprom. Here is my initialization code for spi for 2809.
SpibRegs.SPICCR.bit.SPISWRESET = 0; // Reset SPI
// SpibRegs.SPIFFTX.all = 0xE040;
SpibRegs.SPIFFRX.all = 0x204F;
SpibRegs.SPIFFCT.all = 0x0;
SpibRegs.SPISTS.all = 0x0000;
SpibRegs.SPIBRR = 100;
SpibRegs.SPIPRI.bit.FREE = 1;
SpibRegs.SPICCR.all = 0x0097;
SpibRegs.SPIFFTX.all = 0x8040;
SpibRegs.SPICTL.all = 0x000E;
SpiaRegs.SPICCR.bit.SPISWRESET = 1;
Gpio are set right.
There is an example code for reading one byte.
Uint16 ReadEEPROM(Uint16 addr, Uint16 co){
Uint16 rbuf,address;
if(co){
address = addr + 256;
}
else{
address = addr;
}
/* read data out of the memory */
GpioDataRegs.GPACLEAR.bit.SPI_CS = 1;
DELAY_US(1);
SpibRegs.SPITXBUF = READ << 8; // write opcode into serial shift data register
while(SpibRegs.SPISTS.bit.INT_FLAG != 1){}
dummy = SpibRegs.SPIRXBUF;
SpibRegs.SPITXBUF = (address & 0xff00); // write opcode into serial shift data register
while(SpibRegs.SPISTS.bit.INT_FLAG != 1){}
dummy = SpibRegs.SPIRXBUF;
SpibRegs.SPITXBUF = (address & 0x00ff) << 8;
while(SpibRegs.SPISTS.bit.INT_FLAG != 1){}
// dummy = SpibRegs.SPIRXBUF;
SpibRegs.SPITXBUF = 0x00 << 8;
while(SpibRegs.SPISTS.bit.INT_FLAG != 1){}
// dummy = SpibRegs.SPIRXBUF;
DELAY_US(14);
GpioDataRegs.GPASET.bit.SPI_CS = 1;
// SpibRegs.SPITXBUF = DUMMY; // write dummy into serial shift data register to turn on sck
rbuf = SpibRegs.SPIRXBUF; // receive data from the EEPROM
return(rbuf);
}
When I read data from eeprom on oscilloscope I get the right answer, but when I read the SPIRXBUF I`m getting the data which I transferred to TXBUF... why I`m getting on RX what I`ve just send to eeprom?