LoginSignup
0
0

STM32G031と温度センサーMCP9701で温度をシリアル出力(テーブル方式)

Last updated at Posted at 2022-07-06

x MCP9701-E/TO 販売コード 103199

x PA2をGPIOにがわかる人むけ

目的
安価に温度を測る。

センター 400mV
ステップ 19.5mV 1℃

1 ADC
2 VDD
3 GND
4 Serial

8 SWD
7 SWD
6 未使用-未接続
5 未使用-未接続

o_con566.jpg



//SER_MCP9701_table_031_1

static const char tmp_t[]={
0*2+0,0*2+1,0*2+1,
1*2+0,1*2+1,1*2+1,
2*2+0,2*2+1,2*2+1,
3*2+0,3*2+1,3*2+1,
4*2+0,4*2+1,4*2+1,
5*2+0,5*2+1,5*2+1,
6*2+0,6*2+1,6*2+1,
7*2+0,7*2+1,7*2+1,
8*2+0,8*2+1,8*2+1,
9*2+0,9*2+1,9*2+1,
10*2+0,10*2+1,10*2+1,
11*2+0,11*2+1,11*2+1,
12*2+0,12*2+1,12*2+1,
13*2+0,13*2+1,13*2+1,
14*2+0,14*2+1,14*2+1,
15*2+0,15*2+1,15*2+1,
16*2+0,16*2+1,16*2+1,
17*2+0,17*2+0,17*2+1,
18*2+0,18*2+0,18*2+1,
19*2+0,19*2+0,19*2+1,
20*2+0,20*2+0,20*2+1,
21*2+0,21*2+0,21*2+1,
22*2+0,22*2+0,22*2+1,
23*2+0,23*2+0,23*2+1,
24*2+0,24*2+0,24*2+1,
25*2+0,25*2+0,25*2+1,
26*2+0,26*2+0,26*2+1,
27*2+0,27*2+0,27*2+1,
28*2+0,28*2+0,28*2+1,
29*2+0,29*2+0,29*2+1,
30*2+0,30*2+0,30*2+1,
31*2+0,31*2+0,31*2+1,
32*2+0,32*2+0,32*2+1,
33*2+0,33*2+0,33*2+1,
34*2+0,34*2+0,34*2+1,
35*2+0,35*2+0,35*2+1,
36*2+0,36*2+0,36*2+1,36*2+1,
37*2+0,37*2+1,37*2+1,
38*2+0,38*2+1,38*2+1,
39*2+0,39*2+1,39*2+1
};

static const char data[][5]={
"00.0","00.5","01.0","01.5","02.0","02.5","03.0","03.5","04.0","04.5","05.0","05.5","06.0","06.5","07.0","07.5","08.0","08.5","09.0","09.5",
"10.0","10.5","11.0","11.5","12.0","12.5","13.0","13.5","14.0","14.5","15.0","15.5","16.0","16.5","17.0","17.5","18.0","18.5","19.0","19.5",
"20.0","20.5","21.0","21.5","22.0","22.5","23.0","23.5","24.0","24.5","25.0","25.5","26.0","26.5","27.0","27.5","28.0","28.5","29.0","29.5",
"30.0","30.5","31.0","31.5","32.0","32.5","33.0","33.5","34.0","34.5","35.0","35.5","36.0","66.5","37.0","37.5","38.0","38.5","39.0","39.5"
};

#include <Arduino.h>

//初期化処理
void setup()
{

  delay(3000); //not delete

  //シリアルの初期化
  Serial.setTx(PA2_ALT1);
  Serial.setHalfDuplex();
  Serial.begin(9600);

} //setup

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

  //センサーの値を読み込む
  analogReadResolution(12); // ADC 12bit mode
  int s = analogRead(A9);   // PB7  PIN1 031 センサーの読み取り値

  //温度の表示
  s = (s >> 3);
  if (s >= 184) {
    Serial.print("40.0");
  } else if (s <= 62) {
    Serial.print("-0.0");
  } else {
    Serial.print(data[tmp_t[s - 63]]);
  }
  Serial.println();

  //1秒の待ち
  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