0
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]STM32G030F6、1ビット拡張エキスパンダー(I2Cスレーブ拡張I.O)

Posted at

参考

いろいろ注意

  • 過去ログを見よ!!!

結果

Screenshot from 2025-10-26 20-20-49.png

Screenshot from 2025-10-26 20-20-58.png

プログラム




//I2C_Slave_1bit_ext_out_STM32G030F6_1


//インクルド
#include <Arduino.h>
#include <Wire.h>  // I2C


//定義
#define DD 4  // PA4 OUTPUT pin x (ダイレクトドライブ)


//初期化
void setup() {

  //I2Cのポートの変更
  Wire.setSDA(10);  //PA10
  Wire.setSCL(9);   //PA9

  //I2Cの初期化
  Wire.begin(0x80 >> 1);         // I2Cスレーブアドレスの設定
  Wire.onReceive(receiveEvent);  // データが来ると呼ばれる関数

  //GPIOの初期化
  pinMode(DD, OUTPUT);  // sets the LED pin as output
  digitalWrite(DD,1);   //LED off

}  //setup


//メインループ
void loop() {

  delay(3);  //ダミー

}  //loop


//レシーブイベント(受信)
void receiveEvent(int howMany) {

  int x = Wire.read();  // I2C受信データの読み込み

  digitalWrite(DD, ((~x) & 0x01));  // 1bit出力

}  //receiveEvent




0
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
0
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?