OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 3950|回复: 2

求助:关于TF卡用Fatfs实现读写

[复制链接]

2

主题

5

帖子

0

精华

新手入门

积分
15
金钱
15
注册时间
2017-7-28
在线时间
3 小时
发表于 2017-7-28 14:40:34 | 显示全部楼层 |阅读模式
1金钱
平台是STM32F4探索者自己移植Fatfs在探索板上使用
SPI模式 淘宝买的TF卡模块 QQ图片20170728143329.png
在串口在打印的信息如下
disk_initialize Success : 0

mount filesystem 0 Success : 0

write file test......

f_open() failed : 13

f_puts() success
f_puts() success
file size:0
f_read() fail

f_open返回值为13  There is no valid FAT volume
困惑很多天了 求大神解答疑惑 谢谢!!

SD_SPI.zip

11.37 MB, 下载次数: 97

源文件

正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

2

主题

5

帖子

0

精华

新手入门

积分
15
金钱
15
注册时间
2017-7-28
在线时间
3 小时
 楼主| 发表于 2017-7-28 14:41:55 | 显示全部楼层
已经把SD卡格式化为FAT32模式 但是没有用
回复

使用道具 举报

2

主题

5

帖子

0

精华

新手入门

积分
15
金钱
15
注册时间
2017-7-28
在线时间
3 小时
 楼主| 发表于 2017-7-28 14:52:14 | 显示全部楼层
/*                一些初始化                */  
        SystemInit();
        LED_Init();                                                //初始化LED
        uart_init(115200);                                //初始化串口波特率为115200
        delay_init(168);                                  //初始化延时函数
        MSD0_SPI_Configuration();                //初始化SPI
       
        /*                        初始化SD卡                        */
        Res = disk_initialize(0);
        if(Res != RES_OK)
        {
                printf("disk_initialize failed : %d\n\r",Res);
        }
        else
        {
                printf("disk_initialize Success : %d\n\r",Res);
        }
       
        res = f_mount(0,&fs);
        if(res != FR_OK)
        {
                printf("mount filesystem 0 failed : %d\n\r",res);
        }
        else
        {
                printf("mount filesystem 0 Success : %d\n\r",res);
        }
      
    //写文件  
        printf("write file test......\n\r");
        //打开文件  如果data.txt存在,则打开;否则,创建一个新文件
    res = f_open(&file, "0:/A.txt",FA_OPEN_ALWAYS|FA_READ|FA_WRITE );  
    if(res!=FR_OK) { printf("f_open() failed : %d\n\r",res); }  
    else { printf("f_open() Success : %d\n\r",res); }  
       
    //将指针指向文件末  
    res = f_lseek(&file, file.fsize);     
    br = f_puts("1234567890", &file) ;  //向文件末写入字符串  
    if(br<1) { printf("f_puts() fail \r\n"); }  
    else { printf("f_puts() success \r\n"); }  
      
    res = f_lseek(&file, 2);     
    br = f_puts("--", &file) ;  //向文件末写入字符串  
    if(br<1) { printf("f_puts() fail \r\n"); }  
    else { printf("f_puts() success \r\n"); }  
      
    //读文件  
    br = file.fsize;  
    printf("file size:%d\r\n",br);  
    res = f_read(&file, buffer, file.fsize, &br);     //一次读一个字节知道读完全部文件信息  
    if(res == FR_OK ) { printf("text:%s\r\n", buffer); }  
    else { printf(" f_read() fail \r\n"); }  
  
    //关闭文件  
    f_close(&file);  
/*其他的一些操作*/  
        while(1)
        {
                delay_ms(200);                                           
                LED0=!LED0;
        }
        return 0;
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-5-16 13:59

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表