Hello sir,
I'm using the tiva tm4c123 launchpad. To read and write data from/into an Serial EEPROM i'm using SSI communication. I have attached my program below. while reading an eeprom i always got the value of 0x00 instead of the particular value that i have written. And I dont know that where i did the mistake either in transmit part or receive part. I'm using 25c040 EEPROM
void ssi_init()
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
SysCtlPeripheralReset(SYSCTL_PERIPH_SSI0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_5);//TX, CS, SCK are setted as output
GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_4); // RX is setted as input
//Pin Configuration
GPIOPinConfigure(GPIO_PA2_SSI0CLK);
GPIOPinConfigure(GPIO_PA3_SSI0FSS);
GPIOPinConfigure(GPIO_PA4_SSI0RX);
GPIOPinConfigure(GPIO_PA5_SSI0TX);
GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5);
SSIClockSourceSet(SSI0_BASE, SSI_CLOCK_SYSTEM); // sets the system clock as the source of clock
SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, 125000, 8);// defines base, System clk, Mode 0 = SPH = SPO = 0,Master, 125 KHz, no. of bits = 8 = 1 byte transfer
SSIEnable(SSI0_BASE); // enables SSI
}
void eeprom_write(unsigned int adr, unsigned char dat)
{
SysCtlDelay(100000);
GPIOPinWrite(GPIO_PORTA_BASE,CS,0xff);// Made the SS = 1
SysCtlDelay(100000);
GPIOPinWrite(GPIO_PORTA_BASE,CS,0x00); //Dropped down SS to select slave 25C040
SSIDataPut(SSI0_BASE,0x06); // sent the 0x06 as the required Write enable WREN command as per microchip Datasheet
while(SSIBusy(SSI0_BASE)); //Wait until it transmit
GPIOPinWrite(GPIO_PORTA_BASE,CS,0xff); // Pulsed high SS
SysCtlDelay(100000);
GPIOPinWrite(GPIO_PORTA_BASE,CS,0); // pulled low SS for sending the remaining commands
SSIDataPut(SSI0_BASE,0x0A); // Cmd for Write cmd to SPI EEPROM as per datasheet
SSIDataPut(SSI0_BASE,adr); // Mem. location inside EEPROM
SSIDataPut(SSI0_BASE,dat); // test data
while(SSIBusy(SSI0_BASE)); // wait till bzy
GPIOPinWrite(GPIO_PORTA_BASE,CS,0xff); // pulled high to complete write process
SysCtlDelay(1000000); // Twc
GPIOPinWrite(GPIO_PORTA_BASE, CS, 0); //CS = 0;
SSIDataPut(SSI0_BASE,0x02); while(SSIBusy(SSI0_BASE));//spi_WR(0x04);
GPIOPinWrite(GPIO_PORTA_BASE, CS, 8); //CS = 1;
SysCtlDelay(1000000);
}
unsigned char eeprom_read(unsigned int adr)
{
SysCtlDelay(100000);
GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,0xff); // Made the SS = 1
SysCtlDelay(100000);
GPIOPinWrite(GPIO_PORTA_BASE, CS, 0); //CS = 0;
SSIDataPut(SSI0_BASE,0x0B); // Cmd for read cmd to SPI EEPROM as per datasheet
SSIDataPut(SSI0_BASE, adr); while(SSIBusy(SSI0_BASE)); //Mem. location inside EEPROM
SSIDataGet(SSI0_BASE,reply); // Reading the memory location inside eeprom
GPIOPinWrite(GPIO_PORTA_BASE, CS, 8); //CS = 1;
return(reply); //return the data present in ssi RX reg
}
void main()
{
//Enable the periphral...
ssi_init(); delay();// 100ms delay
eeprom_write(0,10); delay();// 100ms delay
// here 0 is Address location in eeprom and 10 is data to be written
while(1)
{
unsigned char a= eeprom_read(0);
display(a);
}}