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?

More than 1 year has passed since last update.

STM32G071とI2Cを使い0x40(8ビット表記0x80)に「hello...」と出力する。(Arduino)

Posted at

x NUCLEO-G071RB

目的
I2Cのテスト
I2C->USART9600bps->USBのテスト

o_con759.jpg

STM32G031とVSCode+STM32CubeでI2Cスレーブの受信文字をシリアル出力(受信)(STM32-I2C-USART)(CH340N)




//I2C_HELLO_071_1

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

#define D_LED1     PA5

#define ADDR1  0x40


//文字の表示 nana_seg
int ns_putc(char str1)
{

  //I2Cに送信
  Wire.beginTransmission(ADDR1);
  Wire.write( str1 );
  Wire.endTransmission();

  delay(1);//連続送信防止の為に1ms待つ

  //戻り値
  return (0);

}//ns_putc


//文字列の表示 nana_seg
int ns_puts(char *str1)
{

  //文字の中身がゼロか
  while (*str1) {

    ns_putc( *str1 ++  );

  } //while

  //戻り値
  return (0);

}//ns_puts


//初期化
void setup() {

  //GPIOの初期化
  pinMode(D_LED1, OUTPUT);

  //i2cの初期化
  Wire.begin(); //071

}//setup


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

  digitalWrite(D_LED1, 1); //LED ON debug

  //I2Cに文字列を出力
  ns_puts("hello world\r\n");

  delay(500);//0.5秒待つ


  digitalWrite(D_LED1, 0); //LED OFF debug
  delay(500);//0.5秒待つ

}//loop






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?