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@2:4436529c3560, 2019-08-30 (annotated)
- Committer:
- stillChris
- Date:
- Fri Aug 30 03:34:01 2019 +0000
- Revision:
- 2:4436529c3560
- Parent:
- 1:f6f0b501542a
- Child:
- 3:c8b1679fa467
Fix runtime coding errors
Who changed what in which revision?
| User | Revision | Line number | New 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 | 1:f6f0b501542a | 20 | MB85RSxx_SPI hFram(PA_7, PA_6, PA_5, PA_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 | 1:f6f0b501542a | 24 | MB85RSxx_SPI hFram(PD_4, PD_3, PD_1, PD_5); |
| 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 | 1:f6f0b501542a | 28 | MB85RSxx_SPI hFram(PC_12, PC_11, PC_10, PC_9); |
| 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 | 2:4436529c3560 | 43 | return 1; |
| stillChris | 0:f19cfceb5f7b | 44 | printf("\nFRAM Fill Memory\n"); |
| stillChris | 0:f19cfceb5f7b | 45 | |
| stillChris | 0:f19cfceb5f7b | 46 | for(testAddr=0; testAddr<addrRange; testAddr++) |
| stillChris | 0:f19cfceb5f7b | 47 | { |
| stillChris | 0:f19cfceb5f7b | 48 | testData = 0;//ESHD_FRAM_TEST_DATA; |
| stillChris | 0:f19cfceb5f7b | 49 | //fill byte by byte |
| stillChris | 0:f19cfceb5f7b | 50 | hFram.write(testAddr, (char)testData); |
| stillChris | 0:f19cfceb5f7b | 51 | |
| stillChris | 0:f19cfceb5f7b | 52 | if(testAddr&0xff)//Each 256 bytes |
| stillChris | 0:f19cfceb5f7b | 53 | { |
| stillChris | 0:f19cfceb5f7b | 54 | printf("."); //Print "." to the UART each 512 bytes |
| stillChris | 0:f19cfceb5f7b | 55 | led2=led2?0:1; //Toggle LED2 |
| stillChris | 0:f19cfceb5f7b | 56 | } |
| stillChris | 0:f19cfceb5f7b | 57 | } |
| stillChris | 0:f19cfceb5f7b | 58 | for(testAddr=0; testAddr<addrRange; testAddr++) |
| stillChris | 0:f19cfceb5f7b | 59 | { |
| stillChris | 0:f19cfceb5f7b | 60 | testData = hFram.read(testAddr); |
| stillChris | 0:f19cfceb5f7b | 61 | if(testAddr&0xff)//Each 256 bytes |
| stillChris | 0:f19cfceb5f7b | 62 | { |
| stillChris | 0:f19cfceb5f7b | 63 | printf("."); //Print "." to the UART |
| stillChris | 0:f19cfceb5f7b | 64 | led2=led2?0:1; //Toggle LED2 |
| stillChris | 0:f19cfceb5f7b | 65 | } |
| stillChris | 2:4436529c3560 | 66 | if(testData != ESHD_FRAM_TEST_DATA) |
| stillChris | 0:f19cfceb5f7b | 67 | { |
| stillChris | 2:4436529c3560 | 68 | |
| stillChris | 2:4436529c3560 | 69 | printf("\nFRAM test failure - memory = 0x%04x, expected value = 0x%02x, data read = 0x%02x\n\n", |
| stillChris | 2:4436529c3560 | 70 | testAddr, ESHD_FRAM_TEST_DATA, testData); |
| stillChris | 0:f19cfceb5f7b | 71 | rtnVal = -1; |
| stillChris | 0:f19cfceb5f7b | 72 | } |
| stillChris | 0:f19cfceb5f7b | 73 | } |
| stillChris | 0:f19cfceb5f7b | 74 | |
| stillChris | 0:f19cfceb5f7b | 75 | printf("FRAM Test Complete\n"); |
| stillChris | 0:f19cfceb5f7b | 76 | |
| stillChris | 0:f19cfceb5f7b | 77 | return (rtnVal); |
| stillChris | 0:f19cfceb5f7b | 78 | } |
| stillChris | 0:f19cfceb5f7b | 79 | |
| stillChris | 0:f19cfceb5f7b | 80 | |
| stillChris | 0:f19cfceb5f7b | 81 | int main() |
| stillChris | 0:f19cfceb5f7b | 82 | { |
| stillChris | 0:f19cfceb5f7b | 83 | float sensor_value = 0; |
| stillChris | 0:f19cfceb5f7b | 84 | int16_t pDataXYZ[3] = {0}; |
| stillChris | 0:f19cfceb5f7b | 85 | float pGyroDataXYZ[3] = {0}; |
| stillChris | 0:f19cfceb5f7b | 86 | |
| stillChris | 0:f19cfceb5f7b | 87 | BSP_TSENSOR_Init(); |
| stillChris | 0:f19cfceb5f7b | 88 | BSP_HSENSOR_Init(); |
| stillChris | 0:f19cfceb5f7b | 89 | BSP_PSENSOR_Init(); |
| stillChris | 0:f19cfceb5f7b | 90 | |
| stillChris | 0:f19cfceb5f7b | 91 | BSP_MAGNETO_Init(); |
| stillChris | 0:f19cfceb5f7b | 92 | BSP_GYRO_Init(); |
| stillChris | 0:f19cfceb5f7b | 93 | BSP_ACCELERO_Init(); |
| stillChris | 0:f19cfceb5f7b | 94 | |
| stillChris | 2:4436529c3560 | 95 | printf("ESHD Main Menu\n"); |
| stillChris | 0:f19cfceb5f7b | 96 | while(1) { |
| stillChris | 0:f19cfceb5f7b | 97 | |
| stillChris | 0:f19cfceb5f7b | 98 | led1 = 1; |
| stillChris | 0:f19cfceb5f7b | 99 | |
| stillChris | 0:f19cfceb5f7b | 100 | sensor_value = BSP_TSENSOR_ReadTemp(); |
| stillChris | 0:f19cfceb5f7b | 101 | printf("\nTEMPERATURE = %.2f degC\n", sensor_value); |
| stillChris | 0:f19cfceb5f7b | 102 | |
| stillChris | 0:f19cfceb5f7b | 103 | sensor_value = BSP_HSENSOR_ReadHumidity(); |
| stillChris | 0:f19cfceb5f7b | 104 | printf("HUMIDITY = %.2f %%\n", sensor_value); |
| stillChris | 0:f19cfceb5f7b | 105 | |
| stillChris | 0:f19cfceb5f7b | 106 | sensor_value = BSP_PSENSOR_ReadPressure(); |
| stillChris | 0:f19cfceb5f7b | 107 | printf("PRESSURE is = %.2f mBar\n", sensor_value); |
| stillChris | 0:f19cfceb5f7b | 108 | |
| stillChris | 0:f19cfceb5f7b | 109 | led1 = 0; |
| stillChris | 0:f19cfceb5f7b | 110 | |
| stillChris | 0:f19cfceb5f7b | 111 | wait(1); |
| stillChris | 0:f19cfceb5f7b | 112 | |
| stillChris | 0:f19cfceb5f7b | 113 | led1 = 1; |
| stillChris | 0:f19cfceb5f7b | 114 | |
| stillChris | 0:f19cfceb5f7b | 115 | BSP_MAGNETO_GetXYZ(pDataXYZ); |
| stillChris | 0:f19cfceb5f7b | 116 | printf("\nMAGNETO_X = %d\n", pDataXYZ[0]); |
| stillChris | 0:f19cfceb5f7b | 117 | printf("MAGNETO_Y = %d\n", pDataXYZ[1]); |
| stillChris | 0:f19cfceb5f7b | 118 | printf("MAGNETO_Z = %d\n", pDataXYZ[2]); |
| stillChris | 0:f19cfceb5f7b | 119 | |
| stillChris | 0:f19cfceb5f7b | 120 | BSP_GYRO_GetXYZ(pGyroDataXYZ); |
| stillChris | 0:f19cfceb5f7b | 121 | printf("\nGYRO_X = %.2f\n", pGyroDataXYZ[0]); |
| stillChris | 0:f19cfceb5f7b | 122 | printf("GYRO_Y = %.2f\n", pGyroDataXYZ[1]); |
| stillChris | 0:f19cfceb5f7b | 123 | printf("GYRO_Z = %.2f\n", pGyroDataXYZ[2]); |
| stillChris | 0:f19cfceb5f7b | 124 | |
| stillChris | 0:f19cfceb5f7b | 125 | BSP_ACCELERO_AccGetXYZ(pDataXYZ); |
| stillChris | 0:f19cfceb5f7b | 126 | printf("\nACCELERO_X = %d\n", pDataXYZ[0]); |
| stillChris | 0:f19cfceb5f7b | 127 | printf("ACCELERO_Y = %d\n", pDataXYZ[1]); |
| stillChris | 0:f19cfceb5f7b | 128 | printf("ACCELERO_Z = %d\n", pDataXYZ[2]); |
| stillChris | 0:f19cfceb5f7b | 129 | |
| stillChris | 0:f19cfceb5f7b | 130 | led1 = 0; |
| stillChris | 0:f19cfceb5f7b | 131 | |
| stillChris | 2:4436529c3560 | 132 | ESHD_testFram(0, ESHD_FRAM_NUM_BYTES/64, 1); |
| stillChris | 0:f19cfceb5f7b | 133 | |
| stillChris | 0:f19cfceb5f7b | 134 | wait(1); |
| stillChris | 0:f19cfceb5f7b | 135 | } |
| stillChris | 0:f19cfceb5f7b | 136 | } |