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.

STM32L010と温度,STTS751で液晶温度計 (Mbed)(AQM0802A)(STM32L010F4P6)

Posted at

x mbed2リビジョン125
x リビジョンの変更ができる人むけ

x 昔、秋月で売っていた温度センサーSTTS751
代用品は、S-5851A。(おもにアドレスの違い)

目的
AQM0802Aで遊ぶ
適当にあつたI2C温度センサーを使用

o_cop162.jpg

o_cop161.jpg

LPC812MAXのプログラムとI2Cの定義が違う


//       SDA    SCL
I2C i2c(PA_10, PA_9); //010


参考

I2C_LCD_751_010_1




#include "mbed.h"

//STTS751 0x39
#define ADDR        (0x72) //  address
#define ADDR_LCD    (0x7C) //  address

//       SDA    SCL
I2C i2c(PA_10, PA_9); //010

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

char    tempval;        //温度
char    data_read[6];   //i2cバッファー

//液晶初期化配列
char INIT_com[]= {0x0,0x38,
                  0x0,0x39,
                  0x0,0x4,
                  0x0,0x14,
                  0x0,0x70,
                  0x0,0x56,
                  0x0,0x6C,
                  0x0,0x38,
                  0x0,0xC,
                  0x0,0x1,
                  0x40,0x41
                 };

//液晶のクリア
char INIT_cls[]= {0x0,0x1};

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

    //液晶の初期化
    for(int ii=0; ii<11; ii++) {
        i2c.write(ADDR_LCD, &INIT_com[ii*2], 2);
        wait_ms(2);
    }//for

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

        //液晶のクリア
        i2c.write(ADDR_LCD,INIT_cls,2);
        wait_ms(2);

        //初期化
        //set address 0
        i2c.write(ADDR, "\000", 1); //addres 0

        //温度の読み込み
        // Read temperature register
        i2c.read(ADDR, &tempval,1);

        //tempval = 21; //debug

        //液晶に出力
        // Display result
        data_read[3] = 0;
        data_read[2] = '0' + tempval - ( DIV10(tempval) * 10 ); //1の桁
        data_read[1] = '0' + DIV10(tempval);                    //10の桁
        data_read[0] = '@';
        i2c.write(ADDR_LCD, data_read,3);

        //1秒待つ
        wait_ms(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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?