LoginSignup
0
0

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

Last updated at Posted at 2022-08-19

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

x 超超重要 なぜか秋月STM32G031J6M6がうり切れていた。注意!!(2022/8/27現在)

x 過去ログを見よ
x PA_2をOBでGPIOに出来る人むけ
x STM32G031は、秋月で売っているSTM32G031J6M6の事

目的
秋月で売っている安価なMCP9701(約25円)を使って温度を出力する。
なぜこうなったかは、MCP9701のログをみて
センター400mV,ステップ19.5mV/1℃

o_con692.jpg

o_con693.jpg

o_con694.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 "mbed.h"

//シリアルの定義
UnbufferedSerial serial_port(PA_2, PA_3); //031

//アナログ入力の設定
AnalogIn adc_vbat(PB_7); //PB_7 ADC1/11


//メイン関数
int main()
{

    //シリアルの初期化
    serial_port.baud(9600);
    serial_port.format(
        /* bits */ 8,
        /* parity */ SerialBase::None,
        /* stop bit */ 1
    );

    //無限ループ
    while(1) {

        //センサーのADC値を0から512に変換
        int s = (int)(adc_vbat.read() * 512.0);
 
        //温度の表示
        //s = (s >> 3);
        if(s >= 184) {
            serial_port.write("40.0", 4);
        } else if(s <= 62) {
            serial_port.write("-0.0", 4);
        } else {
            serial_port.write(data[tmp_t[s-63]], 4);
        }
        serial_port.write("\r\n", 2);

        //1秒待つ
        wait_us(1000*1000);

    } //while

} //main




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