This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

msp430F5329 is interfaced to 16gb sd card

Other Parts Discussed in Thread: MSP430F5329, MSP430WARE

HI All,

16 SD card is interface to msp430f5329 controller and able to read and write data using SPI and also FAT32 file system write is tested, able to created text file on SD card and data is able to write in text file single and no .of packets.

now my problem is re-open text file and writing is not happening, not understanding where am doing mistake.  

am using FAT file system example from  ti\MSP430Ware_3_50_00_04\examples\boards\MSP-EXP430F5529\MSP-EXP430F5529_UE_Demo_Software\Firmware\Source\FatFs example.

in F_write() function of ff.c  added one condition,  no.of packets to write greater than zero  

if (disk_write(fp->fs->drv, wbuff, sect, (BYTE)cc) != RES_OK)
ABORT(fp->fs, FR_DISK_ERR);
if(bytes>0)
sect +=1;

main program is :

 

WDTCTL = WDTPW + WDTCNTCL + WDTIS_3; // 512 ms for internal ref clock as clock source

initGpio();
initClock();
initScia0();
initScia1();
initspiB1();
initTimerA0();
initlcd();
initkey();
#ifdef SD_Card
P6OUT |= BIT3; //RS 485 Enable pin is high
sci1_msg("SD card testing .....\n\r");
status=disk_status();
if(status == 0) //SD card inserted
do{
status1=disk_initialize();
watchdogReset();
}while(status1!=0x00);
sci1_msg("Diskinitialization success.....\n\r");
P6OUT &= ~BIT3;

// checking FTA32 file system
f_mount(0,&FatFs);
//Data_write_into_SD_card();
if (f_open(&Fil, "newfile.txt", FA_WRITE | FA_CREATE_ALWAYS) == FR_OK) { // Create a file /

f_write(&Fil, sof,512, &bw,1);
f_write(&Fil,dataStore,512, &bw,1);

f_close(&Fil);

}

// again writing data to SD card in same file, now writing 100 times

if (f_open(&Fil, "newfile.txt",FA_OPEN_EXISTING |FA_WRITE) == FR_OK) { // Create a file /

for(i=0;i<100;i++)
{
f_write(&Fil, "pvt",512, &bw,1);
f_write(&Fil,dataStore,512, &bw,1);


} //End of for loop
f_close(&Fil);
}

#endif

every time 2nd time data only available on SD card, first time data is not available, thinking first time data is over writing to 2nd time data,

if i write single time, data is available on sd card.

thinking after sending f_close(&Fil); it is writing starting memory location means, In f_write() function Create a new cluster chain, may be is it creating issue?  

kindly help me to solve the problem.

  • Hi,

    so if I understood you correctly you are able to write to the SD card once and the data is available. But if you try writing a second time you cannot write. Is my understanding correct?
    Please clearly explain what scenarios you see in your application and describe the outcome of those scenarios.

    Besides that, did you already debug your code? Do you have an indication what is happening when you try to write a second time?
    Please help me understand what your actual issue is in a detailed description so that I can help you to troubleshoot the root cause.

    Thanks and best regards,
    Britta
  • Hi,

    could you test how it works with the unmodified ff.c?
  • Hi Britta Ruelander and Tomasz Kocon thanks for giving quick replay.

    Ruelander,
    my issue is data is writing in sd card using FAT32 file system, after sending f_close(), next time i write data in the same text file data is overwriting on previous data.
    Tomasz kocon,
    Tested with unmodified ff.c file also it is overwriting the previous data.

    my problem is solved,

    actually in f_open() function first and second time also using same parameters "FA_WRITE | FA_CREATE_ALWAYS "
    changed second time "FA_OPEN_EXISTING|FA_WRITE"

    in f_open() function fp->fs always assign to zero(fp->fs =0), in second time calling f_open() function not exciting fp->fs =0

    end of f_open() function fp->fs = dj.fs; fp->id = dj.fs->id , first time fs values are overwriting with dj.fs values,

    and also passing LEAVE_FF(dj.fs, res); here also fp->fs values are overwriting.

    so second time am calling f_open() function above thing are not executing.

**Attention** This is a public forum