Part Number: MSP430FR5994
Tool/software: Code Composer Studio
hello
I wrote a code which supposed to create files on the SD card, but the actual code is not working. I'm} remplace
I'm using SDHC 16GB
there no error while compile . Is there any option to overcom this , like kind of node application which i can control the SD card with?
hier is the code :
#define MAX_BUF_SIZE 32
#define FRESULT
#define FA_READ 0x01
#define FA_OPEN_EXISTING 0x00
#define FA__ERROR 0x80
#define CLOCK_FREQ 8000000
#define DESIRED_SPI_FREQ 400000
#if !_FS_READONLY
#define FA_WRITE 0x02
#define FA_CREATE_NEW 0x04
#define FA_CREATE_ALWAYS 0x08
#define FA_OPEN_ALWAYS 0x10
#define FA__WRITTEN 0x20
#define FA__DIRTY 0x40
#endif
#define MAX_FILE_LEN 12
#define FRESULT
#ifdef __cplusplus
extern "C" {
#endif
char fileName[12][MAX_FILE_LEN];
typedef unsigned char BYTE;
typedef unsigned int UINT;
//extern int mode=7;
//extern int noSDCard=0;
//void sdcardLog(void);
//void sendDataSDCard(void);
SDCardLib sdCardLib;
uint8_t fileNum = 0;
#if defined(__IAR_SYSTEMS_ICC__)
#pragma location = 0x9000
__no_init uint16_t dataArray[12289];
#endif
#define MAX_BUF_SIZE 32
char buffer[212];
char bufsize[32];
FRESULT res; /* Result code */
FIL fil; /* File object */
uint8_t test[7]="1234GO";
uint16_t br;
uint16_t toReadSize = bufsize;
const char filName[] ="demo.txt";
// FatFs Static Variables
extern void SDCard_setCSLow(void);
extern SDCardLib_Status SDCard_detectCard(void);
extern void SDCard_init(void);
extern SDCardLib_Interface sdIntf_MSP430FR5994LP;
int main(void)
{
PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode
SDCard_init();
SDCard_setCSHigh();
// WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
SDCardLib_Status SDCard_detectCard();
{
//Pull-up resistor for SD detect pin
//Pulled low if SD is inserted
GPIO_setAsInputPinWithPullUpResistor(GPIO_PORT_P7, GPIO_PIN2);
if (GPIO_getInputPinValue(GPIO_PORT_P7, GPIO_PIN2)==0) {
P1DIR |= 0x01; // Set P1.0 to output direction
for(;;) {
volatile unsigned int i; // volatile to prevent optimization
P1OUT ^= 0x01; // Toggle P1.0 using exclusive-OR
i = 1000; // SW Delay
do i--;
while(i != 0);
}
printf("no sd card...");
return SDCARDLIB_STATUS_NOT_PRESENT;
}
else {
return SDCARDLIB_STATUS_PRESENT;
}
}
if(SDCARDLIB_STATUS_PRESENT==true){
GPIO_setAsInputPinWithPullUpLowResistor(GPIO_PORT_P7, GPIO_PIN2);
// Open file
res = f_open(&fil, fileName, FA_WRITE | FA_CREATE_ALWAYS);
if (res!= FR_OK)
{
goto WRITE_EXIT;
}
UINT FilWritten;
// Write to file
res = f_write(&fil, test, sizeof(test),&FilWritten);
if (res!=FR_NO_FILE)
{
f_puts(&fil, "GO");
f_putc(&fil, "2390123");
}
goto WRITE_EXIT;
}
WRITE_EXIT:
// Close the file
f_close(&fil);
return res;
}