Maxim Integrated / Mbed OS MAX30208_Demo

Dependencies:   max32630fthr USBDevice

Revision:
0:d996cb30964c
Child:
1:bf1f12445c37
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jul 15 15:06:32 2020 +0000
@@ -0,0 +1,258 @@
+/*******************************************************************************
+* Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included
+* in all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
+* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+* OTHER DEALINGS IN THE SOFTWARE.
+*
+* Except as contained in this notice, the name of Maxim Integrated
+* Products, Inc. shall not be used except as stated in the Maxim Integrated
+* Products, Inc. Branding Policy.
+*
+* The mere transfer of this software does not imply any licenses
+* of trade secrets, proprietary technology, copyrights, patents,
+* trademarks, maskwork rights, or any other form of intellectual
+* property whatsoever. Maxim Integrated Products, Inc. retains all
+* ownership rights.
+*******************************************************************************
+*/
+#include "mbed.h"
+#include "max32630fthr.h"
+#include "USBSerial.h"
+#include "MAX30208.h"
+
+MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
+
+// Hardware serial port over DAPLink
+Serial uart(P2_1, P2_0);
+
+// Virtual serial port over USB
+USBSerial microUSB; 
+DigitalOut rLED(LED1);
+DigitalOut gLED(LED2);
+DigitalOut bLED(LED3);
+
+I2C i2c(P3_4, P3_5);  //sda,scl
+
+MAX30208 TempSensor(i2c, 0x50); //Constructor takes 7-bit slave adrs
+
+int main()
+{
+    
+    microUSB.printf("micro USB serial port\r\n");
+    rLED = LED_ON;
+    gLED = LED_ON;
+    bLED = LED_OFF;
+
+    rLED = LED_OFF;
+    
+    MAX30208::Configuration_InterruptEnable InterruptEnable;
+    MAX30208::Configuration_FIFOConfig2 FIFOConfig2;
+    MAX30208::Configuration_GPIOSetup GPIOSetup;
+    MAX30208::Configuration_GPIOControl GPIOControl;
+    
+
+    uint16_t val;
+    
+    while(1) {
+    
+    TempSensor.takeDataMeasurment();
+    wait_ms(50);
+    microUSB.printf("Before = %d\r\n",val);
+    TempSensor.readData(val);
+    microUSB.printf("After = %d\r\n",val);
+    float temp = TempSensor.toCelsius(val);
+    microUSB.printf("Temp C = %f\r\n",temp);
+    temp = TempSensor.toFahrenheit(temp);
+    microUSB.printf("Temp F = %f\r\n",temp);
+    
+    
+    
+    //readInterruptRegister
+    if (TempSensor.readInterruptRegister(InterruptEnable) == 0){
+        microUSB.printf("InterruptRegister intial config = %d\r\n", InterruptEnable.all);
+    }
+    InterruptEnable.config.TEMP_HI_EN = 1;
+    InterruptEnable.config.TEMP_LO_EN = 1;
+    if (TempSensor.writeInterruptRegister(InterruptEnable) != 0){
+        microUSB.printf("Error writing Interrupt register\r\n");
+    }
+    
+    //readFIFOConfig2
+    if (TempSensor.readFIFOConfig2(FIFOConfig2) == 0){
+        microUSB.printf("FIFOConfig2 initial config = %d\r\n", FIFOConfig2.all);
+    }
+    FIFOConfig2.config.FIFO_RO = 1;
+    FIFOConfig2.config.A_FULL_TYPE = 1;
+    if (TempSensor.writeFIFOConfig2(FIFOConfig2) != 0){
+        microUSB.printf("Error writing FIFO Config2 register\r\n");
+    }
+    
+    //readGPIOSetup
+    if (TempSensor.readGPIOSetup(GPIOSetup) == 0){
+        microUSB.printf("GPIOSetup initial config = %d\r\n", GPIOSetup.all);
+    }
+    GPIOSetup.config.GPIO0_MODE = 2;
+    GPIOSetup.config.GPIO1_MODE = 3;
+    if (TempSensor.writeGPIOSetup(GPIOSetup) != 0){
+        microUSB.printf("Error writing GPIO Setup register\r\n");
+    }
+    
+    //readGPIOControl
+    if (TempSensor.readGPIOControl(GPIOControl) == 0){
+        microUSB.printf("GPIOControl initial config = %d\r\n", GPIOControl.all);
+    }
+    GPIOControl.config.GPIO0_LL = 1;
+    GPIOControl.config.GPIO1_LL = 1;
+    if (TempSensor.writeGPIOControl(GPIOControl) != 0){
+        microUSB.printf("Error writing register\r\n");
+    }
+    
+    //writeInterruptRegister
+    if (TempSensor.readInterruptRegister(InterruptEnable) == 0){
+        microUSB.printf("Interrupt Register new config = %d\r\n", InterruptEnable.all);
+    }
+    InterruptEnable.config.TEMP_HI_EN = 0;
+    InterruptEnable.config.TEMP_LO_EN = 0;
+    if (TempSensor.writeInterruptRegister(InterruptEnable) != 0){
+        microUSB.printf("Error writing Interrupt Registerregister\r\n");
+    }
+    
+//writeFIFOConfig2
+    if (TempSensor.readFIFOConfig2(FIFOConfig2) == 0){
+        microUSB.printf("FIFOConfig2 new config = %d\r\n", FIFOConfig2.all);
+    }
+    FIFOConfig2.config.FIFO_RO = 0;
+    FIFOConfig2.config.A_FULL_TYPE = 0;
+    if (TempSensor.writeFIFOConfig2(FIFOConfig2) != 0){
+        microUSB.printf("Error writing register\r\n");
+    }
+    
+    //writeGPIOSetup
+    if (TempSensor.readGPIOSetup(GPIOSetup) == 0){
+        microUSB.printf("GPIOSetup new config = %d\r\n", GPIOSetup.all);
+    }
+    GPIOSetup.config.GPIO0_MODE = 0;
+    GPIOSetup.config.GPIO1_MODE = 0;
+    if (TempSensor.writeGPIOSetup(GPIOSetup) != 0){
+        microUSB.printf("Error writing register\r\n");
+    }
+    
+    /*//readGPIOControl
+    if (TempSensor.readGPIOControl(GPIOControl) == 0){
+        microUSB.printf("GPIOControl new config = %d\r\n", GPIOControl.all);
+    }
+    GPIOControl.config.GPIO0_LL = 0;
+    GPIOControl.config.GPIO1_LL = 0;
+    if (TempSensor.writeGPIOControl(GPIOControl) != 0){
+        microUSB.printf("Error writing register\r\n");
+    }
+    */
+    TempSensor.resetDevice();
+    
+    //NEED MORE WORK HERE, GOTTA CHECK A CONDITION ON THIS GUY
+    //TempSensor.readStatus()
+
+    microUSB.printf("\r\n\r\n");
+    uint16_t PointerValue;
+    
+    //Write Pointer Test
+    TempSensor.readWritePointer(PointerValue);
+    microUSB.printf("Current Write Pointer Value: %d\r\n",PointerValue);
+    microUSB.printf("New Value Measured\r\n");
+    TempSensor.takeDataMeasurment();
+    wait_ms(50);
+    TempSensor.readWritePointer(PointerValue);
+    microUSB.printf("Current Write Pointer Value: %d\r\n",PointerValue);
+
+    microUSB.printf("\r\n\r\n");
+    
+    //Read Pointer Test
+    TempSensor.readReadPointer(PointerValue);    
+    microUSB.printf("Current Read Pointer Value: %d\r\n",PointerValue);
+    TempSensor.readData(val);
+    microUSB.printf("New Value Read\r\n");
+    TempSensor.readReadPointer(PointerValue);    
+    microUSB.printf("Current Read Pointer Value: %d\r\n",PointerValue);
+    microUSB.printf("Read Pointer Written to '15'\r\n");
+    TempSensor.writeReadPointer(0x0F);
+    TempSensor.readReadPointer(PointerValue);
+    microUSB.printf("Current Read Pointer Value: %d\r\n",PointerValue);
+    
+    microUSB.printf("\r\n\r\n");
+    
+    uint16_t Counter;
+    TempSensor.resetDevice();
+    
+    //Data Counter
+    TempSensor.readDataCounter(Counter);
+    microUSB.printf("Initial Data Read: %d\r\n",Counter);
+    microUSB.printf("Reading 16 temperatures\r\n");
+    for(int i=0;i<16;i++){
+        TempSensor.takeDataMeasurment();
+        wait_ms(50);
+    }
+    TempSensor.readDataCounter(Counter);
+    microUSB.printf("Curent Data Read: %d\r\n",Counter);
+    
+    microUSB.printf("\r\n\r\n");
+    //Data Overflow
+    microUSB.printf("Reading 30 temperatures\r\n");
+    for (int i =0;i<30;i++){
+           TempSensor.takeDataMeasurment();
+           wait_ms(50);
+    }
+    TempSensor.readOverflow(Counter);
+    microUSB.printf("Overflow Counter: %d\r\n",Counter);
+    
+    microUSB.printf("\r\n\r\n");
+    uint16_t config;
+    TempSensor.resetDevice();
+    //Config1
+    TempSensor.readFIFOConfig1(config);    
+    microUSB.printf("FIFO Config init Value: %d\r\n",config);
+    microUSB.printf("Writing '3' to FIFO Config 1\r\n");
+    TempSensor.writeFIFOConfig1(0x03);
+    TempSensor.readFIFOConfig1(config);    
+    microUSB.printf("FIFO Config Value: %d\r\n",config);
+    
+    microUSB.printf("\r\n\r\n");
+    TempSensor.resetDevice();
+    //read/write alarm
+    uint16_t HI;
+    uint16_t LO;
+    TempSensor.readAlarmHigh(HI);
+    TempSensor.readAlarmLow(LO);
+    
+    microUSB.printf("Inital Alarm High: %d\r\n",HI);
+    microUSB.printf("Inital Alarm Low: %d\r\n",LO);
+    microUSB.printf("Setting High to '4321'\r\n");
+    microUSB.printf("Setting High to '1234'\r\n");
+    TempSensor.writeAlarmHigh(0x10E1);
+    TempSensor.writeAlarmLow(0x04D2);
+    TempSensor.readAlarmHigh(HI);
+    TempSensor.readAlarmLow(LO);
+    
+    microUSB.printf("Alarm High: %d\r\n",HI);
+    microUSB.printf("Alarm Low: %d\r\n",LO);
+    
+    microUSB.printf("\r\n\r\n\r\n\r\n");
+    TempSensor.resetDevice();
+    wait(5);
+    }
+}
+