This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

SD card

hello dear all,
I have a problem in create a text file in SD card. here is my code. it doesn't create text file. i work on LPC1768. would you tell me what is the problem with my code?

FATFS fs;         /* Work area (file system object) for logical drive */
FIL fsrc;         /* file objects */
FRESULT res;
UINT br;
int SD_TotalSize(void);
char path[512]="0:";
uint8_t textFileBuffer[] = "Thank \r\n";
FRESULT scan_files (char* path);

f_mount(0,&fs);

 res = f_open( &fsrc , "0:/Demo.TXT" , FA_CREATE_NEW | FA_WRITE);

    if ( res == FR_OK )
    {
      /* Write buffer to file */
      res = f_write(&fsrc, textFileBuffer, sizeof(textFileBuffer), &br);

          printf("Demo.TXT successfully created");

      /*close file */
      f_close(&fsrc);
    }
    else if ( res == FR_EXIST )
    {
          printf("Demo.TXT created in the disk");
    }

        scan_files(path);
        SD_TotalSize();

    /* Infinite loop */
    while (1)
                {}
}

Parents Reply Children
  • Yes, there are real big market for fencing broken code. Decide if the coders here are actually capable of writing and debugging their own software.

    Break it down to the SD layer, and the diskio.c layer, which have probably both been lifted from other sources. Prove that the SD code is actually functional, and can read/write sector(s) properly. If that doesn't work properly, or handle/manage errors effectively, nothing you layer on top of it is going to be successful.

  • Yeah - right!

    You're using an open-source library, and your code doesn't even work - clearly a prime target for theft!!

    And yet you expect people to fix your broken code for free?!

    So how about taking the original code you posted, and using that to demonstrate the problem?

    Add the return value checks.

    See where it's failing,

  • i don't write "I can not show all the code. Someone will steel it." !!!!!
    is it possible someone steal my name?!! it's so strange!