博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
STM32利用FATFS读写数组
阅读量:4029 次
发布时间:2019-05-24

本文共 1916 字,大约阅读时间需要 6 分钟。

因为存为TXT可以实现,但是读取TXT里边的数据总是不尽如人意,所以,最终存为bin文件了。

先摘几个观点:

http://www.openedv.com/posts/list/36712.htm “文本文件存储的都是ASCII内容,如果你以16进制格式显示出来,那就是ASCII的内码。

http://www.openedv.com/posts/list/58089.htm“  

stm32 Fatfs 读写SD卡(http://www.ichanging.org/stm32-fatfs-sd.html)

f_openhttp://elm-chan.org/fsw/ff/en/open.html

实现的部分代码(读写bin文件)(其他可以借鉴 原子的FATFS相关实例等 http://www.openedv.com/forums/show/0/2/0/55.htm)

u32 sd_size;	FIL file;	FRESULT res;	UINT bw;	UINT br;//ʵ¼Ê¶ÁÈ¡µ½µÄ×Ö½ÚÊý
// SD ¿¨	while(SD_Initialize())//¼ì²â²»µ½SD¿¨	{	  		//LCD_ShowString(60,170,200,16,16,"SD Card Error!");		printf("\r\nSD Card Error!\r\n");		delay_ms(500);							//LCD_ShowString(60,170,200,16,16,"Please Check! ");		printf("\r\nSD Card Error!\r\n");		delay_ms(500);	}	printf("\r\nSD Card OKr\n");		printf("\r\nSD Card Size:     MB\r\n");	sd_size=SD_GetSectorCount();//µÃµ½ÉÈÇøÊý	printf("\r\nsd_size:%d\r\n",sd_size);	f_mount(fs[0],"0:",1); 					//¹ÒÔØSD¿¨ 		res=f_open(&file,"0:/Test.bin",FA_CREATE_ALWAYS | FA_WRITE  );	if(res != FR_OK)	{			printf("\r\nOpen file error!\r\n");	}	else	{		if(res == FR_OK)		{					iTemp=13;			res = f_write(&file, &iTemp, sizeof(iTemp), &bw);               /* Write it to the dst file */			//res = f_write(&file, "\r\n",2, &bw);               /* Write it to the dst file */			iTemp=1;			res = f_write(&file, &iTemp, sizeof(iTemp), &bw);               /* Write it to the dst file */			printf("\r\nwrite data ok!\r\n");		}		else		{			printf("\r\nwrite data error!\r\n");		}	 }	f_close(&file);		 res=f_open(&file,"0:/Test.bin",FA_OPEN_EXISTING|FA_READ);//	if(res!=FR_OK)	{		printf("\r\n f_open() fail .. \r\n");	}	else	{		printf("\r\n f_open() success .. \r\n");	}	while(!f_eof(&file))	{		iBuf=0;		res = f_read(&file, &iTemp, sizeof(u16), &br);//¶ÁÈ¡Ò»¸ö16λµÄÊý¾Ý		if(res==FR_OK)		{			iBuf++;			printf("%d \r\n",iTemp);		}		else		{			printf("\r\n f_read() fail .. \r\n");  		}	}	f_close(&file);  f_mount(fs[0],"0:",NULL);

转载地址:http://zwqbi.baihongyu.com/

你可能感兴趣的文章
Django objects.all()、objects.get()与objects.filter()之间的区别介绍
查看>>
python:如何将excel文件转化成CSV格式
查看>>
Django 的Error: [Errno 10013]错误
查看>>
机器学习实战之决策树(一)
查看>>
[LeetCode By Python] 2 Add Two Number
查看>>
python 中的 if __name__=='__main__' 作用
查看>>
机器学习实战之决策树二
查看>>
[LeetCode By Python]7 Reverse Integer
查看>>
[LeetCode By Python]9. Palindrome Number
查看>>
[leetCode By Python] 14. Longest Common Prefix
查看>>
[LeetCode By Python]107. Binary Tree Level Order Traversal II
查看>>
[LeetCode By Python]108. Convert Sorted Array to Binary Search Tree
查看>>
[leetCode By Python]111. Minimum Depth of Binary Tree
查看>>
[LeetCode By Python]118. Pascal's Triangle
查看>>
[LeetCode By Python]121. Best Time to Buy and Sell Stock
查看>>
[LeetCode By Python]122. Best Time to Buy and Sell Stock II
查看>>
[LeetCode By Python]125. Valid Palindrome
查看>>
[LeetCode By Python]136. Single Number
查看>>
[LeetCode By Python]167. Two Sum II - Input array is sorted
查看>>
[LeetCode BY Python]169. Majority Element
查看>>