Content originally posted in LPCWare by rahulvasist on Fri Aug 12 01:15:08 MST 2011
Hi,
I'm a newbie to ARM controllers. I've been trying to interface a FRAM( fm25cl64).
I'm trying to write some data to the memory and read back the same data. But so far I'm not receiving any data. The data buffer always shows 0xff after the read operation.
. Pls help
int main(void) {
unsigned int data[]={2,0,0,100};
unsigned int dataread[11],readcmd[10]={5,0,0};
unsigned int dummy,i,stat;
LPC_PINCON->PINSEL0=(3<<30);
LPC_PINCON->PINSEL1=60;
LPC_PINCON->PINMODE0=(1<<31);
LPC_PINCON->PINMODE1=42;
LPC_SPI->SPCR=0x820;
LPC_SPI->SPCCR=88;
LPC_GPIO0->FIODIR= (1<<16);
LPC_GPIO0->FIOSET = (1<<16);
for(i=0;i<100;i++);
LPC_GPIO0->FIOCLR= (1<<16);
LPC_SPI->SPDR=6; //to send write enable
LPC_GPIO0->FIOSET = (1<<16);
for(i=0;i<100;i++);
LPC_GPIO0->FIOCLR= (1<<16);
for(i=0;i<100;i++);
{
LPC_SPI->SPDR=data;
stat=LPC_SPI->SPSR ;
dummy= stat & 128; //writing data to the memory. 2 is the write to memory command
//followed by 2-byte address
while((dummy )!= 128)
{
stat=LPC_SPI->SPSR ;
dummy= stat & 128;
}
dummy=LPC_SPI->SPDR;
}
LPC_GPIO0->FIOSET = (1<<16);
for(i=0;i<100;i++);
LPC_GPIO0->FIOCLR= (1<<16);
for(i=0;i<5;i++)
{
LPC_SPI->SPDR=readcmd;
stat=LPC_SPI->SPSR ;
while((stat & 128 )!= 128) //read from memory
stat=LPC_SPI->SPSR ; //5 is the read from memory followed by 2-byte address
dataread=LPC_SPI->SPDR;
}
LPC_GPIO0->FIOSET = (1<<16);
return 0 ;
}