[讨论]大家伙帮忙看下我利用串口中断读出来的数据对不

我写的程序比较简单,初始化376,检测U盘,打开固定文件,读文件10000字节,关闭文件,这几个函数顺序执行,可是我在用串口中断方式读取固定文件10000字节的时候,出现的情况如图所示(由于读文件是由读块组成的,图中是我打印出的每次读出的块得长度),我对我读出的数据有所怀疑,虽然字节总数是正确的,但是细看下,还有读出来的是0字节或者2字节,我感觉自己可能读错了,大家伙帮我分析下吧。

readblock -> s是读块函数返回的字节数 最后一行是打印的总数,及其最后一次返回的状态码

PM 03:42:34> readblock -> s = 255 PM 03:42:35> readblock -> s = 0 PM 03:42:35> readblock -> s = 255 PM 03:42:36> readblock -> s = 0 PM 03:42:36> readblock -> s = 2 PM 03:42:38> readblock -> s = 0 PM 03:42:38> readblock -> s = 255 PM 03:42:39> readblock -> s = 0 PM 03:42:39> readblock -> s = 255 PM 03:42:40> readblock -> s = 0 PM 03:42:40> readblock -> s = 2 PM 03:42:41> readblock -> s = 0 PM 03:42:41> readblock -> s = 255 PM 03:42:42> readblock -> s = 0 PM 03:42:42> readblock -> s = 255 PM 03:42:43> readblock -> s = 0 PM 03:42:43> readblock -> s = 2 PM 03:42:45> readblock -> s = 0 PM 03:42:45> readblock -> s = 255 PM 03:42:46> readblock -> s = 0 PM 03:42:46> readblock -> s = 255 PM 03:42:47> readblock -> s = 0 PM 03:42:47> readblock -> s = 2 PM 03:42:48> readblock -> s = 0 PM 03:42:48> readblock -> s = 255 PM 03:42:49> readblock -> s = 0 PM 03:42:49> readblock -> s = 255 PM 03:42:51> readblock -> s = 0 PM 03:42:51> readblock -> s = 2 PM 03:42:52> readblock -> s = 0 PM 03:42:52> readblock -> s = 255 PM 03:42:53> readblock -> s = 0 PM 03:42:53> readblock -> s = 255 PM 03:42:54> readblock -> s = 0 PM 03:42:54> readblock -> s = 2 PM 03:42:55> readblock -> s = 0 PM 03:42:55> readblock -> s = 255 PM 03:42:56> readblock -> s = 0 PM 03:42:57> readblock -> s = 255 PM 03:42:58> readblock -> s = 0 PM 03:42:58> readblock -> s = 2 PM 03:42:59> readblock -> s = 0 PM 03:42:59> readblock -> s = 255 PM 03:43:00> readblock -> s = 0 PM 03:43:00> readblock -> s = 255 PM 03:43:01> readblock -> s = 0 PM 03:43:01> readblock -> s = 2 PM 03:43:02> readblock -> s = 0 PM 03:43:02> readblock -> s = 255 PM 03:43:03> readblock -> s = 0 PM 03:43:03> readblock -> s = 255 PM 03:43:04> readblock -> s = 0 PM 03:43:04> readblock -> s = 2 PM 03:43:05> readblock -> s = 0 PM 03:43:06> readblock -> s = 255 PM 03:43:07> readblock -> s = 0 PM 03:43:07> readblock -> s = 255 PM 03:43:08> readblock -> s = 0 PM 03:43:08> readblock -> s = 2 PM 03:43:09> readblock -> s = 0 PM 03:43:09> readblock -> s = 255 PM 03:43:10> readblock -> s = 0 PM 03:43:10> readblock -> s = 255 PM 03:43:11> readblock -> s = 0 PM 03:43:11> readblock -> s = 2 PM 03:43:12> readblock -> s = 0 PM 03:43:12> readblock -> s = 255 PM 03:43:13> readblock -> s = 0 PM 03:43:13> readblock -> s = 255 PM 03:43:14> readblock -> s = 0 PM 03:43:14> readblock -> s = 2 PM 03:43:16> readblock -> s = 0 PM 03:43:16> readblock -> s = 255 PM 03:43:17> readblock -> s = 0 PM 03:43:17> readblock -> s = 255 PM 03:43:18> readblock -> s = 0 PM 03:43:18> readblock -> s = 2 PM 03:43:19> readblock -> s = 0 PM 03:43:19> readblock -> s = 255 PM 03:43:20> readblock -> s = 0 PM 03:43:20> readblock -> s = 255 PM 03:43:21> readblock -> s = 0 PM 03:43:21> readblock -> s = 2 PM 03:43:22> readblock -> s = 0 PM 03:43:22> readblock -> s = 255 PM 03:43:23> readblock -> s = 0 PM 03:43:23> readblock -> s = 255 PM 03:43:25> readblock -> s = 0 PM 03:43:25> readblock -> s = 2 PM 03:43:26> readblock -> s = 0 PM 03:43:26> readblock -> s = 255 PM 03:43:27> readblock -> s = 0 PM 03:43:27> readblock -> s = 255 PM 03:43:28> readblock -> s = 0 PM 03:43:28> readblock -> s = 2 PM 03:43:29> readblock -> s = 0 PM 03:43:29> readblock -> s = 255 PM 03:43:31> readblock -> s = 0 PM 03:43:31> readblock -> s = 255 PM 03:43:32> readblock -> s = 0 PM 03:43:32> readblock -> s = 2 PM 03:43:33> readblock -> s = 0 PM 03:43:33> readblock -> s = 255 PM 03:43:34> readblock -> s = 0 PM 03:43:34> readblock -> s = 255 PM 03:43:35> readblock -> s = 0 PM 03:43:35> readblock -> s = 2 PM 03:43:36> readblock -> s = 0 PM 03:43:36> readblock -> s = 255 PM 03:43:37> readblock -> s = 0 PM 03:43:38> readblock -> s = 255 PM 03:43:39> readblock -> s = 0 PM 03:43:39> readblock -> s = 2 PM 03:43:40> readblock -> s = 0 PM 03:43:40> readblock -> s = 255 PM 03:43:41> readblock -> s = 0 PM 03:43:41> readblock -> s = 17 PM 03:43:42> readblock -> s = 0 PM 03:43:42> ch376byteread() 0x14 <10000>

从你打印的信息上面看 255,2都是正确的,因为CH376从U盘读写文件的时候 是分扇区的(512字节),但是字节方式单次只允许使用255字节,所以对CH376来说一个扇区需要分3次读写完成,即255+255+2,然后才可以对第二个扇区进行操作。 程序中打印的0字节 是从哪边来的? 需要你查查程序。


_study_兄 我仔细检查程序了,也不确定怎么着出来的0,我也相当纳闷~~~ 还有一个问题,请帮忙解决,我重新发一个帖子


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