-
Notifications
You must be signed in to change notification settings - Fork 4
Class_I2C
Ko-ichiro Sugiyama edited this page May 15, 2022
·
7 revisions
I2C シリアルインターフェースを扱います。
- scl: SCL PIN
- sda: SDA PIN
- port: port (default 0)
- freq: frequency (default 40000)
例
i2c = I2C.new(22,21)
- i2c_adrs_7: I2C address
- [data1, data2, ...]: data array 指定されたバイトを順次出力します。
例
i2c.write( i2c_ADRS_7, [0x02, 0x16, 0x00] )
指定された文字列を出力します。
例
i2c.write( ADRS, "string" )
指定されたバイト数のデータを読み込みます。指定されたバイト数のデータが到着していない場合、ブロックします。
paramsを指定することで、read前にparamsを出力します。すなわち、以下のシーケンスとなります。
(S) - ADRS7 (W)(A) - [params ...] - (Sr) - ADRS7 (R)(A) - data_1 (A)... data_n (A|N) - (P)
S : Start condition P : Stop condition
Sr: Repeated start condition
A : Ack N : Nack
例
s = i2c.read( ADRS, 2, 0xfe ) # 0xfeレジスタから2バイト取得
- i2c_adrs_7: I2C address
- read_bytes: read_bytes (integer)
例
array = i2c.readfrom( ADRS, 2) #指定されたバイト数のデータを読み込む.
基本
- はじめの一歩 (Hello World)
- クラス定義
- サンプルプログラム
開発者向け
その他