Hi. I need some help. I am required to do a project using TIVA C series launchpad and its LCD booster pack (Kentec LCD display). Currently facing a problem of storing data into a SD card. Basically, I need to store data into a SD card using SSI, in this case I am using SSI3. With just TIVA launchpad itself, I was successfully stored a list of data into SD card by using the push button 1 from the TIVA launchpad board. (When I press the push button 1, the data will be storing into the SD card.) After that, I tried using the Kentec LCD display together with the TIVA launchpad to store the data into the SD card. I made a push button widget on the LCD. When I press the widget, the data will be storing into the SD card. So now, the problem is, when I press the widget, the LCD will goes white screen slowly. After a few second, the screen will be completely turned white. But, the widget can still be pressed, and the data is still storing into the SD card, just without display.
I am using CCS v6.
I included the third_party/ mmc-dk-tm4c123g port.
This is my code:
////////////////////////
#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include "inc/tm4c123gh6pm.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "grlib/grlib.h"
#include "grlib/widget.h"
#include "grlib/canvas.h"
#include "grlib/pushbutton.h"
#include "Kentec320x240x16_ssd2119_8bit.h"
#include "touch.h"
#include "driverlib/fpu.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include <string.h>
#include "fatfs/src/ff.h"
#include "fatfs/src/diskio.h"
extern tCanvasWidget g_sBackground1;
extern tPushButtonWidget g_sPushBtn1;
tContext sContext;
#ifdef DEBUG
void__error__(char *pcFilename, uint32_t ulLine)
{
}
#endif
void writeSD(char *file, char *data);
void Press(tWidget *pWidget);
unsigned int Txt_Name,count,usBytesWrite;
static FATFS g_sFatFs; // The following are data structures used by FatFs.
static FIL g_sFileObject;
char *Name[250]={"1.txt", "2.txt", "3.txt", "4.txt", "5.txt",
"6.txt", "7.txt", "8.txt", "9.txt", "10.txt"};
char *display[11]={"0 ","1 ","2 ","3 ","4 ","5 ","6 ","7 ","8 ","9 ","10 "};
char *Next_Line = "\r\n";
Canvas(g_sBackground1, WIDGET_ROOT, 0, &g_sPushBtn1,
&g_sKentec320x240x16_SSD2119, 110, 100, 100, 40,
CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0);
RectangularButton(g_sPushBtn1, &g_sBackground1, 0, 0,
&g_sKentec320x240x16_SSD2119, 110, 100, 100, 40,
(PB_STYLE_OUTLINE | PB_STYLE_TEXT_OPAQUE | PB_STYLE_TEXT |
PB_STYLE_FILL), ClrRed, ClrRed, ClrRed, ClrWhite,
g_psFontCmss22b, "Press", 0, 0, 0, 0, Press);
void Press(tWidget *pWidget)
{
f_mount(0, &g_sFatFs);
while(f_open(&g_sFileObject, Name[Txt_Name], FA_CREATE_NEW | FA_WRITE)==FR_EXIST && Txt_Name<=9)//if the file name exist
{
Txt_Name++;
}
if(Txt_Name>=10) //if more than 10 files exist
{
//do nothing
}
else
{
for(count=0;count<=10;count++)
{
writeSD(Name[Txt_Name], display[count]); //storing data into sd
}
}
Txt_Name=0;
count=0;
}
int main(void)
{
SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
Kentec320x240x16_SSD2119Init();
TouchScreenInit();//Using ADC0
TouchScreenCallbackSet(WidgetPointerMessage);
GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI3); //for sd card
GPIOPinConfigure(GPIO_PD0_SSI3CLK);
GPIOPinConfigure(GPIO_PD1_SSI3FSS);
GPIOPinConfigure(GPIO_PD2_SSI3RX);
GPIOPinConfigure(GPIO_PD3_SSI3TX);
WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sBackground1);
WidgetPaint((tWidget *)&g_sBackground1);
GrContextForegroundSet(&sContext, ClrLightCyan);
while(1)
{
WidgetMessageQueueProcess();
}
}
void writeSD(char *file, char *data)
{
if (f_open(&g_sFileObject, file, FA_CREATE_NEW | FA_WRITE)==FR_OK)
{
if(f_write(&g_sFileObject,data,strlen(data),&usBytesWrite)==FR_OK) // write file
{
if(f_write(&g_sFileObject,Next_Line,strlen(Next_Line),&usBytesWrite)==FR_OK)
{
f_sync(&g_sFileObject);
}
}
}
else
{
if (f_open(&g_sFileObject, file, FA_CREATE_NEW | FA_WRITE)==FR_EXIST) // if the file is exist
{
if (f_open(&g_sFileObject, file, FA_OPEN_EXISTING | FA_WRITE)==FR_OK)
{
if(f_lseek(&g_sFileObject, g_sFileObject.fsize)==FR_OK) // write file
{
if(f_write(&g_sFileObject,data,strlen(data),&usBytesWrite)==FR_OK)
{
if(f_write(&g_sFileObject,Next_Line,strlen(Next_Line),&usBytesWrite)==FR_OK)
{
f_close(&g_sFileObject);
}
}
}
}
}
}
}
//////////////////////
Anyone know what is going on?
Thanks in advance.