Utilisation de l'I2C avec les capteurs thermiques TMP117

Dependencies:   mbed USBDevice

Revision:
9:ec201f39892f
Parent:
7:f5e10b18984d
--- a/main.cpp	Tue Dec 17 14:25:24 2019 +0000
+++ b/main.cpp	Tue Jan 28 11:09:13 2020 +0000
@@ -1,95 +1,65 @@
-//Includes
-
+ //Includes
 #include "mbed.h"
-#include "SimpleBLE.h"
-#include "LIS3DH.h"
-
-//Accelerometer
+Timer timer;
+#include "USBSerial.h"
 
-#define MOSI PC_12
-#define MISO PC_11
-#define CS PC_5
-#define SCLK PC_10
-
-//Init simpleBLE
-
-SimpleBLE ble("ObCP_CROC_ENSMM");
+#define I2C_SDA                  PB_9           // The µcontrolleur SDA 
+#define I2C_SCL                  PB_8           // The µcontrolleur SCL
 
 
-// GPIO set
+int Intervalle_Mesures = 300;      //Choix de l'intervalle de mesure en sec
 
 //Interrupt input
-
-InterruptIn user1(PC_13);  //User1
-
-//PWM output
-
-PwmOut PWMoutput(PB_1);          //Main PWM output
-PwmOut Green(PC_8);              //PWM Red LED
-PwmOut Red(PC_6);                //PWM Green LED
-PwmOut Blue(PC_9);               //PWM Blue LED
+InterruptIn button(PC_13); //User1
 
-//Init accelerometer
-
-LIS3DH      acc(MOSI, MISO, SCLK, CS, LIS3DH_DR_NR_LP_50HZ, LIS3DH_FS_2G);
-
-// Characteristics Accelerometer input
-
-SimpleChar<float> accX = ble.readOnly_float(0xA000, 0xA002);
-SimpleChar<float> accY = ble.readOnly_float(0xA000, 0xA003);
-SimpleChar<float> accZ = ble.readOnly_float(0xA000, 0xA004);
+//USART
+USBSerial pc(0x1f00, 0x2012, 0x0001, false);
 
 
-// When characteristic LED RGB changing
-
-void LEDupdate(uint32_t newColor)
-{
-    // read individual bytes
-    uint8_t* channels = (uint8_t*)&newColor;
-
-    // cast to float, as PwmOut expects a value between 0.0f and 1.0f
-    Red   = static_cast<float>(channels[0]) / 255.0f;
-    Green = static_cast<float>(channels[1]) / 255.0f;
-    Blue  = static_cast<float>(channels[2]) / 255.0f;
-}
-
-// When characteristic PWM output changing
-
-void PWMupdate(uint8_t pwmvalue)
-{
+//Voie I2C du F411
+I2C i2c(I2C_SDA, I2C_SCL);
 
-    // cast to float, as PwmOut expects a value between 0.0f and 1.0f
-    PWMoutput   = static_cast<float>(pwmvalue) / 255.0f;
-}
-
-// When characteristic input changing
-void Accupdate()
-{
+//Variables
 
-    accX = float(short((acc.read_reg(LIS3DH_OUT_X_H) << 8) | acc.read_reg(LIS3DH_OUT_X_L))) * 0.001F / 15;
-    accY = float(short((acc.read_reg(LIS3DH_OUT_Y_H) << 8) | acc.read_reg(LIS3DH_OUT_Y_L))) * 0.001F / 15;
-    accZ = float(short((acc.read_reg(LIS3DH_OUT_Z_H) << 8) | acc.read_reg(LIS3DH_OUT_Z_L))) * 0.001F / 15;
-
-}
-
-// Characteritic PWM LED RGB
-SimpleChar<uint32_t> color = ble.writeOnly_u32(0x6200, 0x6201, &LEDupdate);
-
-// Characteristic PWM output
-SimpleChar<uint8_t> pwmout = ble.writeOnly_u8(0xA000, 0xA001, &PWMupdate);
-
+float tmp;
+char cmd[2];
 
 //Main program
-
-int main(int, char**)
-{
-
-    ble.start();
-    Ticker t;
-    t.attach(&Accupdate, 5.0f);
-
-    while (1) {
-        ble.waitForEvent();
-
+int main(){
+    
+    timer.start();
+    float time, time1;
+    
+    time = timer.read_ms()/1000;
+    
+    pc.printf("Initialiation...\t");
+    cmd[0] = 0x01;
+    cmd[1] = 0x00;
+        
+    i2c.write(0x91, cmd, 2);
+    cmd[0] = 0x00;
+    i2c.write(0x91, cmd, 1);
+    
+    pc.printf("Initialiation OK\t");
+    
+    cmd[0] = 0;
+    cmd[1] = 0;
+    while (button == 1) {
+        time1 = timer.read_ms()/1000;
+        
+        if (time1-time>Intervalle_Mesures){
+            i2c.read(0x90, cmd, 2);
+        
+            float x = float(cmd[0])*2;
+            float y = float(cmd[1])*0.0078125;
+            tmp = x + y;
+            pc.printf("%0.2f", tmp);
+            
+            time=timer.read_ms()/1000;
+            time1=timer.read_ms()/1000;
+        }
     }
 }
+        
+        
+