x 超超重要 なぜか秋月STM32G031J6M6がうり切れていた。注意!!(2022/8/27現在)
x 過去ログを見よ!!(S-5851と7セグ)
x 3秒以内に書き込み器を接続してコネクト
x STM32G031とは、秋月で売っているSTM32G031J6M6の事
x OBでBoot pinレガシーとNRST(3)リセットと内部リセット出力に変更できる人むけ
x SWDをつぶすので注意
x 書き込み器のリセットを繋ぐと書き換えが簡単に出来る
1.SCLとSDAを接続、プルアップも忘れずに
2.電源の接続
3.下記のソースコードを書き込む
4.コンパイル実行で表示されたら終了
5.おわり
参考
// gpio_7seg_5851_031_1
#include "mbed.h"
//******* ****** ***** *****
// * * * *
// * * ***** * ***
// * **** * * *
// * * * * *
// * ***** ***** *****
#define swclk1 PA_14 //
#define swdio1 PA_13 //
#define en1 PB_7 //
DigitalOut swdclk(swclk1);
DigitalOut swdio(swdio1);
DigitalOut en(en1);
char seg[32] = {
0x00, //0 @ -> ' '
0x77, //1 A o
0x7c, //2 B combined use "6"
0x39, //3 C
0x5e, //4 D
0x79, //5 E o
0x71, //6 F
0x3d, //7 G
0x76, //8 H o
0x06, //9 I combined use "1"
0x1e, //10 J
0x75, //11 K
0x38, //12 L o
0x15, //13 M
0x37, //14 N o
0x3f, //15 O o combined use "0"
0x73, //16 P
0x67, //17 Q combined use "9"
0x50, //18 R
0x6d, //19 S combined use "5"
0x78, //20 T
0x3e, //21 U
0x1c, //22 V
0x2a, //23 W o
0x64, //24 X
0x6e, //25 Y
0x5b, //26 Z combined use "2"
0x4f, //27 [ --> "3"
0x66, //28 \ --> "4"
0x27, //29 ] --> "7"
0x7f, //26 ^ --> "8"
0x08 //31 _
};
void seg1(char v)
{
for(int jj=0; jj<8; jj++) {
if( (v<<jj) & 0x80 ) {
swdio=1; //ビットが1
} else {
swdio=0; //ビットが0
}//endif
swdclk=1;
swdclk=0; //clk
}//for
en=1;
en=0;
}//seg1
char nn[]= {'O','I','Z','[','\\','S','B', ']','^','Q'};
int comma1=0; // コンマ(小数点)の有効フラグ 1で有効 0無効
//7segの一文字出力 nana_seg
int ns_putc(char ch) {
if(ch == ' ') {
ch = '@';
} else if(ch == '.') {
return(0);
} else if (ch >= '0' && ch <= '9' ) {
ch = nn[ch-'0'];
}
if( comma1 != 0 ) { comma1 = (0x80); }
seg1(seg[ch-64] | comma1 );
comma1 = 0;
//戻り値
return(0);
}//ns_putc
//文字列の表示 nana_seg
int ns_printf(char *str1) {
//文字の中身がゼロか
while(*str1){
//コンマの処理
comma1=0;
if( (*(str1+1) ) == '.' ) { comma1=1; }
//一文字出力
ns_putc(*str1 ++);
} //while
//戻り値
return(0);
}//ns_printf
// sda scl
I2C i2c(PA_12, PA_11); //010
//メイン関数
int main()
{
// 3s wait not delete
wait_us(3000*1000);
char data_read[8]; //バッファー
char out_buff[8]; //バッファー
//7セグの初期化
en=0;
swdclk=0;
ns_printf( (char *)"ST");
wait_us(500*1000); //debug
//初期値の表示
ns_printf( (char *)" 0.");
wait_us(1000*1000);
//無限ループ
while(1) {
//初期化
//set address 0
i2c.write(0x90, "\000", 1); wait_us(1000);//addres 0
//温度の読み込み
// Read temperature register
i2c.read(0x90 | 1, data_read,2,false); wait_us(1000);
//画面に表示
sprintf( out_buff, "%2d.", data_read[0] );
ns_printf(out_buff);
//1秒待つ
wait_us(1000*1000);
}//while
}//main