lpcware

need help writing to sd card

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by CortexM3 on Mon Jun 03 05:32:51 MST 2013
hi im trying to interface a sd card to lpc1769.im trying to write a simple text to the sd card but nothing seems to be working. any help would be appreciated.

int main (void)
{
    DSTATUS errd;                           //error var for Disk
    FRESULT res;                            //error var vor FAT
    char *ptr;                                     //path pointer
    UINT btw, cnt = 8*512;                //Counter array
    char Buff[8*512];                      //FAT buffer
    FATFS Fatfs[0];                           //Fat file system var
    FIL File;                                       //File var

    init_GPIO();
    GPIO_SetDir(2, 1<<13, 1);
    GPIO_SetValue(2, 1<<13);
    int i;
    init_ssp();                           
    Timer0_Wait(500);
    res = f_mount(0, &Fatfs[0]);
    errd = disk_initialize(0);



    while(1)
    {
        res = f_open(&File, "data.txt", FA_WRITE);

        for (i=0; i < 50; i++)
        {
          res = f_write(&File,"Hello world ", 11,&btw ) ;
          Timer0_Wait(10);
        }
          res = f_close(&File)  ;
        }

}

Outcomes