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.
