Environmental_Shield_F4_API

Dependencies:   mbed

Fork of Environmental_sheild_F4 by Sumit Johar

Committer:
Deepti
Date:
Thu Aug 14 05:25:37 2014 +0000
Revision:
2:e88266f73a67
Parent:
1:745a595b1df2
Environmental_Shield_F4_API

Who changed what in which revision?

UserRevisionLine numberNew contents of line
manoj123 0:c3c9b1c8e3cb 1 #include "mbed.h"
manoj123 0:c3c9b1c8e3cb 2 #include "nucleo-f401re.h"
manoj123 0:c3c9b1c8e3cb 3 #include "x_nucleo_ike01x1_pressure.h"
manoj123 0:c3c9b1c8e3cb 4 #include "x_nucleo_ike01x1_uv.h"
manoj123 0:c3c9b1c8e3cb 5 #include "x_nucleo_ike01x1_hum_temp.h"
manoj123 0:c3c9b1c8e3cb 6 //------------------------------------
manoj123 0:c3c9b1c8e3cb 7 // Hyperterminal configuration
manoj123 0:c3c9b1c8e3cb 8 // 9600 bauds, 8-bit data, no parity
manoj123 0:c3c9b1c8e3cb 9 //------------------------------------
manoj123 0:c3c9b1c8e3cb 10 uint8_t PRESInit=0;
manoj123 0:c3c9b1c8e3cb 11 uint8_t UVInit=0;
manoj123 0:c3c9b1c8e3cb 12 uint8_t HumTempInit=0;
manoj123 0:c3c9b1c8e3cb 13 /*Global variables */
manoj123 0:c3c9b1c8e3cb 14 uint8_t HumTempId=0;
manoj123 0:c3c9b1c8e3cb 15 uint8_t PressID=0;
manoj123 0:c3c9b1c8e3cb 16 int dec_precision = 2;
manoj123 0:c3c9b1c8e3cb 17 volatile float UVI_Value;
manoj123 0:c3c9b1c8e3cb 18 volatile float PRESSURE_Value;
manoj123 0:c3c9b1c8e3cb 19 volatile float HUMIDITY_Value;
manoj123 0:c3c9b1c8e3cb 20 volatile float TEMPERATURE_Value;
manoj123 0:c3c9b1c8e3cb 21 void floatToInt(float in, int32_t *out_int, int32_t *out_dec, int32_t dec_prec);
manoj123 0:c3c9b1c8e3cb 22 Serial pc(SERIAL_TX, SERIAL_RX);
manoj123 0:c3c9b1c8e3cb 23
manoj123 0:c3c9b1c8e3cb 24 DigitalOut myled(LED1);
manoj123 0:c3c9b1c8e3cb 25
manoj123 0:c3c9b1c8e3cb 26 int main()
manoj123 0:c3c9b1c8e3cb 27 {
manoj123 0:c3c9b1c8e3cb 28
manoj123 0:c3c9b1c8e3cb 29 int mul = 1;
manoj123 0:c3c9b1c8e3cb 30 for(int i = 0; i < dec_precision; i++)
manoj123 0:c3c9b1c8e3cb 31 mul = mul*10;
manoj123 0:c3c9b1c8e3cb 32
manoj123 0:c3c9b1c8e3cb 33 if(!BSP_HUM_TEMP_isInitialized()) {
manoj123 0:c3c9b1c8e3cb 34 BSP_HUM_TEMP_Init(); //This also Inits I2C interface from here.
manoj123 0:c3c9b1c8e3cb 35 }
manoj123 0:c3c9b1c8e3cb 36 HumTempId = BSP_HUM_TEMP_ReadID();
manoj123 0:c3c9b1c8e3cb 37 if(HumTempId==I_AM_HTS221){
manoj123 0:c3c9b1c8e3cb 38 HumTempInit=1;
manoj123 0:c3c9b1c8e3cb 39 }
manoj123 0:c3c9b1c8e3cb 40 /*End Temp Sensor Init*/
manoj123 0:c3c9b1c8e3cb 41
manoj123 0:c3c9b1c8e3cb 42 /*Initialize the pressure sensors*/
manoj123 0:c3c9b1c8e3cb 43 if(!BSP_PRESSURE_isInitialized()) {
manoj123 0:c3c9b1c8e3cb 44 BSP_PRESSURE_Init(); //This also Inits I2C interface from here.
manoj123 0:c3c9b1c8e3cb 45 PRESInit=1;
manoj123 0:c3c9b1c8e3cb 46 }
manoj123 0:c3c9b1c8e3cb 47 PressID = BSP_PRESSURE_ReadID();
manoj123 0:c3c9b1c8e3cb 48
manoj123 0:c3c9b1c8e3cb 49 int32_t d1, d2, d3, d4;
manoj123 0:c3c9b1c8e3cb 50
manoj123 0:c3c9b1c8e3cb 51 pc.printf("Hello World !\n");
manoj123 0:c3c9b1c8e3cb 52 while(1) {
manoj123 0:c3c9b1c8e3cb 53 wait(1);
manoj123 0:c3c9b1c8e3cb 54
manoj123 0:c3c9b1c8e3cb 55 if(BSP_HUM_TEMP_isInitialized())
manoj123 0:c3c9b1c8e3cb 56 {
manoj123 0:c3c9b1c8e3cb 57 BSP_HUM_TEMP_GetHumidity((float *)&HUMIDITY_Value);
manoj123 0:c3c9b1c8e3cb 58 BSP_HUM_TEMP_GetTemperature((float *)&TEMPERATURE_Value);
manoj123 0:c3c9b1c8e3cb 59
manoj123 0:c3c9b1c8e3cb 60 floatToInt(HUMIDITY_Value, &d1, &d2, mul);
manoj123 0:c3c9b1c8e3cb 61 floatToInt(TEMPERATURE_Value, &d3, &d4, mul);
manoj123 0:c3c9b1c8e3cb 62 pc.printf("H: %d.%02d T: %d.%02d", d1, d2, d3, d4);
manoj123 0:c3c9b1c8e3cb 63
manoj123 0:c3c9b1c8e3cb 64 }
manoj123 0:c3c9b1c8e3cb 65
manoj123 0:c3c9b1c8e3cb 66 if(BSP_PRESSURE_isInitialized())
manoj123 0:c3c9b1c8e3cb 67 {
manoj123 0:c3c9b1c8e3cb 68 BSP_PRESSURE_GetPressure((float *)&PRESSURE_Value);
manoj123 0:c3c9b1c8e3cb 69 floatToInt(PRESSURE_Value, &d1, &d2, mul);
manoj123 0:c3c9b1c8e3cb 70 pc.printf(" P: %d.%02d\n", d1, d2);
manoj123 0:c3c9b1c8e3cb 71
manoj123 0:c3c9b1c8e3cb 72 }
manoj123 0:c3c9b1c8e3cb 73
manoj123 0:c3c9b1c8e3cb 74 if(BSP_UV_isInitialized())
manoj123 0:c3c9b1c8e3cb 75 {
manoj123 0:c3c9b1c8e3cb 76 BSP_UV_GetIndex((float *)&UVI_Value);
manoj123 0:c3c9b1c8e3cb 77 floatToInt(UVI_Value, &d1, &d2, mul);
manoj123 0:c3c9b1c8e3cb 78 pc.printf("UV: %d.%02d\n", d1, d2);
manoj123 0:c3c9b1c8e3cb 79 }
manoj123 0:c3c9b1c8e3cb 80
sjohar 1:745a595b1df2 81 pc.printf("Done");
manoj123 0:c3c9b1c8e3cb 82 myled = !myled;
manoj123 0:c3c9b1c8e3cb 83 }
manoj123 0:c3c9b1c8e3cb 84 }
manoj123 0:c3c9b1c8e3cb 85 void floatToInt(float in, int32_t *out_int, int32_t *out_dec, int32_t dec_prec)
manoj123 0:c3c9b1c8e3cb 86 {
manoj123 0:c3c9b1c8e3cb 87 *out_int = (int32_t)in;
manoj123 0:c3c9b1c8e3cb 88 in = in - (float)(*out_int);
manoj123 0:c3c9b1c8e3cb 89 *out_dec = (int32_t)(in*dec_prec);
manoj123 0:c3c9b1c8e3cb 90 }