void sd_card_mount_card_capacity (void) { if(f_mount(&SDFatFS, (TCHAR const*)SDPath, 1) != FR_OK) { SendString("SD card mounting error"); Error_Handler(); } else { #if 1 { uint8_t buf[30]; sprintf(buf,"SD_Cap %llu \n\r", ((unsigned long long)hsd1.SdCard.BlockSize * hsd1.SdCard.BlockNbr)); SendString(buf); // Display capacity } #endif } } void sd_card_write_read (void) { FRESULT res; /* FatFs function common result code */ uint8_t sd_state = MSD_OK; if((WriteCnt == 0) && (Stop_Read_Write_Flag == 0)) { if(f_open(&SDFile, "DATA.TXT", FA_CREATE_ALWAYS | FA_WRITE) != FR_OK) { Error_Handler(); } else { res = f_write(&SDFile, §or_d[0], 512, &byteswritten); if((res == FR_OK) && (byteswritten > 0)) { f_close(&SDFile); } } Stop_Read_Write_Flag = 1; WriteCnt = WriteCnt + 1; } else if((WriteCnt >= 1) && (Stop_Read_Write_Flag == 1)) { if(f_open(&SDFile, "DATA.TXT", FA_OPEN_EXISTING |FA_WRITE | FA_OPEN_APPEND) != FR_OK) { Error_Handler(); } else { res = f_write(&SDFile, §or_d[0], 512, &byteswritten); if((res == FR_OK) && (byteswritten > 0)) { datawritecnt++; } } } WriteCnt = WriteCnt + 1; if(WriteCnt>=2073600) //This count is for the 8days recording { Stop_Read_Write_Flag = 2; //Stop writing file } }