Maxim Integrated / Mbed OS MAX30208_Demo

Dependencies:   max32630fthr USBDevice

Committer:
tlyp
Date:
Mon Aug 10 13:03:59 2020 +0000
Revision:
1:bf1f12445c37
Parent:
0:d996cb30964c
Child:
2:836c3793cd68
Initial Commit for MAX30208 EV-Kit Library and Testing Script

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tlyp 0:d996cb30964c 1 /*******************************************************************************
tlyp 0:d996cb30964c 2 * Copyright (C) 2018 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 0:d996cb30964c 32 */
tlyp 0:d996cb30964c 33 #include "mbed.h"
tlyp 0:d996cb30964c 34 #include "max32630fthr.h"
tlyp 0:d996cb30964c 35 #include "USBSerial.h"
tlyp 0:d996cb30964c 36 #include "MAX30208.h"
tlyp 0:d996cb30964c 37
tlyp 0:d996cb30964c 38 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
tlyp 0:d996cb30964c 39
tlyp 0:d996cb30964c 40 // Hardware serial port over DAPLink
tlyp 0:d996cb30964c 41 Serial uart(P2_1, P2_0);
tlyp 0:d996cb30964c 42
tlyp 0:d996cb30964c 43 // Virtual serial port over USB
tlyp 0:d996cb30964c 44 USBSerial microUSB;
tlyp 0:d996cb30964c 45 DigitalOut rLED(LED1);
tlyp 0:d996cb30964c 46 DigitalOut gLED(LED2);
tlyp 0:d996cb30964c 47 DigitalOut bLED(LED3);
tlyp 0:d996cb30964c 48
tlyp 0:d996cb30964c 49 I2C i2c(P3_4, P3_5); //sda,scl
tlyp 0:d996cb30964c 50
tlyp 0:d996cb30964c 51 MAX30208 TempSensor(i2c, 0x50); //Constructor takes 7-bit slave adrs
tlyp 0:d996cb30964c 52
tlyp 1:bf1f12445c37 53 void testInt(){
tlyp 1:bf1f12445c37 54 microUSB.printf("Triggered\r\n");
tlyp 1:bf1f12445c37 55 }
tlyp 1:bf1f12445c37 56
tlyp 0:d996cb30964c 57 int main()
tlyp 0:d996cb30964c 58 {
tlyp 0:d996cb30964c 59
tlyp 0:d996cb30964c 60 microUSB.printf("micro USB serial port\r\n");
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 0:d996cb30964c 65 rLED = LED_OFF;
tlyp 0:d996cb30964c 66
tlyp 0:d996cb30964c 67 MAX30208::Configuration_InterruptEnable InterruptEnable;
tlyp 0:d996cb30964c 68 MAX30208::Configuration_FIFOConfig2 FIFOConfig2;
tlyp 0:d996cb30964c 69 MAX30208::Configuration_GPIOSetup GPIOSetup;
tlyp 0:d996cb30964c 70 MAX30208::Configuration_GPIOControl GPIOControl;
tlyp 0:d996cb30964c 71
tlyp 0:d996cb30964c 72
tlyp 0:d996cb30964c 73 uint16_t val;
tlyp 0:d996cb30964c 74
tlyp 1:bf1f12445c37 75
tlyp 0:d996cb30964c 76 while(1) {
tlyp 0:d996cb30964c 77
tlyp 0:d996cb30964c 78 TempSensor.takeDataMeasurment();
tlyp 0:d996cb30964c 79 wait_ms(50);
tlyp 0:d996cb30964c 80 microUSB.printf("Before = %d\r\n",val);
tlyp 0:d996cb30964c 81 TempSensor.readData(val);
tlyp 0:d996cb30964c 82 microUSB.printf("After = %d\r\n",val);
tlyp 0:d996cb30964c 83 float temp = TempSensor.toCelsius(val);
tlyp 0:d996cb30964c 84 microUSB.printf("Temp C = %f\r\n",temp);
tlyp 0:d996cb30964c 85 temp = TempSensor.toFahrenheit(temp);
tlyp 0:d996cb30964c 86 microUSB.printf("Temp F = %f\r\n",temp);
tlyp 0:d996cb30964c 87
tlyp 0:d996cb30964c 88
tlyp 0:d996cb30964c 89
tlyp 0:d996cb30964c 90 //readInterruptRegister
tlyp 0:d996cb30964c 91 if (TempSensor.readInterruptRegister(InterruptEnable) == 0){
tlyp 0:d996cb30964c 92 microUSB.printf("InterruptRegister intial config = %d\r\n", InterruptEnable.all);
tlyp 0:d996cb30964c 93 }
tlyp 0:d996cb30964c 94 InterruptEnable.config.TEMP_HI_EN = 1;
tlyp 0:d996cb30964c 95 InterruptEnable.config.TEMP_LO_EN = 1;
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 0:d996cb30964c 99
tlyp 0:d996cb30964c 100 //readFIFOConfig2
tlyp 0:d996cb30964c 101 if (TempSensor.readFIFOConfig2(FIFOConfig2) == 0){
tlyp 0:d996cb30964c 102 microUSB.printf("FIFOConfig2 initial config = %d\r\n", FIFOConfig2.all);
tlyp 0:d996cb30964c 103 }
tlyp 0:d996cb30964c 104 FIFOConfig2.config.FIFO_RO = 1;
tlyp 0:d996cb30964c 105 FIFOConfig2.config.A_FULL_TYPE = 1;
tlyp 0:d996cb30964c 106 if (TempSensor.writeFIFOConfig2(FIFOConfig2) != 0){
tlyp 0:d996cb30964c 107 microUSB.printf("Error writing FIFO Config2 register\r\n");
tlyp 0:d996cb30964c 108 }
tlyp 0:d996cb30964c 109
tlyp 0:d996cb30964c 110 //readGPIOSetup
tlyp 0:d996cb30964c 111 if (TempSensor.readGPIOSetup(GPIOSetup) == 0){
tlyp 0:d996cb30964c 112 microUSB.printf("GPIOSetup initial config = %d\r\n", GPIOSetup.all);
tlyp 0:d996cb30964c 113 }
tlyp 0:d996cb30964c 114 GPIOSetup.config.GPIO0_MODE = 2;
tlyp 0:d996cb30964c 115 GPIOSetup.config.GPIO1_MODE = 3;
tlyp 0:d996cb30964c 116 if (TempSensor.writeGPIOSetup(GPIOSetup) != 0){
tlyp 0:d996cb30964c 117 microUSB.printf("Error writing GPIO Setup register\r\n");
tlyp 0:d996cb30964c 118 }
tlyp 0:d996cb30964c 119
tlyp 0:d996cb30964c 120 //readGPIOControl
tlyp 0:d996cb30964c 121 if (TempSensor.readGPIOControl(GPIOControl) == 0){
tlyp 0:d996cb30964c 122 microUSB.printf("GPIOControl initial config = %d\r\n", GPIOControl.all);
tlyp 0:d996cb30964c 123 }
tlyp 0:d996cb30964c 124 GPIOControl.config.GPIO0_LL = 1;
tlyp 0:d996cb30964c 125 GPIOControl.config.GPIO1_LL = 1;
tlyp 0:d996cb30964c 126 if (TempSensor.writeGPIOControl(GPIOControl) != 0){
tlyp 0:d996cb30964c 127 microUSB.printf("Error writing register\r\n");
tlyp 0:d996cb30964c 128 }
tlyp 0:d996cb30964c 129
tlyp 0:d996cb30964c 130 //writeInterruptRegister
tlyp 0:d996cb30964c 131 if (TempSensor.readInterruptRegister(InterruptEnable) == 0){
tlyp 0:d996cb30964c 132 microUSB.printf("Interrupt Register new config = %d\r\n", InterruptEnable.all);
tlyp 0:d996cb30964c 133 }
tlyp 0:d996cb30964c 134 InterruptEnable.config.TEMP_HI_EN = 0;
tlyp 0:d996cb30964c 135 InterruptEnable.config.TEMP_LO_EN = 0;
tlyp 0:d996cb30964c 136 if (TempSensor.writeInterruptRegister(InterruptEnable) != 0){
tlyp 0:d996cb30964c 137 microUSB.printf("Error writing Interrupt Registerregister\r\n");
tlyp 0:d996cb30964c 138 }
tlyp 0:d996cb30964c 139
tlyp 0:d996cb30964c 140 //writeFIFOConfig2
tlyp 0:d996cb30964c 141 if (TempSensor.readFIFOConfig2(FIFOConfig2) == 0){
tlyp 0:d996cb30964c 142 microUSB.printf("FIFOConfig2 new config = %d\r\n", FIFOConfig2.all);
tlyp 0:d996cb30964c 143 }
tlyp 0:d996cb30964c 144 FIFOConfig2.config.FIFO_RO = 0;
tlyp 0:d996cb30964c 145 FIFOConfig2.config.A_FULL_TYPE = 0;
tlyp 0:d996cb30964c 146 if (TempSensor.writeFIFOConfig2(FIFOConfig2) != 0){
tlyp 0:d996cb30964c 147 microUSB.printf("Error writing register\r\n");
tlyp 0:d996cb30964c 148 }
tlyp 0:d996cb30964c 149
tlyp 0:d996cb30964c 150 //writeGPIOSetup
tlyp 0:d996cb30964c 151 if (TempSensor.readGPIOSetup(GPIOSetup) == 0){
tlyp 0:d996cb30964c 152 microUSB.printf("GPIOSetup new config = %d\r\n", GPIOSetup.all);
tlyp 0:d996cb30964c 153 }
tlyp 0:d996cb30964c 154 GPIOSetup.config.GPIO0_MODE = 0;
tlyp 0:d996cb30964c 155 GPIOSetup.config.GPIO1_MODE = 0;
tlyp 0:d996cb30964c 156 if (TempSensor.writeGPIOSetup(GPIOSetup) != 0){
tlyp 0:d996cb30964c 157 microUSB.printf("Error writing register\r\n");
tlyp 0:d996cb30964c 158 }
tlyp 1:bf1f12445c37 159
tlyp 0:d996cb30964c 160 TempSensor.resetDevice();
tlyp 0:d996cb30964c 161
tlyp 0:d996cb30964c 162
tlyp 0:d996cb30964c 163 microUSB.printf("\r\n\r\n");
tlyp 0:d996cb30964c 164 uint16_t PointerValue;
tlyp 0:d996cb30964c 165
tlyp 0:d996cb30964c 166 //Write Pointer Test
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 microUSB.printf("New Value Measured\r\n");
tlyp 0:d996cb30964c 170 TempSensor.takeDataMeasurment();
tlyp 0:d996cb30964c 171 wait_ms(50);
tlyp 0:d996cb30964c 172 TempSensor.readWritePointer(PointerValue);
tlyp 0:d996cb30964c 173 microUSB.printf("Current Write Pointer Value: %d\r\n",PointerValue);
tlyp 0:d996cb30964c 174
tlyp 0:d996cb30964c 175 microUSB.printf("\r\n\r\n");
tlyp 0:d996cb30964c 176
tlyp 0:d996cb30964c 177 //Read Pointer Test
tlyp 0:d996cb30964c 178 TempSensor.readReadPointer(PointerValue);
tlyp 0:d996cb30964c 179 microUSB.printf("Current Read Pointer Value: %d\r\n",PointerValue);
tlyp 0:d996cb30964c 180 TempSensor.readData(val);
tlyp 0:d996cb30964c 181 microUSB.printf("New Value Read\r\n");
tlyp 0:d996cb30964c 182 TempSensor.readReadPointer(PointerValue);
tlyp 0:d996cb30964c 183 microUSB.printf("Current Read Pointer Value: %d\r\n",PointerValue);
tlyp 0:d996cb30964c 184 microUSB.printf("Read Pointer Written to '15'\r\n");
tlyp 0:d996cb30964c 185 TempSensor.writeReadPointer(0x0F);
tlyp 0:d996cb30964c 186 TempSensor.readReadPointer(PointerValue);
tlyp 0:d996cb30964c 187 microUSB.printf("Current Read Pointer Value: %d\r\n",PointerValue);
tlyp 0:d996cb30964c 188
tlyp 0:d996cb30964c 189 microUSB.printf("\r\n\r\n");
tlyp 0:d996cb30964c 190
tlyp 0:d996cb30964c 191 uint16_t Counter;
tlyp 0:d996cb30964c 192 TempSensor.resetDevice();
tlyp 0:d996cb30964c 193
tlyp 0:d996cb30964c 194 //Data Counter
tlyp 0:d996cb30964c 195 TempSensor.readDataCounter(Counter);
tlyp 0:d996cb30964c 196 microUSB.printf("Initial Data Read: %d\r\n",Counter);
tlyp 0:d996cb30964c 197 microUSB.printf("Reading 16 temperatures\r\n");
tlyp 0:d996cb30964c 198 for(int i=0;i<16;i++){
tlyp 0:d996cb30964c 199 TempSensor.takeDataMeasurment();
tlyp 0:d996cb30964c 200 wait_ms(50);
tlyp 0:d996cb30964c 201 }
tlyp 0:d996cb30964c 202 TempSensor.readDataCounter(Counter);
tlyp 0:d996cb30964c 203 microUSB.printf("Curent Data Read: %d\r\n",Counter);
tlyp 0:d996cb30964c 204
tlyp 0:d996cb30964c 205 microUSB.printf("\r\n\r\n");
tlyp 0:d996cb30964c 206 //Data Overflow
tlyp 0:d996cb30964c 207 microUSB.printf("Reading 30 temperatures\r\n");
tlyp 0:d996cb30964c 208 for (int i =0;i<30;i++){
tlyp 0:d996cb30964c 209 TempSensor.takeDataMeasurment();
tlyp 0:d996cb30964c 210 wait_ms(50);
tlyp 0:d996cb30964c 211 }
tlyp 0:d996cb30964c 212 TempSensor.readOverflow(Counter);
tlyp 0:d996cb30964c 213 microUSB.printf("Overflow Counter: %d\r\n",Counter);
tlyp 0:d996cb30964c 214
tlyp 0:d996cb30964c 215 microUSB.printf("\r\n\r\n");
tlyp 0:d996cb30964c 216 uint16_t config;
tlyp 0:d996cb30964c 217 TempSensor.resetDevice();
tlyp 0:d996cb30964c 218 //Config1
tlyp 0:d996cb30964c 219 TempSensor.readFIFOConfig1(config);
tlyp 0:d996cb30964c 220 microUSB.printf("FIFO Config init Value: %d\r\n",config);
tlyp 0:d996cb30964c 221 microUSB.printf("Writing '3' to FIFO Config 1\r\n");
tlyp 0:d996cb30964c 222 TempSensor.writeFIFOConfig1(0x03);
tlyp 0:d996cb30964c 223 TempSensor.readFIFOConfig1(config);
tlyp 0:d996cb30964c 224 microUSB.printf("FIFO Config Value: %d\r\n",config);
tlyp 0:d996cb30964c 225
tlyp 0:d996cb30964c 226 microUSB.printf("\r\n\r\n");
tlyp 0:d996cb30964c 227 TempSensor.resetDevice();
tlyp 0:d996cb30964c 228 //read/write alarm
tlyp 0:d996cb30964c 229 uint16_t HI;
tlyp 0:d996cb30964c 230 uint16_t LO;
tlyp 0:d996cb30964c 231 TempSensor.readAlarmHigh(HI);
tlyp 0:d996cb30964c 232 TempSensor.readAlarmLow(LO);
tlyp 0:d996cb30964c 233
tlyp 0:d996cb30964c 234 microUSB.printf("Inital Alarm High: %d\r\n",HI);
tlyp 0:d996cb30964c 235 microUSB.printf("Inital Alarm Low: %d\r\n",LO);
tlyp 0:d996cb30964c 236 microUSB.printf("Setting High to '4321'\r\n");
tlyp 0:d996cb30964c 237 microUSB.printf("Setting High to '1234'\r\n");
tlyp 0:d996cb30964c 238 TempSensor.writeAlarmHigh(0x10E1);
tlyp 0:d996cb30964c 239 TempSensor.writeAlarmLow(0x04D2);
tlyp 0:d996cb30964c 240 TempSensor.readAlarmHigh(HI);
tlyp 0:d996cb30964c 241 TempSensor.readAlarmLow(LO);
tlyp 0:d996cb30964c 242
tlyp 0:d996cb30964c 243 microUSB.printf("Alarm High: %d\r\n",HI);
tlyp 0:d996cb30964c 244 microUSB.printf("Alarm Low: %d\r\n",LO);
tlyp 0:d996cb30964c 245
tlyp 0:d996cb30964c 246 microUSB.printf("\r\n\r\n\r\n\r\n");
tlyp 0:d996cb30964c 247 TempSensor.resetDevice();
tlyp 0:d996cb30964c 248 wait(5);
tlyp 0:d996cb30964c 249 }
tlyp 0:d996cb30964c 250 }
tlyp 0:d996cb30964c 251