Last active
September 3, 2019 06:18
-
-
Save SaheblalBagwan/c2dfdada2415660966bf795fa8bdc149 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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.