結果
プログラム
- I2Cスレーブ stm32c0116-dk
//I2C_slave_OUT_46_c0116_1
//インクルド
#include <Arduino.h>
#include <Wire.h> //I2C
//初期化処理
void setup() {
//I2Cの初期化
Wire.begin(0x80 >> 1); // Slave ID #80
Wire.onRequest(requestEvent); //呼ばれる関数
} //setup
//メインループ
void loop() {
delay(3); //ダミー
} //loop
//I2Cの読み取り関数
void requestEvent() {
//値の送信
Wire.write(46);
} //requestEvent
- I2Cマスター Arduino UNO V3
//I2C_master_IN_46_UNO_1A
//インクルド
#include <Arduino.h>
#include <Wire.h> //I2C
//初期化
void setup() {
Serial.begin(9600); //シリアルポートの初期化
Wire.begin(); //I2Cの初期化
} //setup
//メインループ
void loop() {
//読み込み
Wire.requestFrom(0x80 >> 1, 1);
int b = 99; //読み込み値 バイナリーの「b」
while (Wire.available()) { // 要求より短いデータが来る可能性あり
b = Wire.read(); // 1バイトを受信
} //while
//値を表示
Serial.println(b);
delay(1000); //1秒待つ
} //loop