OneWire总线基本点

  One-wire总线是DALLAS公司研制开发的一种协议,采用单根信号线,既传输时钟,又传输数据而且数据传输是双向的。它具有节省I/O 口线资源、结构简单、成本低廉、便于总线扩展和维护等诸多优点。它由一个总线主节点、一个或多个从节点组成系统,通过一根信号线对从芯片进行数据的读取。每一个符合One-wire协议的从芯片都有一个唯一的地址,48位的序列号、8位的家族代码和8位的CRC代码。主芯片对各个从芯片的寻址依据这64位的不同来进行。

  One-wire总线利用一根线实现双向通信。因此其协议对时序的要求较严格,如应答等时序都有明确的时间要求。基本的时序包括复位及应答时序、写一位时序、读一位时序。在复位及应答时序中,主器件发出复位信号后,要求从器件在规定的时间内送回应答信号;在位读和位写时序中,主器件要在规定的时间内读回或写出数据。为了与其它模拟接口的子程序在结构形式上尽量一致,在One-wire模拟时序程序中把位读和位写时序拓延,形成低位在前的字节读写时序。最终形成三个子程序:复位及应答子程序、写N个字节子程序和读N个字节子程序。

  1-wire 单总线适用于单个主机系统,能够控制一个或多个从机设备。主机可以是微控制器,从机可以是单总线器件,它们之间的数据交换只通过一条信号线。当只有一个从机位于总线上时系统可按照单节点系统操作;而当多个从机位于总线上,时则系统按照多节点系统操作。

 

OneWireArduino库函数

//OneWire建立一个目标 myWire,对应一个特定引脚

OneWire myWire(pin)

  Create the OneWire object, using a specific pin. Even though you can connect many 1 wire devices to the same pin, if you have a large number, smaller groups each on their own pin can help isolate wiring problems. You can create multiple OneWire objects, one for each pin.

 

//查询下一个设备,其地址用8字节数组addrArray表示

myWire.search(addrArray)

  Search for the next device. The addrArray is an 8 byte array. If a device is found, addrArray is filled with the device's address and true is returned. If no more devices are found, false is returned.

  Perform a search. If this function returns a '1' then it has  enumerated the next device and you may retrieve the ROM from the OneWire_address variable. If there are no devices, no further devices, or something horrible happens in the middle of the  enumeration then a 0 is returned. If a new device is found then  its address is copied to newAddr. Use reset_search() to start over.

  Return TRUE : device found, ROM number in ROM_NO buffer

FALSE : device not found, end of search

///开始一个新的查询

myWire.reset_search() 

  Begin a new search. The next use of search will begin at the first device.

You need to use this function to start a search again from the beginning.

You do not need to do it for the first search, though you could.

 

//复位

myWire.reset()

  Reset the 1-wire bus. Usually this is needed before communicating with any device.

Perform a 1-Wire reset cycle. Returns 1 if a device responds with a presence pulse. Returns 0 if there is no device or the bus is shorted or otherwise held low for more than 250uS

Returns 1 if a device asserted a presence pulse, 0 otherwise.

//选择一个设备,对应的地址是addrArray

myWire.select(addrArray)

  Do a ROM select. Select a device based on its address. After a reset, this is needed to choose which device you will use, and then all communication will be with that device, until another reset.

  Issue a 1-Wire rom select command, you do the reset first.

//跳过设备选择,直接使用设备,适用于只有一个设备的情况

myWire.skip()

  Skip the device selection. This only works if you have a single device, but you can avoid searching and use this to immediatly access your device.

  Do a ROM skip,Issue a 1-Wire rom skip command, to address all on bus.

// Read a bit.读一个位

uint8_t read_bit(void);   

  Read a bit. Port and bit is used to cut lookup time and provide more certain timing.

// Read a byte.读一个字节

uint8_t read(void);  

void read_bytes(uint8_t *buf, uint16_t count);

// Write a bit. 写一个位

void write_bit(uint8_t v);

  Write a bit. Port and bit is used to cut lookup time and provide more certain timing.

The bus is always left powered at the end, see note in write() about that.

  Stop forcing power onto the bus. You only need to do this if  you used the 'power' flag to write() or used a write_bit() call  and aren't about to do another read or write. You would rather  not leave this powered if you don't have to, just in case  someone shorts your bus.

// 写一个字节

myWire.write(num, 1);

void write(uint8_t v, uint8_t power = 0);

void write_bytes(const uint8_t *buf, uint16_t count, bool power = 0);

  Write a byte, and leave power applied to the 1 wire bus.

  The writing code uses the active drivers to raise the pin high, if you need power after the write (e.g. DS18S20 in parasite power mode) then set 'power' to 1, otherwise the pin will go tri-state at the end of the write to avoid heating in a short or other mishap.

//写一个字节

myWire.write(num);  

  Write a byte. If 'power' is one then the wire is held high at the end for parasitically powered devices. You are responsible for eventually depowering it by calling depower() or doing another read or write.

//进行CRC检查

myWire.crc8(dataArray, length)

uint8_t OneWire::crc8( uint8_t *addr, uint8_t len)

uint16_t OneWire::crc16(uint8_t* input, uint16_t len)

  Compute a CRC check on an array of data.

  Compute a Dallas Semiconductor 8 bit CRC. These show up in the ROM and the registers.

OneWire总线的Arduino库函数的更多相关文章

  1. I2C总线的Arduino库函数

    I2C总线的Arduino库函数 I2C即Inter-Integrated Circuit串行总线的缩写,是PHILIPS公司推出的芯片间串行传输总线.它以1根串行数据线(SDA)和1根串行时钟线(S ...

  2. 总线SPI的Arduino库函数

    来源参考:https://www.cnblogs.com/MyAutomation/p/9348480.html 总线SPI的Arduino库函数 SPI基本知识 SPI:高速同步串行口.是一种标准的 ...

  3. Arduino库函数中文说明

    #define 常量名 常量值 % 取模运算符 String abc  /  char abc[n]  定义字符串 pinMode(pin,mode);  用于引脚的初始化  mode包括 INPUT ...

  4. arduino库函数1

    https://wenku.baidu.com/view/e657b1f0bcd126fff6050baf.html 的阅读笔记.现在到了 第四十页. setup应该是 在开始 执行一次. 然后 lo ...

  5. 步进电机的Arduino库函数

    This library allows you to control unipolar or bipolar stepper motors. To use it you will need a ste ...

  6. 伺服电机的Arduino库函数

    servo.attach(pin)  //连接伺服电机的信号线于控制板的引脚,9或10号引脚servo.attach(pin, min, max) servo: a variable of type ...

  7. Arduino小车学习与研究

    信安系统设计基础实践模块 Arduino小车学习与研究 ================== 陈都(20135328) 余佳源(20135321) 莫凡(20135225) ---------- 索引 ...

  8. Arduino小车学习与研究博客

    Arduino小车学习与研究博客 信安系统设计基础实践模块 Arduino小车学习与研究 ================== 陈都(20135328) 余佳源(20135321) 莫凡(201352 ...

  9. AVR开发 Arduino方法(一) 端口子系统

    Arduino UNO R3使用的主处理器ATMega328P上有3个8位的输入/输出端口,它们分别是PB,PC和PD.Arduino IDE提供的Blink示例可以帮助我们了解端口的数字输出功能: ...

随机推荐

  1. Babel知识点相关

    本篇是根据最新babel 7版本写的,里面用到的一些babel相关包都是babel 7的     1,babel是如何工作的 babel是一个转译器,这里我严格区分了转译器和编译器,因为编译器最终生成 ...

  2. python爬取酷我音乐(收费也可)

    第一次创作,请多指教 环境:Python3.8,开发工具:Pycharm 很多人学习python,不知道从何学起.很多人学习python,掌握了基本语法过后,不知道在哪里寻找案例上手.很多已经做案例的 ...

  3. T4m

    Unity T4M 中文讲解 http://blog.csdn.net/tianmao111/article/details/46482963

  4. 前端通过jqplot绘制折线图

    首先需要下载jqplot需要的js与css文件,我已近打包好了,需要的可以下载 接下来导入其中关键的js与css如下, <link href="css/jquery.jqplot.mi ...

  5. 听过N次还是不会之:浏览器输入url后到底经历了什么

    有没有这种场景:当你被问起某一项知识点时,你大脑里想起经常看到过这样的问题,可是具体是怎么样就是说不清楚. 好吧,我就是这样的,于是整理一下,实在记不住,以后找起来也方便. 当你在浏览器地址栏里输入一 ...

  6. File类与IO流

    一.File类与IO流 数组.集合等内容都是把数据放在内存里面,一旦关机或者断电,数据就会立刻从内存里面消失.而IO主要讲文件的传输(输入和输出),把内存里面的数据持久化到硬盘上,如.txt .avi ...

  7. leetcode刷题-80.删除排序数组中的重复项 II

    题目 给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素最多出现两次,返回移除后数组的新长度. 不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成. ...

  8. 云计算openstack核心组件——glance— 镜像服务(6)

    一.glance介绍:              Glance是Openstack项目中负责镜像管理的模块,其功能包括虚拟机镜像的查找.注册和检索等. Glance提供Restful API可以查询虚 ...

  9. 基于k8s的集群稳定架构

    前言 我司的集群时刻处于崩溃的边缘,通过近三个月的掌握,发现我司的集群不稳定的原因有以下几点: 1.发版流程不稳定 2.缺少监控平台[最重要的原因] 3.缺少日志系统 4.极度缺少有关操作文档 5.请 ...

  10. 性能之qps,并发数,相应时间

    QPS:每秒处理的请求数.QPS = 并发数/请求平均处理时间. 请求响应时间=请求等待时间+网络时间+请求处理时间.假设请求处理时间不受影响,持续不变,实际请求数大于QPS,会影响请求响应时间,大量 ...