1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[I2C]STM32C0116-DKでI2Cスレーブで遊ぶ。UNO3ホストで「46」を読む。

Last updated at Posted at 2025-08-08

結果

Screenshot from 2025-08-09 07-02-29.png

image_original(60).jpg

プログラム

  • 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



1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?