[技术问答] OneWire库函数介绍

[复制链接]
 楼主| 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:


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

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

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

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

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

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

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

  8. 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等
小夏天的大西瓜 发表于 2023-2-27 14:09 | 显示全部楼层
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 来自手机 | 显示全部楼层
单线通信现在很少应用了吧
您需要登录后才可以回帖 登录 | 注册

本版积分规则

302

主题

4962

帖子

24

粉丝
快速回复 在线客服 返回列表 返回顶部

302

主题

4962

帖子

24

粉丝
快速回复 在线客服 返回列表 返回顶部