sd卡建立文件夹后再建立文件,建立文件时返回值说找不到路径?

2019-07-20 23:54发布

[mw_shl_code=c,true]#define __SHOW_SD_PROCEDURE__ RTC_TimeTypeDef RTC_TimeStruct; //__align(8) 8字节对其 RTC_DateTypeDef RTC_DateStruct; char FileDirName[16]; int j = 0; DIR FileDir; DIR* CreateNewFileDir(void) { sprintf(FileDirName, "/%02d-%2d-%2d",RTC_DateStruct.RTC_Year, RTC_DateStruct.RTC_Month, RTC_DateStruct.RTC_Date); f_mkdir(FileDirName); //以当前的日期创建一个文件夹 } static int i = 0; char FileName[64]; char CntBuf[64]; u8 res_open = 1; int open = 0; char date[16]; char time[16]; FIL File; FIL* CreateNewFile(void) { sprintf(FileName, "/%02d-%2d-%2d/%02d-%2d-%2d.txt", RTC_DateStruct.RTC_Year, RTC_DateStruct.RTC_Month, RTC_DateStruct.RTC_Date, RTC_TimeStruct.RTC_Hours, RTC_TimeStruct.RTC_Minutes, RTC_TimeStruct.RTC_Seconds); sprintf(date, "Date: %02d:%02d:%02d",RTC_DateStruct.RTC_Year,RTC_DateStruct.RTC_Month,RTC_DateStruct.RTC_Date); sprintf(time, "Time: %02d:%02d:%02d",RTC_TimeStruct.RTC_Hours,RTC_TimeStruct.RTC_Minutes,RTC_TimeStruct.RTC_Seconds); LCD_ShowString(60, 80, 210, 16, 16, date); LCD_ShowString(60, 110, 210, 16, 16, time); while(res_open!=0) { res_open = f_open(&File, FileName, FA_OPEN_ALWAYS | FA_WRITE ); if(++open > 2) { sprintf(CntBuf, "f_open = %d", res_open); LCD_ShowString(60, 50, 210, 16, 16, CntBuf); } } res_open = 1; open = 0; f_lseek(&File, 0); #ifdef __SHOW_SD_PROCEDURE__ LCD_ShowString(60, 140, 210, 16, 16, FileName); #endif LCD_ShowString(60, 170, 210, 16, 16, "CreateNewFile = "); LCD_ShowNum(200, 170, ++i, 8, 16); return &File; } #define FILE_BLOCK_CNT 20 int FileBlockCnt = 0; int FileCnt = 0; int NowDate=0; int main(void) { char CntBuf[64]; FIL *SDFile = NULL; //------------------------------- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置系统中断优先级分组2 //------------------------------- delay_init(168); // 初始化延时函数 uart_init(115200); // 初始化串口波特率为115200 LED_Init(); // 初始化LED LCD_Init(); // LCD初始化 RS485_Init(115200); // 初始化RS485串口2 RTC_Set_WakeUp(RTC_WakeUpClock_CK_SPRE_16bits, 0); // 配置WAKE UP中断,1秒钟中断一次 IWDG_Init(4, 2500); //与分频数为64,重载值为2500,溢出时间为5s exfuns_init(); //为fatfs相关变量申请内存 usmart_dev.init(72); my_mem_init(SRAMIN); //初始化内部内存池 SD_InitializeCards(); f_mount(fs[0], "0:", 1); //注册工作区 // //----------------------------- while(1) { if(QueueFullWithData) { if(FileBlockCnt == 0) { IWDG_Feed(); //喂狗 RTC_GetDate(RTC_Format_BIN, &RTC_DateStruct); RTC_GetTime(RTC_Format_BIN, &RTC_TimeStruct); if (NowDate!=RTC_DateStruct.RTC_Date) { CreateNewFileDir(); NowDate = RTC_DateStruct.RTC_Date; } SDFile = CreateNewFile(); IWDG_Feed(); //喂狗 //sd卡存储的内容越多,打开的时间越慢 } f_write(SDFile, QueueFullWithData, QUEUE_SIZE, (UINT*)&bw); delay_ms(10); QueueFullWithData = NULL; LCD_ShowString(60, 200, 210, 16, 16, "Saved File Block = "); LCD_ShowNum(200, 200, ++FileBlockCnt, 8, 16); if(FileBlockCnt == FILE_BLOCK_CNT) { f_close(SDFile); FileBlockCnt = 0; LCD_ShowString(60, 230, 210, 16, 16, "Saved File Cnt = "); LCD_ShowNum(200, 230, ++FileCnt, 8, 16); } } IWDG_Feed(); //喂狗 } }[/mw_shl_code] [mw_shl_code=c,true]建立好文件夹以后,往文件夹里面建立txt文件,结果返回值说找不到路径,请问是哪里有错了?[/mw_shl_code]
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。