LoginSignup
0
0

STM32F767と温度センサーMCP9701で温度をシリアル出力 (Mbed)

Last updated at Posted at 2021-06-27

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

x あまり正確では、ない

目的
秋月で売っている安価なMCP9701(約25円)を使って温度を出力する。

構成
MCP9701-E/TO I-03199

説明
MCP9701は、
0℃の時、400mV
1℃あたり19.5mV
精度は、±4℃
電線が引き出しやすい位置のA0をアナログ入力にする
計算には、容量削減の為に浮動小数点と割り算は、使わない
MCP9700は、ファミリー、オフセット500mV、10mV/1℃ 今回は、使わない


//温度

#include "mbed.h"

//10の割り算 0から1028までは、正しい。主に0から999
#define DVI10(n) ((n*205)>>11)

//アナログ入力の設定
//AnalogIn adc_vbat(A3); //PA_4
AnalogIn adc_vbat(A0); //767 303

//Serial pc(USBTX, USBRX); // tx, rx
Serial pc(SERIAL_TX, SERIAL_RX); //767 303
//Serial pc(PA_2, PA_3); //010
//Serial pc(PA_9, PA_10); //010

int main() {

    int s;  //ADCの値
    int n0; //温度 小数点以上

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

        //adcの読み込み 0から4096
        s = (adc_vbat.read_u16()>>4);

        //電圧を温度に変換 ex 20.0 -> 200 温度の十倍を出力
        s=((s-496)*27081)>>16;

        //s = 0;   //0  debug
        //s = 200; //20 debug

        //小数点以上と小数点以下を分ける
        n0=DVI10(s);    // 小数点以上
        s =(s-(n0*10)); // 小数点以下

        //温度の表示
        pc.printf("%d.%d\r\n",n0,s); //767 303

        //1秒の待ち
        wait_ms(1000);

    } //while

} //main



adc_9701_767M_1.jpg

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