加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

uart缓冲区大小如何设置(转载)

(2011-12-02 10:44:28)
标签:

杂谈

在设计串口程序时,我们都知道要设置一个缓冲区,那么到底这个缓冲区要多大呢?
Jean J.Labrosse 的Embedded_systems_building_blocks中,他是这么说的:
When you use a buffer,the size of the buffer depends on how quickly your background process can get control of the CPU to process the information .For example,if the worst case latency of your background process is 200ms,you should plan for a buffer of at least 192 bytes if your serial port receives bytes at 9600 baud(960 bytes/sec * 200ms).
所以,按他的讲法,缓冲区大小 = 波特率*cpu处理最严重事件的等待时间
一开始我觉得蛮有道理的。波特率越大,缓冲区也应该越大。cpu处理最严重事件的等待时间越长,缓冲区也应该越大
但当我们用usb接收数据到内存里,然后用串口把它显示到pc时,发现会漏数据。我们使用的波特率是9600,串口缓冲区128*128,照这样算cpu处理最严重事件的等待时间可为128*128/960 =17s,怎么可能,但我们还是漏数据?? 突然发现上文讲的缓冲区大小方法是讲接受的,我搞错了,呵呵

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有