This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

tm4c129x eeprom with spi question

hi 

i  have a question about spi with eeprom.

there is a problem about reading data what i wrote.

i think writing to eeprom is working.

but it couldn't read the data what i wrote using random value.

what is the problem .. ?

#include <stdbool.h>
#include <stdint.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include "inc/hw_memmap.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/ssi.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "inc/hw_ints.h"
#include "inc/hw_ssi.h"
#include "inc/hw_types.h"
#include "utils/uartstdio.h"
#include "inc/hw_uart.h"
#include "utils/uartstdio.c"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"

void Config_Master(uint32_t clk);
void Read_DATA(uint32_t ui32Base, uint32_t ui32Address, uint8_t *receive_DATA);
void Write_page(uint32_t ui32Base, uint32_t ui32Address, uint8_t *send_DATA);
void EraseSector(uint32_t ui32Base, uint32_t ui32Address);
uint32_t Read_statusReg(uint32_t ui32Base);

int ui32count=1;

int main(void) {

uint32_t ui32SysClk;
static uint32_t dummy[3] = {0};


int i = 0, j = 0,k=0, intData0 = 0, intData1 = 0, getString = 0, flag=0;
char c, strData0[10];
char hexa[10];
char values[5];
char check=0;
char *ptr;
uint32_t address;
unsigned long ulAddr,ulValTemp;
uint32_t value=10;
uint8_t ui8TxData[32];
uint8_t ui8RxData[32];
// define data that you want to receive


// set the system clock to be 25MHz
ui32SysClk =SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 25000000);

//Configure Master Module and system Parameters.
Config_Master(ui32SysClk);


SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);

GPIOPinTypeGPIOOutput(GPIO_PORTK_BASE, GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);


GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTConfigSetExpClk(UART0_BASE, ui32SysClk, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
UARTEnable(UART0_BASE);
UARTStdioConfig(0, 115200, ui32SysClk);


while(1) {
if(UARTCharsAvail(UART0_BASE)) {
c = UARTCharGet(UART0_BASE);
UARTCharPut(UART0_BASE, c);
if (!getString) strData0[i++] = c;
//else if(!flag) values[k++]=c;
else {if(check==2){values[k++]=c; check=0;} else hexa[j++] = c;}
if(c == ' ') {getString = !getString; check++;}

if(c == 0x0D) {
UARTCharPut(UART0_BASE, 0x0A);
strData0[i - 1] = '\0';
hexa[j-1]='\0';
values[k-1]='\0';


if(strData0[0]=='r'){

address = strtoul(hexa,&ptr,10);

UARTprintf("\n you entered address is : %08x\n",address);
//UARTprintf("you entered r %s - , %c %c %c\n",hexa,hexa[0],hexa[1],hexa[2]);

Read_DATA(SSI3_BASE,address,ui8RxData);

for (i = 0; i < 32; i++) {
UARTprintf("0x%x ", ui8RxData[i]);
if (i != 0 && i % 16 == 0) UARTprintf("\n");
}

}

else if(strData0[0]=='w'){

address = strtoul(hexa,&ptr,10);
value=atoi(values);
srand(value);

UARTprintf("you entered w %s %d\n",hexa,value);
for (i = 0; i < 32; i++){
ui8TxData[i] = (uint8_t) (rand() % 256);
UARTprintf("ui8TxData[%d] = %x\n",i,ui8TxData[i]);
}
Write_page(SSI3_BASE,address,ui8TxData);


}
else if(strData0[0]=='e'){
UARTprintf("you entered e %s\n",hexa);
//address = strtoul(hexa,&ptr,10);
//EraseSector(SSI3_BASE,address);

}


i = 0; j=0; k=0; check=0;
getString = !getString;

}// if(c == 0x0D)

} //if(UARTCharsAvail(UART0_BASE))
} // while(1)


return 0;
}
void Config_Master(uint32_t clk){

// Enable system peripheral
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOQ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI3);

GPIOPinConfigure(GPIO_PQ0_SSI3CLK);
GPIOPinConfigure(GPIO_PQ1_SSI3FSS);
GPIOPinConfigure(GPIO_PQ2_SSI3XDAT0);

GPIOPinTypeSSI(GPIO_PORTQ_BASE,GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2);

GPIOPinConfigure(GPIO_PF0_SSI3XDAT1);
GPIOPinConfigure(GPIO_PF4_SSI3XDAT2);
GPIOPinConfigure(GPIO_PF5_SSI3XDAT3);

GPIOPinTypeSSI(GPIO_PORTF_BASE,GPIO_PIN_0 | GPIO_PIN_4 | GPIO_PIN_5);

// Provide colck to the module.
SSIConfigSetExpClk(SSI3_BASE, clk, SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, 1000000, 8);

SSIAdvModeSet(SSI3_BASE,SSI_ADV_MODE_WRITE);
SSIAdvFrameHoldEnable(SSI3_BASE);
// SSI Module 0 Enable

// SysCtlPeripheralReset(SYSCTL_PERIPH_SSI3);
SSIEnable(SSI3_BASE);


}
void EraseSector(uint32_t ui32Base, uint32_t ui32Address){

SSIAdvModeSet(ui32Base,SSI_ADV_MODE_WRITE);

SSIDataPut(ui32Base,0x20);
SSIDataPut(ui32Base, (ui32Address >> 16) & 0xff);
SSIDataPut(ui32Base, (ui32Address >> 8) & 0xff);
SSIAdvDataPutFrameEnd(ui32Base, ui32Address & 0xff);
while(SSIBusy(ui32Base));

}

uint32_t Read_statusReg(uint32_t ui32Base){

uint32_t ui32Data;

while(SSIDataGetNonBlocking(ui32Base,&ui32Data)!=0);

SSIAdvModeSet(ui32Base,SSI_ADV_MODE_WRITE);
SSIDataPut(ui32Base,0x05);
SSIAdvModeSet(ui32Base,SSI_ADV_MODE_READ_WRITE);
SSIAdvDataPutFrameEnd(ui32Base,0);
SSIDataGet(ui32Base,&ui32Data);

return ui32Data;

}
void Write_page(uint32_t ui32Base, uint32_t ui32Address, uint8_t *send_DATA){

uint32_t getstatus;

UARTprintf("success enter the function In section 1\n");

uint32_t ui32Count = 32;
uint8_t get;
int test=32;

//set EAR register
SSIAdvModeSet(ui32Base, SSI_ADV_MODE_WRITE);
SSIDataPut(ui32Base, 0xc5);
SSIDataPut(ui32Base, (ui32Address >> 24) & 0xff);

// send the WREN command
SSIAdvModeSet(ui32Base, SSI_ADV_MODE_WRITE);
//SSIAdvFrameHoldEnable(ui32Base);
SSIAdvDataPutFrameEnd(ui32Base, 0x06);


//while(SSIBusy(ui32Base));
getstatus = Read_statusReg(ui32Base);

while((getstatus & 0x01) == 0x01) ;
/*
getstatus = Read_statusReg(ui32Base);
while((getstatus & 0x01) != 0x01)
{
getstatus = Read_statusReg(ui32Base);
}
*/


UARTprintf("success enter the function In section 2\n");


SSIAdvModeSet(ui32Base,SSI_ADV_MODE_WRITE);
//SSIAdvFrameHoldEnable(SSI3_BASE);

SSIDataPut(ui32Base,0x02); // send the Page Program Command
SSIDataPut(ui32Base, (ui32Address >> 16) & 0xff);
//UARTprintf("addres >> 16 & 0xff \n : %x",(ui32Address >> 16) & 0xff);
SSIDataPut(ui32Base, (ui32Address >> 8) & 0xff);
//UARTprintf("addres >> 8 & 0xff \n : %x",(ui32Address >> 8) & 0xff);
SSIDataPut(ui32Base, ui32Address & 0xff);
//UARTprintf("addres & 0xff \n : %x",ui32Address&0xff);
while (ui32Count-- != 1){

//get=*send_DATA;
SSIDataPut(ui32Base, *send_DATA++);
//UARTprintf("index 0 to 31 %x \n",get);
//UARTprintf("index 0 to 31",*send_DATA);
//UARTprintf("index : %d value : [%c]\n",ui32Count,send_DATA[ui32Count]);
}

// write last data
SSIAdvDataPutFrameEnd(ui32Base, *send_DATA);


}
void Read_DATA(uint32_t ui32Base, uint32_t ui32Address, uint8_t *receive_DATA){

uint32_t ui32Trash;
uint32_t ui32Data;
uint32_t ui32Count=32;

// WREAR command
SSIAdvModeSet(ui32Base, SSI_ADV_MODE_WRITE);
SSIDataPut(ui32Base, 0xc5);
SSIDataPut(ui32Base, (ui32Address >> 24) & 0xff);

while(SSIDataGetNonBlocking(ui32Base, &ui32Trash) != 0); // Get the useless data

SSIAdvModeSet(ui32Base,SSI_ADV_MODE_WRITE);
// SSIAdvFrameHoldEnable(ui32Base);

SSIDataPut(ui32Base,0x03);

SSIDataPut(ui32Base, (ui32Address >> 16) & 0xff);
//UARTprintf("addres >> 16 & 0xff \n : %x",(ui32Address >> 16) & 0xff);
SSIDataPut(ui32Base, (ui32Address >> 8) & 0xff);
//UARTprintf("addres >>8 & 0xff \n : %x",(ui32Address >> 8) & 0xff);
SSIDataPut(ui32Base, ui32Address & 0xff);
//UARTprintf("addres&0xff \n : %x",ui32Address&0xff);

SSIAdvModeSet(ui32Base,SSI_ADV_MODE_READ_WRITE);
while (1) {
// read last data
if (ui32Count == 1) {
SSIAdvDataPutFrameEnd(ui32Base, 0);
SSIDataGet(ui32Base, &ui32Data);
*receive_DATA = ui32Data & 0xff;
break;
}
// read data
else {
SSIDataPut(ui32Base, 0);
SSIDataGet(ui32Base, &ui32Data);
*receive_DATA++ = ui32Data & 0xff;
//UARTprintf("0x%x \n",*receive_DATA);
ui32Count--;
}
}


}

  • Hello Won,

    That is a big code to comment on. I would suggest the following to be reviewed (may or may not relate to the problem)

    1. SysCtlClockFreqSet is for generating 25MHz from VCO of 480MHz. That is a divider pf 19.2 We do not support fractional dividers on the system clock
    2. The SSI3 has been configured twice for the IO's. Why so?
    3. PF0 is a locked pin. You would need to unlock it before changing the Port Muxing.

    Regards
    Amit