Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed LPS22HB LSM6DSL MB85RSxx_SPI LSM303AGR HTS221 LIS3MDL BSP_B-L475E-IOT01
main.cpp
00001 #include <iostream> 00002 #include "mbed.h" 00003 00004 // Sensors drivers present in the BSP library 00005 #include "stm32l475e_iot01_tsensor.h" 00006 #include "stm32l475e_iot01_hsensor.h" 00007 #include "stm32l475e_iot01_psensor.h" 00008 #include "stm32l475e_iot01_magneto.h" 00009 #include "stm32l475e_iot01_gyro.h" 00010 #include "stm32l475e_iot01_accelero.h" 00011 #include "MB85RSxx_SPI.h" 00012 00013 //DigitalOut led1(LED1); //toggles as part of the main sensor loop 00014 DigitalOut led2(LED2); //toggles during FRAM test 00015 00016 //reference definition: MB85RSxx_SPI(PinName mosi, PinName miso, PinName sclk, PinName nss); 00017 //warning: code requires a single valid hFram definition - no error checking in place. 00018 #define ESHD_FRAM_SPI1 00019 00020 #ifdef ESHD_FRAM_SPI1 //SPI1 pin definition: Arduino connector CN1, MB1297, RevD 00021 MB85RSxx_SPI hFram(PA_7, PA_6, PA_5, PA_2); 00022 #endif 00023 00024 #ifdef ESHD_FRAM_SPI2 //SPI2 pin definition: PMOD connector CN10, MB1297, RevD 00025 MB85RSxx_SPI hFram(PD_4, PD_3, PD_1, PD_5); 00026 #endif 00027 00028 #ifdef ESHD_FRAM_SPI3 //SPI3 pin definition: No external interface on MB1297, RevD 00029 MB85RSxx_SPI hFram(PC_12, PC_11, PC_10, PC_9); 00030 #endif 00031 00032 #define ESHD_FRAM_NUM_BYTES (8 * 1024) //8KBytes 00033 00034 #define ESHD_FRAM_TEST_DATA ((testAddr * 0x51)&0xff) 00035 00036 #define ESHD_RUN_SENSOR_LOOP 00037 //#define SINGLE_STEP_SPI_WRITE 00038 //#define SINGLE_STEP_SPI_READ 00039 #define ESHD_FRAM_TEST_ERROR_INSERT 0 //set one bit in the ESHD_FRAM_TEST_ERROR_INSERT byte to intentionally induce write errors 00040 00041 int ESHD_testFram(int addrOffset, int addrRange, int testMode) 00042 { 00043 int testData=0; 00044 int testAddr=0; 00045 int rtnVal = 0; 00046 00047 printf("\nFRAM test Utility\n"); 00048 printf("~~~~~~~~~~~~~~~~~\n\n"); 00049 hFram.Init(); 00050 printf("\nFRAM Fill Memory\n"); 00051 00052 for(testAddr=0; testAddr<addrRange; testAddr++) 00053 { 00054 testData = ESHD_FRAM_TEST_DATA | ESHD_FRAM_TEST_ERROR_INSERT; 00055 //fill byte by byte 00056 hFram.write(testAddr, (char)testData); 00057 #ifdef SINGLE_STEP_SPI_WRITE 00058 int step; 00059 cin >> step; 00060 #endif 00061 } 00062 printf("\nFRAM Read-Check\n"); 00063 00064 for(testAddr=0; testAddr<addrRange; testAddr++) 00065 { 00066 testData = hFram.read(testAddr); 00067 if(testData != ESHD_FRAM_TEST_DATA) 00068 { 00069 printf("\nFRAM test failure - memory = 0x%04x, expected value = 0x%02x, data read = 0x%02x\n\n", 00070 testAddr, ESHD_FRAM_TEST_DATA, testData); 00071 rtnVal = -1; 00072 } 00073 #ifdef SINGLE_STEP_SPI_WRITE 00074 int step; 00075 cin >> step; 00076 #endif 00077 } 00078 printf("\nFRAM Test Complete\n"); 00079 00080 return (rtnVal); 00081 } 00082 00083 00084 int main() 00085 { 00086 printf("\n\nESHD Main Menu\n"); 00087 printf("~~~~~~~~~~~~~~\n\n"); 00088 00089 #ifdef ESHD_RUN_SENSOR_LOOP 00090 float sensor_value = 0; 00091 int16_t pDataXYZ[3] = {0}; 00092 float pGyroDataXYZ[3] = {0}; 00093 00094 BSP_TSENSOR_Init(); 00095 BSP_HSENSOR_Init(); 00096 BSP_PSENSOR_Init(); 00097 00098 BSP_MAGNETO_Init(); 00099 BSP_GYRO_Init(); 00100 BSP_ACCELERO_Init(); 00101 00102 while(1) { 00103 printf("\n\nESHD Sensor Loop\n"); 00104 printf("~~~~~~~~~~~~~~~~\n\n"); 00105 00106 led2 = 1; 00107 00108 sensor_value = BSP_TSENSOR_ReadTemp(); 00109 printf("TEMPERATURE = %.2f degC\n", sensor_value); 00110 00111 sensor_value = BSP_HSENSOR_ReadHumidity(); 00112 printf("HUMIDITY = %.2f %%\n", sensor_value); 00113 00114 sensor_value = BSP_PSENSOR_ReadPressure(); 00115 printf("PRESSURE is = %.2f mBar\n", sensor_value); 00116 00117 led2 = 0; 00118 00119 wait(1); 00120 00121 led2 = 1; 00122 00123 BSP_MAGNETO_GetXYZ(pDataXYZ); 00124 printf("\nMAGNETO_X = %d\n", pDataXYZ[0]); 00125 printf("MAGNETO_Y = %d\n", pDataXYZ[1]); 00126 printf("MAGNETO_Z = %d\n", pDataXYZ[2]); 00127 00128 BSP_GYRO_GetXYZ(pGyroDataXYZ); 00129 printf("\nGYRO_X = %.2f\n", pGyroDataXYZ[0]); 00130 printf("GYRO_Y = %.2f\n", pGyroDataXYZ[1]); 00131 printf("GYRO_Z = %.2f\n", pGyroDataXYZ[2]); 00132 00133 BSP_ACCELERO_AccGetXYZ(pDataXYZ); 00134 printf("\nACCELERO_X = %d\n", pDataXYZ[0]); 00135 printf("ACCELERO_Y = %d\n", pDataXYZ[1]); 00136 printf("ACCELERO_Z = %d\n", pDataXYZ[2]); 00137 00138 led2 = 0; 00139 #else 00140 //Always run testFram() 00141 while(1) { 00142 #endif //ESHD_RUN_SENSOR_LOOP 00143 00144 ESHD_testFram(0, ESHD_FRAM_NUM_BYTES, 1); 00145 00146 wait(1); 00147 } 00148 00149 }
Generated on Wed Jul 20 2022 12:52:35 by
1.7.2