CH376写数据不完

Start Wait Udisk/SD Ready ? DiskQuery: free cap = 2093 MB Open Create Write begin Write ADC data Current total is 99 Current total is 154 Current total is 209 Current total is 263 Current total is 318 Current total is 373 Current total is 428 Current total is 483 Current total is 538 Current total is 593 Current total is 646 Current total is 701 Current total is 756 Current total is 810 Current total is 865 Current total is 920 Current total is 975 Current total is 1030 Current total is 1085 Current total is 1140 Current total is 1194 Current total is 1249 Current total is 1304 Current total is 1359 Current total is 1413 Current total is 1468 Current total is 1523 Current total is 1578 Current total is 1632 Current total is 1687 Current total is 1742 Current total is 1797 Current total is 1852 Current total is 1907 Current total is 1962 Current total is 2017 Current total is 2072 Current total is 2127 Current total is 2182 Current total is 2236 Current total is 2291 Current total is 2346 Current total is 2401 Current total is 2455 Current total is 2510 Current total is 2565 Current total is 2620 Current total is 2674 Current total is 2729 Current total is 2784 Current total is 2839 Current total is 2894 Current total is 2949 Current total is 3004 Current total is 3059 Current total is 3114 Current total is 3169 Current total is 3224 Current total is 3278 Current total is 3333 Current total is 3388 Current total is 3443 Current total is 3497 Current total is 3552 Current total is 3607 Current total is 3662 Current total is 3716 Current total is 3771 Current total is 3826 Current total is 3881 Current total is 3936 Current total is 3991 Current total is 4046 Current total is 4101 Current total is 4156 Current total is 4211 Current total is 4266 Current total is 4320 Current total is 4375 Current total is 4430 Current total is 4485 Current total is 4539 Current total is 4594 Current total is 4649 Current total is 4704 Current total is 4757 Current total is 4812 Current total is 4867 Current total is 4922 Current total is 4977 Current total is 5032 Current total is 5087 Current total is 5142 Current total is 5197 Current total is 5252 Current total is 5307 Current total is 5361 Current total is 5416 Current total is 5471 Current total is 5526 Current total is 5580 Current total is 5635 Current total is 5690 Current total is 5745 Current total is 5800 Current total is 5855 Current total is 5910 Current total is 5965 Current total is 6020 Current total is 6075 Current total is 6130 Current total is 6184 Current total is 6239 Current total is 6294 Current total is 6349 Current total is 6403 Current total is 6458 Current total is 6513 Current total is 6568 Current total is 6622 Current total is 6677 Current total is 6732 Current total is 6787 Current total is 6842 Current total is 6897 Current total is 6952 Current total is 7007 Current total is 7062 Current total is 7117 Current total is 7172 Current total is 7226 Current total is 7281 Current total is 7336 Current total is 7391 Current total is 7445 Current total is 7500 Current total is 7555 Current total is 7610 Current total is 7664 Current total is 7719 Current total is 7774 Current total is 7829 Current total is 7884 Current total is 7939 Current total is 7994 Current total is 8049 Current total is 8104 Current total is 8159 Current total is 8214 Current total is 8268 Current total is 8323 Current total is 8378 Current total is 8433 Current total is 8487 Current total is 8542 Current total is 8597 Current total is 8652 Current total is 8706 Current total is 8761 Current total is 8816

在我拔除优盘会报错FA U盘里出现一个文件AHY_ADC.TXT,但是没有任何内容 是不是因为没有更新数据长度呢?? 请帮我分析分析原因. 例子是参考CH376EVT里的EXAM8,没有作任何修改啊~~难道是U盘原因?

1、必须更新文件长度 2、例程中采用for循环总次数是360,监控一下次数是不是正确的


文件写完之后要关闭文件,并且更新文件长度,否则文件当中是没有数据的。


printf( "Write begin\n" ); total += sprintf( FileDataBuf + total, "在本次添加数据之前,该文件已有数据的长度是 %ld 字节\xd\xa", NewSize ); /* 将新数据添加到缓冲区的尾部,累计缓冲区内的数据长度 */ mFlushBufferToDisk( 0 ); /* 自动刷新缓冲区,检查缓冲区是否已满,满则写盘 */ printf( "Write ADC data\n" ); TR0=1; /* 用定时器0的计数值代替ADC数据 */ for ( month = 1; month != 4; month ++ ) { /* 因为测试板上没有实时时钟芯片,所以用循环方式模拟月份 */ for ( date = 1; date != 10; date ++ ) { /* 因为测试板上没有实时时钟芯片,所以用循环方式模拟日期 */ year = 2004; /* 假定为2004年 */ hour = TL1 & 0x1F; /* 因为测试板上没有实时时钟芯片,所以用定时器1的计数代替进行演示 */ /* adc = get_adc_data( ); */ adc = ( (UINT16)TH0 << 8 ) | TL0; /* 因为测试板上没有ADC,所以用定时器0的计数代替ADC数据演示 */ total += sprintf( FileDataBuf + total, "Year=%04d, Month=%02d, Date=%02d, Hour=%02d, ADC_data=%u\xd\xa", year, (UINT16)month, (UINT16)date, (UINT16)hour, adc ); /* 将二制制数据格式为一行字符串 */ if ( month == 6 && ( date & 0x0F ) == 0 ) mFlushBufferToDisk( 1 ); /* 强制刷新缓冲区,定期强制刷新缓冲区,这样在突然断电后可以减少数据丢失 */ else mFlushBufferToDisk( 0 ); /* 自动刷新缓冲区,检查缓冲区是否已满,满则写盘 */ printf( "Current total is %d\n", total ); /* 用于监控检查 */ } } printf( "Write end\n" ); //total += sprintf( FileDataBuf + total, " ********************************* " ); /* 将新数据添加到缓冲区的尾部,累计缓冲区内的数据长度 */ //total += sprintf( FileDataBuf + total, "这次的ADC数据到此结束,程序即将退出\xd\xa" ); /* 将新数据添加到缓冲区的尾部,累计缓冲区内的数据长度 */ CH376FileOpen( "\MY_ADC.TXT" ); mFlushBufferToDisk( 1 ); /* 强制刷新缓冲区,因为系统要退出了,所以必须强制刷新 */ printf( "Close\n" ); s = CH376FileClose( FALSE ); /* 关闭文件,扇区模式通常不自动更新文件长度,因为强制刷新缓冲区时已经更新了文件长度,所以这里不需要自动更新文件长度 */ mStopIfError( s ); 我把程序做了点修改, 用串口助手观察结果如下: Start Wait Udisk/SD Ready ? DiskQuery: free cap = 2093 MB Open Create Write begin Write ADC data Current total is 99 Current total is 154 Current total is 209 Current total is 263 Current total is 318 Current total is 373 Current total is 428 Current total is 483 Current total is 538 Current total is 593 Current total is 646 Current total is 701 Current total is 756 Current total is 810 Current total is 865 Current total is 920 Current total is 975 Current total is 1030 Current total is 1085 Current total is 1140 Current total is 1194 Current total is 1249 Current total is 1304 Current total is 1359 Current total is 1413 Current total is 1468 Current total is 1523 Write end Current file size is 1600085842 Error: B4 这个mFlushBufferToDisk( 1 )会导致关闭文件吗?因为B4代表文件已关闭 我打开U盘,看不到MY_ADC.TXT文件,这是什么原因呢??


1、CH376FileOpen有返回值,程序中怎么没有检测 2、mFlushBufferToDisk不会关闭文件,只有CH376FileClose才会 3、写完数据后,为什么调CH376FileOpen呢?这时文件本身就是打开的,建议先不要修改程序的流程,调试成功后再根据需要修改


只有登录才能回复,可以选择微信账号登录