ENSMM
/
I2C_SensorsTMP117
Utilisation de l'I2C avec les capteurs thermiques TMP117
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 //Includes 00002 #include "mbed.h" 00003 Timer timer; 00004 #include "USBSerial.h" 00005 00006 #define I2C_SDA PB_9 // The µcontrolleur SDA 00007 #define I2C_SCL PB_8 // The µcontrolleur SCL 00008 00009 00010 int Intervalle_Mesures = 300; //Choix de l'intervalle de mesure en sec 00011 00012 //Interrupt input 00013 InterruptIn button(PC_13); //User1 00014 00015 //USART 00016 USBSerial pc(0x1f00, 0x2012, 0x0001, false); 00017 00018 00019 //Voie I2C du F411 00020 I2C i2c(I2C_SDA, I2C_SCL); 00021 00022 //Variables 00023 00024 float tmp; 00025 char cmd[2]; 00026 00027 //Main program 00028 int main(){ 00029 00030 timer.start(); 00031 float time, time1; 00032 00033 time = timer.read_ms()/1000; 00034 00035 pc.printf("Initialiation...\t"); 00036 cmd[0] = 0x01; 00037 cmd[1] = 0x00; 00038 00039 i2c.write(0x91, cmd, 2); 00040 cmd[0] = 0x00; 00041 i2c.write(0x91, cmd, 1); 00042 00043 pc.printf("Initialiation OK\t"); 00044 00045 cmd[0] = 0; 00046 cmd[1] = 0; 00047 while (button == 1) { 00048 time1 = timer.read_ms()/1000; 00049 00050 if (time1-time>Intervalle_Mesures){ 00051 i2c.read(0x90, cmd, 2); 00052 00053 float x = float(cmd[0])*2; 00054 float y = float(cmd[1])*0.0078125; 00055 tmp = x + y; 00056 pc.printf("%0.2f", tmp); 00057 00058 time=timer.read_ms()/1000; 00059 time1=timer.read_ms()/1000; 00060 } 00061 } 00062 } 00063 00064 00065
Generated on Fri Jul 22 2022 20:38:49 by 1.7.2