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.

STM32G031J6M6のPA2ハードウェアシリアルから出力(2日掛けて完成)

Last updated at Posted at 2022-05-26

x 動作確認済み2022/5/28 20:16

x OBでPA0をGPIOにするがわかる人むけ

x 場合によっては、二度と書き込めなくなります。

目的
動くかどうかわからないがやってみる
結果動いた

答え合わせ



  Serial.setTx(PA2_ALT1);
  //Serial.setTx(PA14);
  //Serial.setTx(PB6);
  Serial.setHalfDuplex();
  Serial.begin(9600);


o_con501.jpg

o_con502.jpg

o_con503.jpg



8

  PB6  USART1_TX

  PA14 USART2_TX 
  PA15 USART2_RX

1

  PB7 USART1_RX

4

  PA2 USART2_TX

  PA2 LPUART_TX



名前は、まだない




STM32G031-DISCO

Enabled(generic Serial)
 Serial1.begin(9600);    OK?->NG
 Serial2.begin(9600);    NG
 SerialLP1.begin(9600);  NG

Enabled(no generic Serial)
 Serial1.begin(9600);    NG
 Serial2.begin(9600);    NG
 SerialLP1.begin(9600);  NG

Disabled(no Serial support)
 Serial1.begin(9600);    NG
 Serial2.begin(9600);    NG
 SerialLP1.begin(9600);  NG





Nucleo G031K8

Enabled(generic Serial)
 Serial1.begin(9600);    NG
 Serial2.begin(9600);    NG
 SerialLP1.begin(9600);  OK?->NG

Enabled(no generic Serial)
 Serial1.begin(9600);    NG
 Serial2.begin(9600);    NG
 SerialLP1.begin(9600);  NG

Disabled(no Serial support)
 Serial1.begin(9600);    NG
 Serial2.begin(9600);    NG
 SerialLP1.begin(9600);  NG


検証プログラム



//SER_PA_2_test_031_2

#include <Arduino.h>
#include <HardwareSerial.h>

//初期化
void setup() {

  delay(3000); //not Delete

 //extern HardwareSerial Serial;
 //Serial.setTx(PA2);
 //Serial.setRx(PA2);
 //Serial.setHalfDuplex();
 //Serial.begin(9600);
 //while(1){Serial.println("0");delay(2000);}


 //extern HardwareSerial Serial1;
 //Serial1.setTx(PA2);
 //Serial1.setRx(PA2);
 //Serial1.setHalfDuplex();
 //Serial1.begin(9600);
 //while(1){Serial1.println("0");delay(2000);}


 //extern HardwareSerial Serial2;
 //Serial2.setTx(PA2);
 //Serial2.setRx(PA2);
 //Serial2.setHalfDuplex();
 //Serial2.begin(9600);
 //while(1){Serial2.println('0');delay(2000);}


 //extern HardwareSerial SerialLP1;
 SerialLP1.setTx(PA2);
 SerialLP1.setRx(PA2);
 SerialLP1.setHalfDuplex();
 SerialLP1.begin(9600);
 while(1){SerialLP1.println('0');delay(2000);}

}//setup

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




(ちょとだけ前進)

PA14に注目

o_con499.jpg



//SER_HalfDuplex_test_031_2


#include <Arduino.h>
#include <HardwareSerial.h>


//初期化
void setup() {

  Serial.setTx(PA14);
  //Serial.setTx(PB6);
  Serial.setHalfDuplex();
  Serial.begin(9600);

  pinMode(PB7, OUTPUT);

}//setup


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

  Serial.println("Hello World");

  digitalWrite(PB7, HIGH);
  delay(1000);
  digitalWrite(PB7, LOW);
  delay(1000);

}//loop



(完成) PA2からハローワールドの出力

o_con500.jpg




//SER_HalfDuplex_test_031_2


#include <Arduino.h>
#include <HardwareSerial.h>


//初期化
void setup() {

  delay(3000);

  Serial.setTx(PA2_ALT1);
  //Serial.setTx(PA14);
  //Serial.setTx(PB6);
  Serial.setHalfDuplex();
  Serial.begin(9600);

  pinMode(PB7, OUTPUT);

}//setup


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

  Serial.println("Hello World");

  digitalWrite(PB7, HIGH);
  delay(1000);
  digitalWrite(PB7, LOW);
  delay(1000);

}//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?