[技术问答]

OneWire库函数介绍

[复制链接]
233|7
手机看帖
扫描二维码
随时随地手机跟帖
mintspring|  楼主 | 2023-2-26 21:21 | 显示全部楼层 |阅读模式
很多人用过18B20这类单线协议的传感器,知道最好用的库是哪个吗?里面都有哪些库函数。、
The OneWire library provides several functions that can be used to access and control devices on a 1-wire bus. Here is a list of the most common functions:


onewire_reset(): Resets the current 1-wire bus and returns the status of the bus after reset.

onewire_search() : Searches for a new device on the 1-Wire bus and returns its ROM if found.

onewire_skip_rom(): Skips the ROM address in order to access a device directly.

onewire_read_byte() : Reads a single byte from the 1-Wire bus.

onewire_write_byte() : Writes a single byte to the 1-Wire bus.

onewire_read_bit() : Reads a single bit from the 1-Wire bus.

onewire_write_bit(): Writes a single bit to the 1-Wire bus.

onewire_triplet() : Scans the 1-Wire bus and returns three bits representing the state of 2 or 3 devices.

函数 onewire_search() 是一种低成本,可靠的多功能1-Wire协议技术的实现方式。它通过在1-Wire网络中扫描有效的令牌来识别1-Wire器件,并使用search_rom()函数对搜索结果进行校验。同时,它也包含其他重要的辅助功能,是从网络上获得1-Wire树的总线和节点信息的必备工具。

onewire_search()函数主要用于在1-Wire网络上搜索DS18B20传感器。它首先使用skip_romcommand同时发送给所有已连接的DS18B20设备,然后执行search_rom command和match_rom command来匹配特定的DS18B20物理地址,我们可以使用read_rom command来读取特定的DS18B20的芯片ID。如果网络里没有新的设备,就会得到一个空应答,但是它也可以检测到新添加的设备。
所以onewire_search()函数在1-wire网络上的作用就是当添加或移除1-Wire网络中的DS18B20传感器时,它将检测到变化并更新更改。 优势是可以实现自动搜索直到设备被添加或移除,然后重新扫描该网络,并且不会错过任何DS18B20对象。

使用特权

评论回复
xuanhuanzi| | 2023-2-26 21:42 | 显示全部楼层
感谢分享,等我下载了,试试能否移植到51,M0等

使用特权

评论回复
OneWire库不属于基本库

使用特权

评论回复
中国龙芯CDX| | 2023-2-28 14:56 | 显示全部楼层
OneWire库函数学习一下,后期移植到其他MCU上

使用特权

评论回复
LOVEEVER| | 2023-2-28 14:59 | 显示全部楼层
OneWire库函数的使用有优点还是蛮多的

使用特权

评论回复
AloneKaven| | 2023-3-1 19:55 | 显示全部楼层
OneWire库可以学习一下

使用特权

评论回复
七毛钱| | 2023-3-21 09:19 | 显示全部楼层
OneWire库可以学习一下

使用特权

评论回复
chenjun89| | 2023-3-21 19:51 | 显示全部楼层
单线通信现在很少应用了吧

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

281

主题

4801

帖子

23

粉丝