Please allow me to ask the simple questions. I want to implement SPI communications between LPC1768 and M25PE16 (Serial Paged Flash Memory).
When I send 0x9F (ask for chip ID) to the M25PE16, I get only one time interrupt. I expected 8 bytes response. When I send 0x9F again I receive next byte response. Could you please take a look at my code and give me a clue what I may miss? Sorry for my English.
Best Regards.
void spi_init (void) { /* Initialize and enable the SSP Interface module. */ LPC_SC->PCONP |= (1 << 10); /* Enable power to SSPI1 block */ LPC_SC->PCLKSEL0 &= ~(3<<20); LPC_SC->PCLKSEL0 |= (1<<20); LPC_SSP1->CPSR = 4; LPC_SSP1->IMSC = 0x0006; LPC_SSP1->CR0 = 0x0007; /* 8Bit, CPOL=0, CPHA=0 */ LPC_SSP1->CR1 = 0x0002; /* SSP0 enable, master */ NVIC_EnableIRQ(SSP1_IRQn); }
void SSP1_IRQHandler (void) //odbior danych z pamieci { wskSSP1RIS = LPC_SSP1->RIS; if((wskSSP1RIS==0x02)||(wskSSP1RIS==0x08)||(wskSSP1RIS==0x0A)) //rcv znak { while(LPC_SSP1->SR & 0x04) memData[countMem++] = LPC_SSP1->DR; } if(countMem == 8) { countMem = 0; spi_ss(1); //cs high } LPC_SSP1->ICR = 3; }
With the section of code posted and not having used this particular chip, I would say this sounds correct.
You need to write out dummy byte, to initiate the other device (slave) to send, if you are expecting 8 bytes then you need to write out 8 bytes to cause the other device to clock out its 8 data bytes.
Hello Lukasz Gesieniec,
Using SPI you can on recieve a byte if you transmit a byte. You send the command code and then send a dummy byte for every byte you want to receive.
In folder ./Keil/ARM/Flash you will find several Algorithms for SPI Flash.
Best Regards, Martin Guenther
Thank you for all the information.
Many thanks, Lukas