Dear Sirs, Here I am trouble in SPI communication (LPC2378 master mode).I set all registers properly. whenever I writing opcode (any value) on S0SPDR (data register),data transfer flag is set.but S0SPDR register showing 00 (zero).ie. I am not able to write data on data register.
so where is problem?
regards Shyam T.
Dear sirs Here I am doing SPI communication LPC2378 with dataflash (AT456DB161)</>b.Here I am in trouble from few days.I am not getting data on S0SPDR after simulation. Here is my SPI master initalization
void InitSPI(void) { PCONP |= 0x100; PINSEL0 |= 0xC0000000; //P0.15 spi pin configuration PINSEL1 |= 0x0000003F; //P0.16,P0.17,P0.18 PCLKSEL0 |= 0x00000000; //PCLK= CCLK/4 IODIR0 = SPI0_SEL; IOSET0 |= 0x4000; IODIR0 = 0x4000; IOSET0 |= 0x800; S0SPCCR |= 0xA5; //S0SPCCR |= 0xA8; // spi bus frequency S0SPCR |= 0x20; //CPH = 0, CPOL = 0
Here I am writing on SPI (S0SPDR register)
void WrToflash(unsigned int BaseAdd,unsigned char size,unsigned char *buffAdd1) { unsigned char k; unsigned char u32dummyData; for (k=0;k<size; k++) { IOCLR0 |= 0x4000; S0SPDR = 0x87; while (!(S0SPSR & SPIF)); u32dummyData = S0SPDR; S0SPDR = (BaseAdd>>8) & 0xFF; while (!(S0SPSR & SPIF)); u32dummyData = S0SPDR; Delay(1000); S0SPDR = BaseAdd & 0xFF; while (!(S0SPSR & SPIF)); u32dummyData = S0SPDR; BaseAdd++; S0SPDR = buffAdd1[k]; while (!(S0SPSR & SPIF)); u32dummyData = S0SPDR; IOSET0 |= 0x4000; } }
Here I am reading from SPI (S0SPDR register)
void RdFromflash(unsigned int BaseAdd2,unsigned char size2,unsigned char *buffAdd2) { unsigned char j; unsigned char u32dummyData2; IOCLR0 |= 0x4000; S0SPDR = 0xD6; //opcode for rading flash location while (!(S0SPSR & SPIF)); u32dummyData2 = S0SPDR; S0SPDR = (BaseAdd2>>8) & 0xFF; while (!(S0SPSR & SPIF)); u32dummyData2 = S0SPDR; S0SPDR = BaseAdd2 & 0xFF; while (!(S0SPSR & SPIF)); u32dummyData2 = S0SPDR; for (j=0;j<size2;j++) { Delay(1000); S0SPDR = 0; //Dummy write while (!(S0SPSR & SPIF)); buffAdd2[j] = S0SPDR; } IOSET0 |= 0x4000; }
Here what happen I observed status on simulator. all SPI register i observed all all modify according to my settings except datar egister(S0SPDR), when I observed S0SPDR during writing data,i am writing 0x87 but it is not modify,it only showing 0x00.at that time my SPI transfer flag bit is set. so Is my (desired)data transfer is completed,if completed what value it is transfer?
At the time of reading I am getting 0xFF on my hyperterminal.so what will be exect issue?
Plz help me regarding this issue. you can send your code on my mail ID shyam_tayade@rediffmail.com
wating for your positive reply.....
regards Shyam T. Pune India
Writing a byte to the data register does not always mean that you can read back what you wrote. Reading from the register is intended to read the received data, not the data you are about to send. But you have to give the chip time to perform a transfer until there will be something to receive. And if you run in the simulator, then you must write a simulator script that will react to the SPI transfer and return back anything - the simulator don't have real MISO and MOSI signals to perform SPI communication on.
Thanks for reply. ok, that is why i was not able to observe dataregister (S0SPDR). Today I on my UART and send each responce on hypertermanil.I observe that when i send my write opcode (0x87)than at same time i read responce and send it to hyperterminal I got OxFF reponce on hyperterminal.what it means? Is opcode is appropriate reach to dataflash or not?
wating for ur reply....
Regards shaym T. Pune India
Dear Sir Thanks for replying, I got solution, now my SPI communication is working. I found in trouble when I was sending dummy data.
regards Shyam T. pune India