Wire.requestFrom()
描述
呼叫 requestFrom() 藉以向 I2C 的从端请求资料。之后再使用 available() 和 read() 读取资料。
requestFrom() 的第三个参数可以选择要提供或是不提供,当不提供该参数时预设为 true,这个参数被用来改变 requestFrom() 的行为,如果该参数为 true 则 requestFrom() 在传送完请求后会传送停止的指令,释放 I2C 介面。如果该参数为 false 则 requestFrom() 在传送完请求后会传送重新启动的指令,不去释放 I2C 介面,使得其他的主端无法发送请求,这样允许一个主端在控制时可以发送多个请求。
语法
Wire.requestFrom(address, quantity)
Wire.requestFrom(address, quantity, stop)
参数
address:从端的七位元位址
quantity:请求资料量的位元组大小
stop(非必要):如果 stop 为 true 传送请求后释放 I2C,如果 stop 为 false 传送请求后不释放 I2C,型态为 boolean,预设为 true,详见上面的描述
回传
byte:从端回传的资料量大小,单位为位元组
See also
- Wire.available()
- Wire.read()
The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.
