This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
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?
Anybody?
Please help me. I`ve no clue what is wrong. I might only wonder that there is something wrong with the moment when I read the data from SPIRXBUF.
The delay is necessary because without it the CS line would go high before the whole transmission finishes. It might suggest that probably the while INT_FLAG != 1 loop doesnt hold cpu as assumed for the time while sending data. Now I`m receiving from the TXBUF 0 at the end of the code and inside that function I`m getting only READ value or address value. There is nothing more;/
And after adding the dummy reads after while I have the 8bits sck splitted into 4 groups for read, so there is a few us between each byte.
You enable loopback in:
SpibRegs.SPICCR.all = 0x0097;
SIMO/SOMI lines are connected internally. Used for module self tests
Leszek,
some comments.
1) Disable all FIFO - options. Your function READ does not use the FIFO - options, so why enable them? Later, when you have a working basic code, you can go on and use the FIFOs.
2) SpibRegs.SPICCR.all = 0x0097; doesn't make sense. Bit 4 (you set this to 1) is Loopback. This way you can't communicate with an external device.
3) SpiaRegs.SPICCR.bit.SPISWRESET = 1; isn't that the wrong channel ? (Spia)
4.) SpibRegs.SPICTL.all = 0x000E; why set bit 3 (Clock delay)? I am using a M95080 but the data sheet timing looks similar to your device - a clock shift is not neccesary.
5) A usual read access sequence to an eeprom is : CS low , 8 bit command, 16 bit address, 8 more clocks to read the data from the eeprom, CS high. So in summary you need 32 clock cycles. For the 28x this can be done in two 16 bit SPI cycles , first command and upper address, second lower address and 8 read clocks. I'd recommend to setup the SPI in 16 character mode.
I have attached an example for a 28335 and a M95080, which should also work for a 280x -SPI and a 25LC160.
Hope this helps.
Dzieki Bartosz:).
It was loopback;/
Frank: I will disable fifo, because I dont need it at all. After posting new topic, I`ve found that CTL register is wrong, so I`ve changed it form 000E to 0x0006. I know that I could use 16bit transmission, but I want to do an universal communication. What if I want to receive data from eeprom as a sequence.