1.SCLとSDAを接続、プルアップも忘れずに
2.電源の接続
3.下記のソースコードを書き込む
4.コンパイル実行で表示されたら終了
5.おわり
注意
mbedのリビジョンは、125
x PA9,PA10は、いつも間違えるので各自確認のこと
いぞがしい人のために
https://os.mbed.com/users/caa45040/code/AQM0802A_010_test1/
参考
STM32L010のMbedでの温度,STTS751で温度表示(AQM0802A)(STM32L010F4P6)
https://qiita.com/caa45040/items/54b5d2a9425c38b0d908
#include "mbed.h"
#define ADDR (0x7C) // address
//I2C i2c(I2C_SDA, I2C_SCL);
I2C i2c(PA_10, PA_9);
//DigitalOut myled(LED1);
//Serial pc(SERIAL_TX, SERIAL_RX);
//volatile char TempCelsiusDisplay[] = "+abc.d C";
int main()
{
char data_read[2];
//init
wait(0.2);
data_read[0] = 0x0;
data_read[1]=0x38;
i2c.write(ADDR, data_read, 2);
data_read[1]=0x39;
i2c.write(ADDR, data_read, 2);
data_read[1]=0x14;
i2c.write(ADDR, data_read, 2);
data_read[1]=0x70;
i2c.write(ADDR, data_read, 2);
data_read[1]=0x56;
i2c.write(ADDR, data_read, 2);
data_read[1]=0x6C;
i2c.write(ADDR, data_read, 2);
wait(0.2);
data_read[1]=0x38;
i2c.write(ADDR, data_read, 2);
data_read[1]=0x0C;
i2c.write(ADDR, data_read, 2);
data_read[1]=0x01;
i2c.write(ADDR, data_read, 2);
wait(0.2);
data_read[0]='@';
data_read[1]='a';
i2c.write(ADDR, data_read, 2);
while (1) {
// Display result
// pc.printf("temp = %s\n", TempCelsiusDisplay);
// myled = !myled;
wait(2.0);
}
}