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: max32630fthr USBDevice
main.cpp@4:1e55b4a715da, 2020-08-17 (annotated)
- Committer:
- tlyp
- Date:
- Mon Aug 17 15:10:21 2020 +0000
- Revision:
- 4:1e55b4a715da
- Parent:
- 3:27e027ab268b
- Child:
- 5:5dd9f657a9f9
Comment Updates
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tlyp | 0:d996cb30964c | 1 | /******************************************************************************* |
tlyp | 3:27e027ab268b | 2 | * Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved. |
tlyp | 0:d996cb30964c | 3 | * |
tlyp | 0:d996cb30964c | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
tlyp | 0:d996cb30964c | 5 | * copy of this software and associated documentation files (the "Software"), |
tlyp | 0:d996cb30964c | 6 | * to deal in the Software without restriction, including without limitation |
tlyp | 0:d996cb30964c | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
tlyp | 0:d996cb30964c | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
tlyp | 0:d996cb30964c | 9 | * Software is furnished to do so, subject to the following conditions: |
tlyp | 0:d996cb30964c | 10 | * |
tlyp | 0:d996cb30964c | 11 | * The above copyright notice and this permission notice shall be included |
tlyp | 0:d996cb30964c | 12 | * in all copies or substantial portions of the Software. |
tlyp | 0:d996cb30964c | 13 | * |
tlyp | 0:d996cb30964c | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
tlyp | 0:d996cb30964c | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
tlyp | 0:d996cb30964c | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
tlyp | 0:d996cb30964c | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
tlyp | 0:d996cb30964c | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
tlyp | 0:d996cb30964c | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
tlyp | 0:d996cb30964c | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
tlyp | 0:d996cb30964c | 21 | * |
tlyp | 0:d996cb30964c | 22 | * Except as contained in this notice, the name of Maxim Integrated |
tlyp | 0:d996cb30964c | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
tlyp | 0:d996cb30964c | 24 | * Products, Inc. Branding Policy. |
tlyp | 0:d996cb30964c | 25 | * |
tlyp | 0:d996cb30964c | 26 | * The mere transfer of this software does not imply any licenses |
tlyp | 0:d996cb30964c | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
tlyp | 0:d996cb30964c | 28 | * trademarks, maskwork rights, or any other form of intellectual |
tlyp | 0:d996cb30964c | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
tlyp | 0:d996cb30964c | 30 | * ownership rights. |
tlyp | 0:d996cb30964c | 31 | ******************************************************************************* |
tlyp | 3:27e027ab268b | 32 | * @file MAX30208LibTest.cpp |
tlyp | 3:27e027ab268b | 33 | * @brief This is the testing file for the MAX30208 human body temperature sensor library. It uses the default configuration found with the MAX30208 EV-Kit. |
tlyp | 3:27e027ab268b | 34 | * @version 1.0 |
tlyp | 3:27e027ab268b | 35 | * @notes This is a test program for the MAX30208 MBed Library. Both MAX30208.h and MAX30208.cpp need to be imported into the project. |
tlyp | 3:27e027ab268b | 36 | *****************************************************************************/ |
tlyp | 3:27e027ab268b | 37 | |
tlyp | 0:d996cb30964c | 38 | #include "mbed.h" |
tlyp | 0:d996cb30964c | 39 | #include "max32630fthr.h" |
tlyp | 0:d996cb30964c | 40 | #include "USBSerial.h" |
tlyp | 0:d996cb30964c | 41 | #include "MAX30208.h" |
tlyp | 0:d996cb30964c | 42 | |
tlyp | 0:d996cb30964c | 43 | MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); |
tlyp | 0:d996cb30964c | 44 | |
tlyp | 0:d996cb30964c | 45 | // Hardware serial port over DAPLink |
tlyp | 0:d996cb30964c | 46 | Serial uart(P2_1, P2_0); |
tlyp | 0:d996cb30964c | 47 | |
tlyp | 0:d996cb30964c | 48 | // Virtual serial port over USB |
tlyp | 0:d996cb30964c | 49 | USBSerial microUSB; |
tlyp | 0:d996cb30964c | 50 | DigitalOut rLED(LED1); |
tlyp | 0:d996cb30964c | 51 | DigitalOut gLED(LED2); |
tlyp | 0:d996cb30964c | 52 | DigitalOut bLED(LED3); |
tlyp | 0:d996cb30964c | 53 | |
tlyp | 0:d996cb30964c | 54 | I2C i2c(P3_4, P3_5); //sda,scl |
tlyp | 0:d996cb30964c | 55 | |
tlyp | 0:d996cb30964c | 56 | MAX30208 TempSensor(i2c, 0x50); //Constructor takes 7-bit slave adrs |
tlyp | 0:d996cb30964c | 57 | |
tlyp | 0:d996cb30964c | 58 | int main() |
tlyp | 0:d996cb30964c | 59 | { |
tlyp | 0:d996cb30964c | 60 | |
tlyp | 0:d996cb30964c | 61 | rLED = LED_ON; |
tlyp | 0:d996cb30964c | 62 | gLED = LED_ON; |
tlyp | 0:d996cb30964c | 63 | bLED = LED_OFF; |
tlyp | 0:d996cb30964c | 64 | |
tlyp | 3:27e027ab268b | 65 | //Initialize Configuration Registers |
tlyp | 0:d996cb30964c | 66 | MAX30208::Configuration_InterruptEnable InterruptEnable; |
tlyp | 0:d996cb30964c | 67 | MAX30208::Configuration_FIFOConfig2 FIFOConfig2; |
tlyp | 0:d996cb30964c | 68 | MAX30208::Configuration_GPIOSetup GPIOSetup; |
tlyp | 0:d996cb30964c | 69 | MAX30208::Configuration_GPIOControl GPIOControl; |
tlyp | 0:d996cb30964c | 70 | |
tlyp | 0:d996cb30964c | 71 | |
tlyp | 0:d996cb30964c | 72 | uint16_t val; |
tlyp | 0:d996cb30964c | 73 | |
tlyp | 1:bf1f12445c37 | 74 | |
tlyp | 0:d996cb30964c | 75 | while(1) { |
tlyp | 0:d996cb30964c | 76 | |
tlyp | 3:27e027ab268b | 77 | TempSensor.takeDataMeasurment(); //Send temperature record signal |
tlyp | 3:27e027ab268b | 78 | wait_ms(50); //Maximum temperature record time |
tlyp | 3:27e027ab268b | 79 | TempSensor.readData(val); //Read the data |
tlyp | 3:27e027ab268b | 80 | float temp = TempSensor.toCelsius(val); //Convert raw data to celsius |
tlyp | 0:d996cb30964c | 81 | microUSB.printf("Temp C = %f\r\n",temp); |
tlyp | 3:27e027ab268b | 82 | temp = TempSensor.toFahrenheit(temp); //Conver celsius to fahrenheit |
tlyp | 0:d996cb30964c | 83 | microUSB.printf("Temp F = %f\r\n",temp); |
tlyp | 0:d996cb30964c | 84 | |
tlyp | 0:d996cb30964c | 85 | |
tlyp | 0:d996cb30964c | 86 | |
tlyp | 0:d996cb30964c | 87 | //readInterruptRegister |
tlyp | 3:27e027ab268b | 88 | if (TempSensor.readInterruptRegister(InterruptEnable) == 0){ |
tlyp | 0:d996cb30964c | 89 | microUSB.printf("InterruptRegister intial config = %d\r\n", InterruptEnable.all); |
tlyp | 0:d996cb30964c | 90 | } |
tlyp | 3:27e027ab268b | 91 | |
tlyp | 3:27e027ab268b | 92 | //Set Interrupt Config Register Values |
tlyp | 0:d996cb30964c | 93 | InterruptEnable.config.TEMP_HI_EN = 1; |
tlyp | 0:d996cb30964c | 94 | InterruptEnable.config.TEMP_LO_EN = 1; |
tlyp | 3:27e027ab268b | 95 | |
tlyp | 0:d996cb30964c | 96 | if (TempSensor.writeInterruptRegister(InterruptEnable) != 0){ |
tlyp | 0:d996cb30964c | 97 | microUSB.printf("Error writing Interrupt register\r\n"); |
tlyp | 0:d996cb30964c | 98 | } |
tlyp | 3:27e027ab268b | 99 | if (TempSensor.readInterruptRegister(InterruptEnable) == 0){ |
tlyp | 3:27e027ab268b | 100 | microUSB.printf("InterruptRegister new config = %d\r\n", InterruptEnable.all); |
tlyp | 3:27e027ab268b | 101 | } |
tlyp | 3:27e027ab268b | 102 | microUSB.printf("\r\n\r\n"); |
tlyp | 0:d996cb30964c | 103 | |
tlyp | 0:d996cb30964c | 104 | //readFIFOConfig2 |
tlyp | 0:d996cb30964c | 105 | if (TempSensor.readFIFOConfig2(FIFOConfig2) == 0){ |
tlyp | 0:d996cb30964c | 106 | microUSB.printf("FIFOConfig2 initial config = %d\r\n", FIFOConfig2.all); |
tlyp | 0:d996cb30964c | 107 | } |
tlyp | 3:27e027ab268b | 108 | |
tlyp | 3:27e027ab268b | 109 | //Set FIFO Config 2 Register Values |
tlyp | 3:27e027ab268b | 110 | FIFOConfig2.config.FIFO_RO = 1; |
tlyp | 0:d996cb30964c | 111 | FIFOConfig2.config.A_FULL_TYPE = 1; |
tlyp | 0:d996cb30964c | 112 | if (TempSensor.writeFIFOConfig2(FIFOConfig2) != 0){ |
tlyp | 0:d996cb30964c | 113 | microUSB.printf("Error writing FIFO Config2 register\r\n"); |
tlyp | 0:d996cb30964c | 114 | } |
tlyp | 0:d996cb30964c | 115 | |
tlyp | 3:27e027ab268b | 116 | if (TempSensor.readFIFOConfig2(FIFOConfig2) == 0){ |
tlyp | 3:27e027ab268b | 117 | microUSB.printf("FIFOConfig2 new config = %d\r\n", FIFOConfig2.all); |
tlyp | 3:27e027ab268b | 118 | } |
tlyp | 3:27e027ab268b | 119 | |
tlyp | 3:27e027ab268b | 120 | microUSB.printf("\r\n\r\n"); |
tlyp | 3:27e027ab268b | 121 | |
tlyp | 0:d996cb30964c | 122 | //readGPIOSetup |
tlyp | 0:d996cb30964c | 123 | if (TempSensor.readGPIOSetup(GPIOSetup) == 0){ |
tlyp | 0:d996cb30964c | 124 | microUSB.printf("GPIOSetup initial config = %d\r\n", GPIOSetup.all); |
tlyp | 0:d996cb30964c | 125 | } |
tlyp | 3:27e027ab268b | 126 | |
tlyp | 3:27e027ab268b | 127 | //Set GPIO Setup Register Values |
tlyp | 0:d996cb30964c | 128 | GPIOSetup.config.GPIO0_MODE = 2; |
tlyp | 0:d996cb30964c | 129 | GPIOSetup.config.GPIO1_MODE = 3; |
tlyp | 0:d996cb30964c | 130 | if (TempSensor.writeGPIOSetup(GPIOSetup) != 0){ |
tlyp | 0:d996cb30964c | 131 | microUSB.printf("Error writing GPIO Setup register\r\n"); |
tlyp | 0:d996cb30964c | 132 | } |
tlyp | 0:d996cb30964c | 133 | |
tlyp | 3:27e027ab268b | 134 | if (TempSensor.readGPIOSetup(GPIOSetup) == 0){ |
tlyp | 3:27e027ab268b | 135 | microUSB.printf("GPIOSetup new config = %d\r\n", GPIOSetup.all); |
tlyp | 3:27e027ab268b | 136 | } |
tlyp | 3:27e027ab268b | 137 | |
tlyp | 3:27e027ab268b | 138 | microUSB.printf("\r\n\r\n"); |
tlyp | 3:27e027ab268b | 139 | |
tlyp | 0:d996cb30964c | 140 | //readGPIOControl |
tlyp | 0:d996cb30964c | 141 | if (TempSensor.readGPIOControl(GPIOControl) == 0){ |
tlyp | 0:d996cb30964c | 142 | microUSB.printf("GPIOControl initial config = %d\r\n", GPIOControl.all); |
tlyp | 0:d996cb30964c | 143 | } |
tlyp | 3:27e027ab268b | 144 | |
tlyp | 3:27e027ab268b | 145 | //Set GPIO Control Register Values |
tlyp | 0:d996cb30964c | 146 | GPIOControl.config.GPIO0_LL = 1; |
tlyp | 0:d996cb30964c | 147 | GPIOControl.config.GPIO1_LL = 1; |
tlyp | 0:d996cb30964c | 148 | if (TempSensor.writeGPIOControl(GPIOControl) != 0){ |
tlyp | 0:d996cb30964c | 149 | microUSB.printf("Error writing register\r\n"); |
tlyp | 0:d996cb30964c | 150 | } |
tlyp | 3:27e027ab268b | 151 | if (TempSensor.readGPIOControl(GPIOControl) == 0){ |
tlyp | 3:27e027ab268b | 152 | microUSB.printf("GPIOControl new config = %d\r\n", GPIOControl.all); |
tlyp | 0:d996cb30964c | 153 | } |
tlyp | 0:d996cb30964c | 154 | |
tlyp | 3:27e027ab268b | 155 | TempSensor.resetDevice(); //Reset Device Registers |
tlyp | 0:d996cb30964c | 156 | |
tlyp | 0:d996cb30964c | 157 | |
tlyp | 0:d996cb30964c | 158 | microUSB.printf("\r\n\r\n"); |
tlyp | 0:d996cb30964c | 159 | uint16_t PointerValue; |
tlyp | 0:d996cb30964c | 160 | |
tlyp | 3:27e027ab268b | 161 | //Write Data Pointer Test (Read Only) |
tlyp | 0:d996cb30964c | 162 | TempSensor.readWritePointer(PointerValue); |
tlyp | 0:d996cb30964c | 163 | microUSB.printf("Current Write Pointer Value: %d\r\n",PointerValue); |
tlyp | 0:d996cb30964c | 164 | microUSB.printf("New Value Measured\r\n"); |
tlyp | 0:d996cb30964c | 165 | TempSensor.takeDataMeasurment(); |
tlyp | 0:d996cb30964c | 166 | wait_ms(50); |
tlyp | 0:d996cb30964c | 167 | TempSensor.readWritePointer(PointerValue); |
tlyp | 0:d996cb30964c | 168 | microUSB.printf("Current Write Pointer Value: %d\r\n",PointerValue); |
tlyp | 0:d996cb30964c | 169 | |
tlyp | 0:d996cb30964c | 170 | microUSB.printf("\r\n\r\n"); |
tlyp | 0:d996cb30964c | 171 | |
tlyp | 3:27e027ab268b | 172 | //Read Data Pointer Test (Read and Write) |
tlyp | 0:d996cb30964c | 173 | TempSensor.readReadPointer(PointerValue); |
tlyp | 0:d996cb30964c | 174 | microUSB.printf("Current Read Pointer Value: %d\r\n",PointerValue); |
tlyp | 0:d996cb30964c | 175 | TempSensor.readData(val); |
tlyp | 0:d996cb30964c | 176 | microUSB.printf("New Value Read\r\n"); |
tlyp | 0:d996cb30964c | 177 | TempSensor.readReadPointer(PointerValue); |
tlyp | 0:d996cb30964c | 178 | microUSB.printf("Current Read Pointer Value: %d\r\n",PointerValue); |
tlyp | 0:d996cb30964c | 179 | microUSB.printf("Read Pointer Written to '15'\r\n"); |
tlyp | 0:d996cb30964c | 180 | TempSensor.writeReadPointer(0x0F); |
tlyp | 0:d996cb30964c | 181 | TempSensor.readReadPointer(PointerValue); |
tlyp | 0:d996cb30964c | 182 | microUSB.printf("Current Read Pointer Value: %d\r\n",PointerValue); |
tlyp | 0:d996cb30964c | 183 | |
tlyp | 0:d996cb30964c | 184 | microUSB.printf("\r\n\r\n"); |
tlyp | 0:d996cb30964c | 185 | |
tlyp | 3:27e027ab268b | 186 | |
tlyp | 3:27e027ab268b | 187 | TempSensor.resetDevice(); //Reset Device Registers |
tlyp | 3:27e027ab268b | 188 | |
tlyp | 0:d996cb30964c | 189 | uint16_t Counter; |
tlyp | 0:d996cb30964c | 190 | |
tlyp | 0:d996cb30964c | 191 | //Data Counter |
tlyp | 0:d996cb30964c | 192 | TempSensor.readDataCounter(Counter); |
tlyp | 0:d996cb30964c | 193 | microUSB.printf("Initial Data Read: %d\r\n",Counter); |
tlyp | 0:d996cb30964c | 194 | microUSB.printf("Reading 16 temperatures\r\n"); |
tlyp | 0:d996cb30964c | 195 | for(int i=0;i<16;i++){ |
tlyp | 0:d996cb30964c | 196 | TempSensor.takeDataMeasurment(); |
tlyp | 0:d996cb30964c | 197 | wait_ms(50); |
tlyp | 0:d996cb30964c | 198 | } |
tlyp | 3:27e027ab268b | 199 | |
tlyp | 3:27e027ab268b | 200 | //Read Number of Data Points Collected |
tlyp | 0:d996cb30964c | 201 | TempSensor.readDataCounter(Counter); |
tlyp | 0:d996cb30964c | 202 | microUSB.printf("Curent Data Read: %d\r\n",Counter); |
tlyp | 3:27e027ab268b | 203 | microUSB.printf("\r\n\r\n"); |
tlyp | 0:d996cb30964c | 204 | |
tlyp | 0:d996cb30964c | 205 | //Data Overflow |
tlyp | 0:d996cb30964c | 206 | microUSB.printf("Reading 30 temperatures\r\n"); |
tlyp | 3:27e027ab268b | 207 | |
tlyp | 3:27e027ab268b | 208 | //Overflow data registers |
tlyp | 0:d996cb30964c | 209 | for (int i =0;i<30;i++){ |
tlyp | 0:d996cb30964c | 210 | TempSensor.takeDataMeasurment(); |
tlyp | 0:d996cb30964c | 211 | wait_ms(50); |
tlyp | 0:d996cb30964c | 212 | } |
tlyp | 3:27e027ab268b | 213 | |
tlyp | 3:27e027ab268b | 214 | //Read Overflow Register |
tlyp | 0:d996cb30964c | 215 | TempSensor.readOverflow(Counter); |
tlyp | 0:d996cb30964c | 216 | microUSB.printf("Overflow Counter: %d\r\n",Counter); |
tlyp | 0:d996cb30964c | 217 | |
tlyp | 0:d996cb30964c | 218 | microUSB.printf("\r\n\r\n"); |
tlyp | 0:d996cb30964c | 219 | uint16_t config; |
tlyp | 3:27e027ab268b | 220 | |
tlyp | 3:27e027ab268b | 221 | TempSensor.resetDevice(); //Reset Device Registers |
tlyp | 3:27e027ab268b | 222 | |
tlyp | 3:27e027ab268b | 223 | |
tlyp | 0:d996cb30964c | 224 | //Config1 |
tlyp | 0:d996cb30964c | 225 | TempSensor.readFIFOConfig1(config); |
tlyp | 0:d996cb30964c | 226 | microUSB.printf("FIFO Config init Value: %d\r\n",config); |
tlyp | 0:d996cb30964c | 227 | microUSB.printf("Writing '3' to FIFO Config 1\r\n"); |
tlyp | 0:d996cb30964c | 228 | TempSensor.writeFIFOConfig1(0x03); |
tlyp | 0:d996cb30964c | 229 | TempSensor.readFIFOConfig1(config); |
tlyp | 0:d996cb30964c | 230 | microUSB.printf("FIFO Config Value: %d\r\n",config); |
tlyp | 0:d996cb30964c | 231 | |
tlyp | 0:d996cb30964c | 232 | microUSB.printf("\r\n\r\n"); |
tlyp | 3:27e027ab268b | 233 | TempSensor.resetDevice(); //Reset Device Registers |
tlyp | 3:27e027ab268b | 234 | |
tlyp | 3:27e027ab268b | 235 | //Read Alarm Register |
tlyp | 0:d996cb30964c | 236 | uint16_t HI; |
tlyp | 0:d996cb30964c | 237 | uint16_t LO; |
tlyp | 0:d996cb30964c | 238 | TempSensor.readAlarmHigh(HI); |
tlyp | 0:d996cb30964c | 239 | TempSensor.readAlarmLow(LO); |
tlyp | 0:d996cb30964c | 240 | |
tlyp | 0:d996cb30964c | 241 | microUSB.printf("Inital Alarm High: %d\r\n",HI); |
tlyp | 0:d996cb30964c | 242 | microUSB.printf("Inital Alarm Low: %d\r\n",LO); |
tlyp | 0:d996cb30964c | 243 | microUSB.printf("Setting High to '4321'\r\n"); |
tlyp | 0:d996cb30964c | 244 | microUSB.printf("Setting High to '1234'\r\n"); |
tlyp | 3:27e027ab268b | 245 | |
tlyp | 3:27e027ab268b | 246 | //Write Alarm Registers |
tlyp | 0:d996cb30964c | 247 | TempSensor.writeAlarmHigh(0x10E1); |
tlyp | 0:d996cb30964c | 248 | TempSensor.writeAlarmLow(0x04D2); |
tlyp | 3:27e027ab268b | 249 | |
tlyp | 3:27e027ab268b | 250 | //Read Alarm Registers |
tlyp | 0:d996cb30964c | 251 | TempSensor.readAlarmHigh(HI); |
tlyp | 0:d996cb30964c | 252 | TempSensor.readAlarmLow(LO); |
tlyp | 0:d996cb30964c | 253 | |
tlyp | 0:d996cb30964c | 254 | microUSB.printf("Alarm High: %d\r\n",HI); |
tlyp | 0:d996cb30964c | 255 | microUSB.printf("Alarm Low: %d\r\n",LO); |
tlyp | 0:d996cb30964c | 256 | |
tlyp | 0:d996cb30964c | 257 | microUSB.printf("\r\n\r\n\r\n\r\n"); |
tlyp | 3:27e027ab268b | 258 | TempSensor.resetDevice(); //Reset Device Registers |
tlyp | 0:d996cb30964c | 259 | wait(5); |
tlyp | 0:d996cb30964c | 260 | } |
tlyp | 0:d996cb30964c | 261 | } |
tlyp | 0:d996cb30964c | 262 |