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

Last updated at Posted at 2025-08-07

参考

目的

  • 0x80アドレスにデータを送ってLEDを光らす。(arduino的には、0x40
  • たぶん、秋月でIOエキスパンダーを買った方が安い。
  • UNO3は、軽くプルアップがかかっている、らしいが?、プルアップ抵抗は、必要(動けば正義!!!(プルアップ抵抗警察に捕まっちゃうよ!!!

結果

image_original(58).jpg

image_original(59).jpg

プログラム



//I2C_Slave_1bit_ext_out_C0116_1


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


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


//初期化
void setup() {

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

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

}  //setup


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

  delay(3);  //ダミー

}  //loop


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

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

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

}  //receiveEvent



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?