原帖地址:http://www.amobbs.com/thread-5537678-1-1.html
在fatfs文件系统下,实现SD卡的读取追加内容,实现方法是:读取文件、偏移指针、填写内容。追加内容时需要利用f_sleek函数将指针移到文本尾 部,再写问容,具体实现main函数的功能是两个按键来控制添加不同的内容,按键1按下时添加 BYTE sample_buffer[] = "2710,2712,2711,2715,1234,2134,4567,7890 \r\n";按键2按下时添加 BYTE sample_buffer1[] = "1,2,3,4,5,6,7,8,9,0 \r\n";
printf 调试用,
问题是:保存到txt文件中的数据不规则,应该是每一行数据都是靠左边对齐才对,实际是如附件图片所示。
程序:
while (1)
{
if( Key_Scan(GPIOE,GPIO_Pin_5) == KEY_ON)
//按键1按下时添加 sample_buffer中内容
{
printf( "\r\n KEY1 PE5
\n" );
//串口输出调试信息
res = f_open(&fdst,"0:/Demo.TXT", FA_WRITE);
//打开文本,while之前已经 f_mount(0,&fs);
if( res == FR_OK)
{
printf( "\r\n SD has opened
\n" );
res = f_lseek(&fdst, f_size(&fdst));
res = f_write(&fdst, sample_buffer, sizeof(sample_buffer), &bw);
f_close(&fdst);
printf( "\r\n sample_buffer \n" );
}
}
if( Key_Scan(GPIOE,GPIO_Pin_6) == KEY_ON)
//按键2按下时添加 sample_buffer1中内容
{
printf( "\r\n KEY2 PE6
\n" );
res = f_open(&fdst,"0:/Demo.TXT", FA_WRITE);
if( res == FR_OK)
{
printf( "\r\n SD has opened
\n" );
res = f_lseek(&fdst, f_size(&fdst));
res = f_write(&fdst, sample_buffer1, sizeof(sample_buffer), &bw);
f_close(&fdst);
printf( "\r\n sample_buffer1 \n" );
}
}
}
试验结果:txt文本内容
实际显示内容对齐方式是:
感谢您选用 野火STM32开发板 !^_^
1,2,3,4,5,6,7,8,9,0
1,2,3,4,5,6,7,8,9,0
1,2,3,4,5,6,7,8,9,0
1,2,3,4,5,6,7,8,9,0
1,2,3,4,5,6,7,8,9,0
2710,2712,2711,2715,1234,2134,4567,7890
2710,2712,2711,2715,1234,2134,4567,7890
2710,2712,2711,2715,1234,2134,4567,7890
1,2,3,4,5,6,7,8,9,0
1,2,3,4,5,6,7,8,9,0
1,2,3,4,5,6,7,8,9,0
理论或是理想中的显示内容对齐方式是:
感谢您选用 野火STM32开发板 !^_^
1,2,3,4,5,6,7,8,9,0
1,2,3,4,5,6,7,8,9,0
1,2,3,4,5,6,7,8,9,0
1,2,3,4,5,6,7,8,9,0
1,2,3,4,5,6,7,8,9,0
2710,2712,2711,2715,1234,2134,4567,7890
2710,2712,2711,2715,1234,2134,4567,7890
2710,2712,2711,2715,1234,2134,4567,7890
1,2,3,4,5,6,7,8,9,0
1,2,3,4,5,6,7,8,9,0
1,2,3,4,5,6,7,8,9,0
在fatfs文件系统下,实现SD卡的读取追加内容,实现方法是:读取文件、偏移指针、填写内容。追加内容时需要利用f_sleek函数将指针移到文本尾 部,再写问容,具体实现main函数的功能是两个按键来控制添加不同的内容,按键1按下时添加 BYTE sample_buffer[] = "2710,2712,2711,2715,1234,2134,4567,7890 \r\n";按键2按下时添加 BYTE sample_buffer1[] = "1,2,3,4,5,6,7,8,9,0 \r\n";
printf 调试用,
问题是:保存到txt文件中的数据不规则,应该是每一行数据都是靠左边对齐才对,实际是如附件图片所示。
程序:
while (1)
试验结果:txt文本内容
实际显示内容对齐方式是:
感谢您选用 野火STM32开发板 !^_^
1,2,3,4,5,6,7,8,9,0
2710,2712,2711,2715,1234,2134,4567,7890
2710,2712,2711,2715,1234,2134,4567,7890
1,2,3,4,5,6,7,8,9,0
理论或是理想中的显示内容对齐方式是:
感谢您选用 野火STM32开发板 !^_^
1,2,3,4,5,6,7,8,9,0
1,2,3,4,5,6,7,8,9,0
1,2,3,4,5,6,7,8,9,0
1,2,3,4,5,6,7,8,9,0
1,2,3,4,5,6,7,8,9,0
2710,2712,2711,2715,1234,2134,4567,7890
2710,2712,2711,2715,1234,2134,4567,7890
2710,2712,2711,2715,1234,2134,4567,7890
1,2,3,4,5,6,7,8,9,0
1,2,3,4,5,6,7,8,9,0
1,2,3,4,5,6,7,8,9,0