I am using AT45DB081D atmel IC and lm3s5951 stallaries controller
My code is working with GPIO but not with SPI my SPI code is as shown bellow:-
#define SSI_CLK GPIO_PIN_0
#define SSI_CS GPIO_PIN_1
#define SSI_TX GPIO_PIN_3
#define SSI_RX GPIO_PIN_2
unsigned long data;
int main(void){
unsigned long BufReception;
SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_8MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeGPIOOutPut(GPIO_PORTA_BASE, SSI_CS);
GPIOPinWrite(GPIO_PORTA_BASE, SSI_CS, SSI_CS);
GPIOPinTypeSSI(GPIO_PORTA_BASE, SSI_CLK | SSI_TX | SSI_RX );
SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0,
SSI_MODE_MASTER, 1000000, 8);
SSIEnable(SSI0_BASE);
DelayUs(10); //10uSec
Spi_erase();
Buffer_write(); // buffer 1 write
Buffer_read(); // buffer 1 read
LcdDisplay(data);//lcd display
}
void Spi_erase()
{
uint16 block_counter = 0;
unit8 addfld[2];
Df_ReadyBusy();
while(block_counter
<512) //total 512 block
{
addfld[0]=((uint8)(block_counter>>4));
addfld[1]=((uint8)(block_counter<<4));
GPIOPinWrite(GPIO_PORTA_BASE, SSI_CS, 0); //chip select low
SSIDataPut(SSI0_BASE, 0x50); //block erase SSIDataGet(SSI0_BASE, &dummyBuf);//dummy to clear write buffer
SSIDataPut(SSI0_BASE, &addfld[0]
);
SSIDataGet(SSI0_BASE, &dummyBuf);
SSIDataPut(SSI0_BASE,
); //24 bits address&
addfld[0]
SSIDataGet(SSI0_BASE, &dummyBuf);
SSIDataPut(SSI0_BASE, 0x00);
SSIDataGet(SSI0_BASE, &dummyBuf);
GPIOPinWrite(GPIO_PORTA_BASE, SSI_CS, SSI_CS);//chip select high
Df_ReadyBusy();
}
}
void buffer_read()
Df_ReadyBusy();
{
GPIOPinWrite(GPIO_PORTA_BASE, SSI_CS, 0); //chip select low
SSIDataPut(SSI0_BASE, 0xD4); //read buffer 1
SSIDataGet(SSI0_BASE, &dummyBuf);//dummy to clear write buffer
SSIDataPut(SSI0_BASE, 0x00);
SSIDataGet(SSI0_BASE, &dummyBuf);//dummy to clear write buffer
SSIDataPut(SSI0_BASE,
); //24 bits address0x00
SSIDataGet(SSI0_BASE, &dummyBuf);//dummy to clear write buffer
SSIDataPut(SSI0_BASE, 0x00);
SSIDataGet(SSI0_BASE, &dummyBuf);//dummy to clear write buffer
SSIDataPut(SSI0_BASE, 0x00);
SSIDataGet(SSI0_BASE, &data);//read data in 'data'
GPIOPinWrite(GPIO_PORTA_BASE, SSI_CS, SSI_CS);//chip select high
}
void buffer_write()
Df_ReadyBusy();
{
GPIOPinWrite(GPIO_PORTA_BASE, SSI_CS, 0); //chip select low
SSIDataPut(SSI0_BASE, 0x84); //read buffer 1
SSIDataGet(SSI0_BASE, &dummyBuf);//dummy to clear write buffer
SSIDataPut(SSI0_BASE, 0x00);
SSIDataGet(SSI0_BASE, &dummyBuf);//dummy to clear write buffer
SSIDataPut(SSI0_BASE,
); //24 bits address0x00
SSIDataGet(SSI0_BASE, &dummyBuf);//dummy to clear write buffer
SSIDataPut(SSI0_BASE, 0x00);
SSIDataGet(SSI0_BASE, &dummyBuf);//dummy to clear write buffer
SSIDataGet(SSI0_BASE, 0x41); // 'A' character
GPIOPinWrite(GPIO_PORTA_BASE, SSI_CS, SSI_CS);//chip select high
}
void Df_ReadyBusy()
{
uint8 byResult;
for(;;)
{
byResult = GetFlashStatus();
if(byResult & 0x80)
{
break;
}
}
Delay(2);
}
unsigned long GetFlashStatus()
{
uint8 ret;
unsigned long ret1;
GPIOPinWrite(GPIO_PORTA_BASE, SSI_CS, 0); //chip select low
SSIDataPut(SSI0_BASE, 0x57);
SSIDataGet(SSI0_BASE, &ret1);
ret=(uint8)ret1;
GPIOPinWrite(GPIO_PORTA_BASE, SSI_CS, SSI_CS);//chip select high
return ret;
}
My code is not working and it is hang in Df_ReadyBusy() function ,help me please................