实验原理:

  STM32F429上带有SDIO控制器,GMT43液晶模块上将SDIO连接到TF卡座。本实验

将Micro SD卡插入TF卡座上即可。通过FATFS创建test.txt文件,并且写入数据0-255,然后

读出并显示在液晶屏上。

示例截图:

【GMT43智能液晶模块】例程十三:FATFS实验——文件操作-LMLPHP

【GMT43智能液晶模块】例程十三:FATFS实验——文件操作-LMLPHP

源代码下载链接:

链接:https://pan.baidu.com/s/1raoiNl6 密码:5w39

GMT43购买链接:

【GMT43智能液晶模块】例程十三:FATFS实验——文件操作-LMLPHP

【GMT43智能液晶模块】例程十三:FATFS实验——文件操作-LMLPHP

核心代码:

int main(void)
{
FRESULT res; rcc.initialize();
ads7843.initialize();
SDRAM_Init();
SDRAM_GPIOConfig();
FMC_SDRAMWriteProtectionConfig(FMC_Bank2_SDRAM,DISABLE);
lcd_tft.initialize();
systick.initialize(); GUI_Init();
GUI_SetBkColor(GUI_BLACK);
GUI_Clear(); pwm.initialize();
GUI_Delay();
LCD_ON; if(SD_Init() != ){
GUI_SetColor(GUI_RED);
GUI_SetFont(&GUI_FontFixedsys16);
GUI_DispStringHCenterAt("SD Error!",/,/);
while();
} res = f_mount(&fatfs,"0:",);
if(res != RES_OK){
GUI_SetColor(GUI_RED);
GUI_SetFont(&GUI_FontFixedsys16);
GUI_DispStringHCenterAt("f_mount Error!",/,/);
while();
}
power_on.check_touch(); frame.process();
}
static void frame_process(void)
{
FIL file; //文件对象
int i,j;
unsigned int counter; GUI_CURSOR_Show();
WM_SetCreateFlags(WM_CF_MEMDEV);
GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, , ); sprintf(buffer,"Is to write and read\r\n");
MULTIEDIT_AddText(hItem,buffer);
memset(buffer,,sizeof(buffer));
GUI_Exec(); f_open(&file,"0:/test.txt",FA_READ | FA_WRITE | FA_OPEN_ALWAYS);
f_lseek(&file,);
for(i = ;i < ;i++){
write_buffer[i] = i % ;
}
f_write(&file,write_buffer,,&counter); //将缓冲器中的内容写入源文件
f_lseek(&file,); //移动读指针到文件首
f_read(&file,read_buffer,,&counter);
f_close(&file); MULTIEDIT_SetText(hItem,buffer); //上次显示的文本清空 sprintf(buffer,"Complete\r\n");
MULTIEDIT_AddText(hItem,buffer);
memset(buffer,,sizeof(buffer)); sprintf(buffer,"write data:\r\n");
MULTIEDIT_AddText(hItem,buffer);
memset(buffer,,sizeof(buffer)); for(i = ;i < ;i++){
for(j=;j < ;j++){
sprintf(buffer," %02X",write_buffer[i*+j]);
MULTIEDIT_AddText(hItem,buffer);
memset(buffer,,sizeof(buffer));
}
sprintf(buffer,"\r\n");
MULTIEDIT_AddText(hItem,buffer);
memset(buffer,,sizeof(buffer));
} sprintf(buffer,"read data:\r\n");
MULTIEDIT_AddText(hItem,buffer);
memset(buffer,,sizeof(buffer)); for(i = ;i < ;i++){
for(j=;j < ;j++){
sprintf(buffer," %02X",read_buffer[i*+j]);
MULTIEDIT_AddText(hItem,buffer);
memset(buffer,,sizeof(buffer));
}
sprintf(buffer,"\r\n");
MULTIEDIT_AddText(hItem,buffer);
memset(buffer,,sizeof(buffer));
} while(){
GUI_Exec();
}
}
04-17 20:21