Hello everyone,
I'm having a trouble with the f_write function of the tiva C fat library, when I run mi code there is no errors, and I can debug it, so when I put my Launchpad TM4C123G in my application circuit the file is created in the SD Card but it have not write any of the headers in the file. I have seen that after I extract the SD card and I put it in the card port of my laptop. Besides, when I tried to open de file created a message appears, it says:
“The format and file extension "testfile.xls" does not match. The file is damaged or can not be safe. Do not open it unless it trusts its origin. Do you want to open it anyway?
yes no help”
So I clic on yes, I open the file, but nothing was written. I verified the f_write function in the tivaware folder and I wrote it in my code according of the structure. I am using Code Composer Studio 6.
This is a part of my code related with SD card:
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include "inc/hw_ints.h"
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "inc/hw_gpio.h"
#include "inc/hw_hibernate.h"
#include "inc/hw_timer.h"
#include "driverlib/adc.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/timer.h"
#include "driverlib/hibernate.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "driverlib/uart.h"
#include "driverlib/adc.h"
#include "grlib/grlib.h"
#include "utils/cmdline.h"
#include "utils/uartstdio.h"
#include "utils/ustdlib.h"
#include "fatfs/src/ff.h"
#include "fatfs/src/diskio.h"
// The following are data structures used by FatFs.
//*****************************************************************************
static FATFS g_sFatFs;
//*****************************************************************************
// This is the handler for this SysTick interrupt. FatFs requires a timer tick
// every 10 ms for internal timing purposes.
//*****************************************************************************
void
SysTickHandler(void)
{ // Call the FatFs tick timer.
disk_timerproc();
}
void ConfigureSDCard(void)
{
// Enable the peripherals for SDcard
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
// Configure SysTick for a 100Hz interrupt. The FatFs driver wants a 10 ms tick.
ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100);
ROM_SysTickEnable();
ROM_SysTickIntEnable();
// Enable Interrupts
ROM_IntMasterEnable();
// Mount the file system, using logical disk 0.
f_mount(0, &g_sFatFs);
}
void StartSDCard(void)
{
uint32_t count ;
//uint32_t i;
ConfigureSDCard();
FIL fil;
f_open(&fil, "testfile.xls", FA_OPEN_ALWAYS|FA_WRITE|FA_READ);
f_write(&fil, "Temperature(°C)\t", 17, &count);
f_write(&fil, "Battery Level(V)\t", 18, &count);
f_write(&fil, "Solar Panel Voltage(V)\t", 24, &count);
}
int main(void)
{
while(1)
{
StartSDCard();
}
}
That is the connection between my SD Card and the SSI port of my Launchpad:
Thanks for your help.