Skip to content

Instantly share code, notes, and snippets.

@SaheblalBagwan
Last active September 3, 2019 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SaheblalBagwan/c2dfdada2415660966bf795fa8bdc149 to your computer and use it in GitHub Desktop.
Save SaheblalBagwan/c2dfdada2415660966bf795fa8bdc149 to your computer and use it in GitHub Desktop.
#include <lpc17xx.h>
#include "sdcard.h"
#include "uart.h"
#include "fat32.h"
#include "stdutils.h"
#include "delay.h"
#include "spi.h"
int main()
{
uint8_t returnStatus,sdcardType,i=0;
fileConfig_st *srcFilePtr;
char str[]={"Hello World, Writing data to SD CARD using 1768"};
SystemInit();
UART0_Init(9600);
returnStatus = SD_Init(&sdcardType);
if(returnStatus)
{
if(returnStatus == SDCARD_NOT_DETECTED)
{
UART0_TxString("\n\r SD card not detected..");
}
else if(returnStatus == SDCARD_INIT_FAILED)
{
UART0_TxString("\n\r Card Initialization failed..");
}
else if(returnStatus == SDCARD_FAT_INVALID)
{
UART0_TxString("\n\r Invalid Fat filesystem");
}
while(1);
}
else
{
UART0_TxString("\n\rSD Card Detected!");
}
srcFilePtr = FILE_Open("test.txt",WRITE,&returnStatus);
if(srcFilePtr == 0)
{
UART0_TxString("\n\rFile Opening Failed");
}
else
{
UART0_TxString("\n\rWriting Data to file");
while(str[i])
{
FILE_PutCh(srcFilePtr,str[i++]);
}
FILE_PutCh(srcFilePtr,EOF);
UART0_TxString("\n\rData saved to file, closing the file.");
FILE_Close(srcFilePtr);
}
while(1);
}// End of main
@vrmadishetty
Copy link

vrmadishetty commented Aug 31, 2019

Hello Sir,

Great work. This code is working as expected.
But there are some issues observed after every cluster (512*64 bytes) complete. If my writing buffer is crossing the cluster, the garbage is stored in every cluster change.
Cluster

How to clear the writing garbage to the sd card at cluster change ?
Also this code works better for writing only single file. Multiple files cause corrupting the sd card.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment