We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Dear Sir, I am trying to make communication with flash memory AT45DB321D with LPC 2378 every register get modified except data register, here is the code given below,
#define Cclk 12000000 //Processor clock #define Pclk Cclk //Periferals clock void InitCPU (void) { PCLKSEL0 = 0xaaaaaaaa ; // Pclk = 1/4 CclK PCLKSEL1 = 0xaaaaaaaa ; MEMMAP = 0x01; MAMCR = 0x00 ; MAMTIM = 0x03 ; MAMCR = 0x02 ; Initgpio(); } void InitSPI(void) { PCONP |= 0x100; //power on for spi 8th bit is SPI bit PINSEL0 |= 0xC0000000; //P0.15 spi pin configuration PINSEL1 |= 0x0000003C; //P0.17,P0.18,P0.16 IODIR0 = 0x00010000; IOSET0 = 0x00010000; //P0.16 S0SPCCR =0x2c ; //0x2C S0SPCR = 0xb8; //0xb8 } while(1) { S0SPDR = 0xFF; while (!(S0SPSR & SPIF)); }
Please reply... Thanks in Advance, Regards, Kishor P.
Have you really spent some debug time, actually comparing what you have written in your source code with the information in the datasheet? Not assumed that what you wrote in the code is correct but actually used pen and paper and scribbled down the bit values as suggested from the processor user manual and then compared with the text you have in the code?
Another thing - have you noticed that the processor have both SPI and SSP0? And that SSP0 (synchronous serial port) can be configured as SPI? Have you noticed the differences (advantages) of using the SSP0 instead of SPI device? You want to program a flash - isn't it an advantage to select the hardware peripherial that supports FIFO, allowing you to perform multiple byte writes without code intervention?
Anyway:
PINSEL0 |= 0xC0000000; //P0.15 spi pin configuration PINSEL1 |= 0x0000003C; //P0.17,P0.18,P0.16
What does the comment "spi pin configuration" mean? It would have helped more if you had written "P0.15 set as SCL"?
What does the comment "P0.17,P0.18,P.16" mean? Wouldn't it have helped more if you told what mapping you configured, so P0.16=SSEL, P0.17=MISO, P0.18=MOSI? Or maybe you don't want your comments to actually help the reader understand what magic a source line does?
And are you sure you should select P0.16 as SSEL? Aren't you supposted to be SPI master? Did you read the processor manual?
If the SSEL signal goes active, when the SPI block is a master, this indicates another master has selected the device to be a slave. This condition is known as a mode fault.
And further down:
If the Px.y/SSEL/... pin is assigned the SSEL function in Pin Function Select Register 0, the SSEL signal must always be inactive when the SPI controller is a master.
So how did you plan to use SSEL? Didn't you intend to inform the flash memory chip when to listen to the SPI communication? How? I don't see any single source line that seems to want to syncrhonize any transfers by giving that flash memory any slave-select, allowing the slave to know what clock pulse that would correspond to the first bit of the transfer.
S0SPCCR =0x2c ; //0x2C
So what help is it with a comment "0x2C" to a source line that assigns the value 0x2c? Can you give us some hints what help the comment brings?
Where can we see any information what PCLK you have configured? And what master clock frequency you computed and assigned to the SPI Clock Counter Register?
S0SPCR = 0xb8; //0xb8
Who will be able to figure out, from your comment, that this line is expected to: - 0x80=0x80: Request an interrupt each time SPIF or MODF are activated? By the way - you don't seem to have any interrupt handler, so why did you want to set this bit? - 0x40=0x00: Want to send data with least significant bit first? - 0x20=0x20: Wants the SPI to operate as master?- Want SCK to be active high? - 0x10=0x10: Want to have the clock polarity so it is active low? - 0x08=0x08: Want to have the clock phase so data is sampled on second clock edge? - 0x04=0x00: Want to send and receive 8 bits/transfer? - 0x03=0x00: Leave reserved bits zero?
I just can't see how that comment 0xb8 is really helping a reader. It would probably not help you either.
You write: "Every register gets modified except data register".
But have you figured out what to expect from this data register? It is not a memory cell. So values written into it can't be read back. You have to perform a full 8-bit transfer before it is meaningful to read anything from it. The manual says that incomming data goes through a shift register and will be latched and presented to this data register after a full transfer is done. And have you made any attempts to verify with an oscilloscope that the MOSI pin do shift out the value you write to this register? That the SCL pin counts pulses while MOSI sends out the data? That the SSEL pin informs the external memory chip that a SPI transfer is active?
while (!(S0SPSR & SPIF));
Doesn't this bit get set? If it does, then it indicates that the SPI master have managed to perform a full word transfer and that you either can send next word, or read back any received word from the other side. But it obviously does not indicate that the SPI slave on the other side have understood that you made an SPI transfer. That requires you to give a proper slave select - and that all signals are correctly connected to that flash memory chip.