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?

Arduino で i2cdetect する(STM32G030F6)

Last updated at Posted at 2025-10-23

参考

いろいろ注意

  • 研究、調査の為に引用しました。
  • 過去ログを見よ!!!
  • 今風に改造した。
  • STM32G030F6

  Wire.setSDA(10);  //PA10
  Wire.setSCL(9);   //PA9
  

結果

  • SSD1306

Screenshot from 2025-10-24 09-06-50.png

Screenshot from 2025-10-24 08-07-09.png

  • Arduino Modulino Buzzer

Screenshot from 2025-10-24 09-48-02.png

Screenshot from 2025-10-24 09-45-29.png

プログラム



//stm32 esp32
//i2cdetect_example_STM32G030F6

#include <Arduino.h>
#include <Wire.h>
#include "i2cdetect.h"

void setup() {


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


  Wire.begin();
  Serial.begin(9600);
  delay(3000);
}

void loop() {
  Serial.println("-- i2cdetect --");
  i2cdetect();
  delay(3000);
}



i2cdetect.cpp



//stm32 esp32

#include <Arduino.h>
#include <Wire.h>
#include "i2cdetect.h"

/*
// _printf base code: http://playground.arduino.cc/Main/Printf
#include <stdarg.h>
#define PRINTF_BUF 80 // define the tmp buffer size (change if desired)
void _printf(const char *format, ...)
{
  char buf[PRINTF_BUF];
  va_list ap;
  va_start(ap, format);
  vsnprintf(buf, sizeof(buf), format, ap);
  for(char *p = &buf[0]; *p; p++) // emulate cooked mode for newlines
  {
    if(*p == '\n')
      Serial.write('\r');
    Serial.write(*p);
  }
  va_end(ap);
}
*/

void i2cdetect(uint8_t first, uint8_t last) {
  uint8_t i, j, address, error;

  // header
  Serial.print("   ");
  for (i = 0; i < 16; i++) {
    //_printf("%3x", i);
    Serial.printf("%3x", i);  //stm32 esp32
  }
  Serial.println();

  for (j = 0; j < 8; j++) {
    //_printf("%02d:", j*10);
    Serial.printf("%02d:", j * 10);  //stm32 esp32
    for (i = 0; i < 16; i++) {
      address = i + j * 16;
      if (address >= first && address <= last) {
        Wire.beginTransmission(address);
        error = Wire.endTransmission();
        if (error) {
          Serial.print(" --");
        } else {
          //_printf(" %02x", address);
          Serial.printf(" %02x", address);  //stm32 esp32
        }
      } else {
        Serial.print("   ");
      }
    }
    Serial.println();
  }
}

void i2cdetect() {
  i2cdetect(0x03, 0x77);
}


i2cdetect.h



//stm32 esp32

#ifndef __I2CDETECT_H_
#define __I2CDETECT_H_

void i2cdetect(uint8_t first, uint8_t last);
void i2cdetect();

#endif


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?