Chris Isabelle / Mbed 2 deprecated ESHD_L475VG_IOT01-Sensors-BSP

Dependencies:   mbed LPS22HB LSM6DSL MB85RSxx_SPI LSM303AGR HTS221 LIS3MDL BSP_B-L475E-IOT01

Committer:
stillChris
Date:
Thu Aug 29 17:52:45 2019 +0000
Revision:
0:f19cfceb5f7b
Child:
1:f6f0b501542a
Initial integration of sensor and FRAM drivers, (see .h for original source).; Created ESHD specific main & FRAM Test.; Included #defines (templates) for SPI1, SPI2 & SPI3.; This initial release is not tested.  Compile & build verification only.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
stillChris 0:f19cfceb5f7b 1 #include "mbed.h"
stillChris 0:f19cfceb5f7b 2
stillChris 0:f19cfceb5f7b 3 // Sensors drivers present in the BSP library
stillChris 0:f19cfceb5f7b 4 #include "stm32l475e_iot01_tsensor.h"
stillChris 0:f19cfceb5f7b 5 #include "stm32l475e_iot01_hsensor.h"
stillChris 0:f19cfceb5f7b 6 #include "stm32l475e_iot01_psensor.h"
stillChris 0:f19cfceb5f7b 7 #include "stm32l475e_iot01_magneto.h"
stillChris 0:f19cfceb5f7b 8 #include "stm32l475e_iot01_gyro.h"
stillChris 0:f19cfceb5f7b 9 #include "stm32l475e_iot01_accelero.h"
stillChris 0:f19cfceb5f7b 10 #include "MB85RSxx_SPI.h"
stillChris 0:f19cfceb5f7b 11
stillChris 0:f19cfceb5f7b 12 DigitalOut led1(LED1); //toggles as part of the main sensor loop
stillChris 0:f19cfceb5f7b 13 DigitalOut led2(LED2); //toggles during FRAM test
stillChris 0:f19cfceb5f7b 14
stillChris 0:f19cfceb5f7b 15 //reference definition: MB85RSxx_SPI(PinName mosi, PinName miso, PinName sclk, PinName nss);
stillChris 0:f19cfceb5f7b 16 //warning: code requires a single valid hFram definition - no error checking in place.
stillChris 0:f19cfceb5f7b 17 #define ESHD_FRAM_SPI2
stillChris 0:f19cfceb5f7b 18
stillChris 0:f19cfceb5f7b 19 #ifdef ESHD_FRAM_SPI1 //SPI1 pin definition: Arduino connector CN1, MB1297, RevD
stillChris 0:f19cfceb5f7b 20 MB85RSxx_SPI hFram(PC_12, PC_11, PC_10, PD_2);
stillChris 0:f19cfceb5f7b 21 #endif
stillChris 0:f19cfceb5f7b 22
stillChris 0:f19cfceb5f7b 23 #ifdef ESHD_FRAM_SPI2 //SPI2 pin definition: PMOD connector CN10, MB1297, RevD
stillChris 0:f19cfceb5f7b 24 MB85RSxx_SPI hFram(PC_12, PC_11, PC_10, PD_2);
stillChris 0:f19cfceb5f7b 25 #endif
stillChris 0:f19cfceb5f7b 26
stillChris 0:f19cfceb5f7b 27 #ifdef ESHD_FRAM_SPI3 //SPI3 pin definition: No external interface on MB1297, RevD
stillChris 0:f19cfceb5f7b 28 MB85RSxx_SPI hFram(PC_12, PC_11, PC_10, PD_2);
stillChris 0:f19cfceb5f7b 29 #endif
stillChris 0:f19cfceb5f7b 30
stillChris 0:f19cfceb5f7b 31 #define ESHD_FRAM_NUM_BYTES (8 * 1024) //8KBytes
stillChris 0:f19cfceb5f7b 32
stillChris 0:f19cfceb5f7b 33 #define ESHD_FRAM_TEST_DATA ((testAddr * 0x51)&0xff)
stillChris 0:f19cfceb5f7b 34
stillChris 0:f19cfceb5f7b 35 int ESHD_testFram(int addrOffset, int addrRange, int testMode)
stillChris 0:f19cfceb5f7b 36 {
stillChris 0:f19cfceb5f7b 37 int testData=0;
stillChris 0:f19cfceb5f7b 38 int testAddr=0;
stillChris 0:f19cfceb5f7b 39 int rtnVal = 0;
stillChris 0:f19cfceb5f7b 40
stillChris 0:f19cfceb5f7b 41 printf("\nFRAM test Utility\n");
stillChris 0:f19cfceb5f7b 42 hFram.Init();
stillChris 0:f19cfceb5f7b 43 printf("\nFRAM Fill Memory\n");
stillChris 0:f19cfceb5f7b 44
stillChris 0:f19cfceb5f7b 45 for(testAddr=0; testAddr<addrRange; testAddr++)
stillChris 0:f19cfceb5f7b 46 {
stillChris 0:f19cfceb5f7b 47 testData = 0;//ESHD_FRAM_TEST_DATA;
stillChris 0:f19cfceb5f7b 48 //fill byte by byte
stillChris 0:f19cfceb5f7b 49 hFram.write(testAddr, (char)testData);
stillChris 0:f19cfceb5f7b 50
stillChris 0:f19cfceb5f7b 51 if(testAddr&0xff)//Each 256 bytes
stillChris 0:f19cfceb5f7b 52 {
stillChris 0:f19cfceb5f7b 53 printf("."); //Print "." to the UART each 512 bytes
stillChris 0:f19cfceb5f7b 54 led2=led2?0:1; //Toggle LED2
stillChris 0:f19cfceb5f7b 55 }
stillChris 0:f19cfceb5f7b 56 }
stillChris 0:f19cfceb5f7b 57 for(testAddr=0; testAddr<addrRange; testAddr++)
stillChris 0:f19cfceb5f7b 58 {
stillChris 0:f19cfceb5f7b 59 testData = hFram.read(testAddr);
stillChris 0:f19cfceb5f7b 60 if(testAddr&0xff)//Each 256 bytes
stillChris 0:f19cfceb5f7b 61 {
stillChris 0:f19cfceb5f7b 62 printf("."); //Print "." to the UART
stillChris 0:f19cfceb5f7b 63 led2=led2?0:1; //Toggle LED2
stillChris 0:f19cfceb5f7b 64 }
stillChris 0:f19cfceb5f7b 65 if(testData != 0)// ESHD_FRAM_TEST_DATA)
stillChris 0:f19cfceb5f7b 66 {
stillChris 0:f19cfceb5f7b 67 printf("/nFRAM test failure - memory = 0x%04x, expected value = 0x%02x, data read = 0x%02x/n/n",
stillChris 0:f19cfceb5f7b 68 testAddr, testData, ESHD_FRAM_TEST_DATA);
stillChris 0:f19cfceb5f7b 69 rtnVal = -1;
stillChris 0:f19cfceb5f7b 70 }
stillChris 0:f19cfceb5f7b 71 }
stillChris 0:f19cfceb5f7b 72
stillChris 0:f19cfceb5f7b 73 printf("FRAM Test Complete\n");
stillChris 0:f19cfceb5f7b 74
stillChris 0:f19cfceb5f7b 75 return (rtnVal);
stillChris 0:f19cfceb5f7b 76 }
stillChris 0:f19cfceb5f7b 77
stillChris 0:f19cfceb5f7b 78
stillChris 0:f19cfceb5f7b 79 int main()
stillChris 0:f19cfceb5f7b 80 {
stillChris 0:f19cfceb5f7b 81 float sensor_value = 0;
stillChris 0:f19cfceb5f7b 82 int16_t pDataXYZ[3] = {0};
stillChris 0:f19cfceb5f7b 83 float pGyroDataXYZ[3] = {0};
stillChris 0:f19cfceb5f7b 84
stillChris 0:f19cfceb5f7b 85 BSP_TSENSOR_Init();
stillChris 0:f19cfceb5f7b 86 BSP_HSENSOR_Init();
stillChris 0:f19cfceb5f7b 87 BSP_PSENSOR_Init();
stillChris 0:f19cfceb5f7b 88
stillChris 0:f19cfceb5f7b 89 BSP_MAGNETO_Init();
stillChris 0:f19cfceb5f7b 90 BSP_GYRO_Init();
stillChris 0:f19cfceb5f7b 91 BSP_ACCELERO_Init();
stillChris 0:f19cfceb5f7b 92
stillChris 0:f19cfceb5f7b 93 while(1) {
stillChris 0:f19cfceb5f7b 94
stillChris 0:f19cfceb5f7b 95 led1 = 1;
stillChris 0:f19cfceb5f7b 96
stillChris 0:f19cfceb5f7b 97 sensor_value = BSP_TSENSOR_ReadTemp();
stillChris 0:f19cfceb5f7b 98 printf("\nTEMPERATURE = %.2f degC\n", sensor_value);
stillChris 0:f19cfceb5f7b 99
stillChris 0:f19cfceb5f7b 100 sensor_value = BSP_HSENSOR_ReadHumidity();
stillChris 0:f19cfceb5f7b 101 printf("HUMIDITY = %.2f %%\n", sensor_value);
stillChris 0:f19cfceb5f7b 102
stillChris 0:f19cfceb5f7b 103 sensor_value = BSP_PSENSOR_ReadPressure();
stillChris 0:f19cfceb5f7b 104 printf("PRESSURE is = %.2f mBar\n", sensor_value);
stillChris 0:f19cfceb5f7b 105
stillChris 0:f19cfceb5f7b 106 led1 = 0;
stillChris 0:f19cfceb5f7b 107
stillChris 0:f19cfceb5f7b 108 wait(1);
stillChris 0:f19cfceb5f7b 109
stillChris 0:f19cfceb5f7b 110 led1 = 1;
stillChris 0:f19cfceb5f7b 111
stillChris 0:f19cfceb5f7b 112 BSP_MAGNETO_GetXYZ(pDataXYZ);
stillChris 0:f19cfceb5f7b 113 printf("\nMAGNETO_X = %d\n", pDataXYZ[0]);
stillChris 0:f19cfceb5f7b 114 printf("MAGNETO_Y = %d\n", pDataXYZ[1]);
stillChris 0:f19cfceb5f7b 115 printf("MAGNETO_Z = %d\n", pDataXYZ[2]);
stillChris 0:f19cfceb5f7b 116
stillChris 0:f19cfceb5f7b 117 BSP_GYRO_GetXYZ(pGyroDataXYZ);
stillChris 0:f19cfceb5f7b 118 printf("\nGYRO_X = %.2f\n", pGyroDataXYZ[0]);
stillChris 0:f19cfceb5f7b 119 printf("GYRO_Y = %.2f\n", pGyroDataXYZ[1]);
stillChris 0:f19cfceb5f7b 120 printf("GYRO_Z = %.2f\n", pGyroDataXYZ[2]);
stillChris 0:f19cfceb5f7b 121
stillChris 0:f19cfceb5f7b 122 BSP_ACCELERO_AccGetXYZ(pDataXYZ);
stillChris 0:f19cfceb5f7b 123 printf("\nACCELERO_X = %d\n", pDataXYZ[0]);
stillChris 0:f19cfceb5f7b 124 printf("ACCELERO_Y = %d\n", pDataXYZ[1]);
stillChris 0:f19cfceb5f7b 125 printf("ACCELERO_Z = %d\n", pDataXYZ[2]);
stillChris 0:f19cfceb5f7b 126
stillChris 0:f19cfceb5f7b 127 led1 = 0;
stillChris 0:f19cfceb5f7b 128
stillChris 0:f19cfceb5f7b 129 ESHD_testFram(0, ESHD_FRAM_NUM_BYTES, 0);
stillChris 0:f19cfceb5f7b 130
stillChris 0:f19cfceb5f7b 131 wait(1);
stillChris 0:f19cfceb5f7b 132 }
stillChris 0:f19cfceb5f7b 133 }