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
Diff: main.cpp
- Revision:
- 3:27e027ab268b
- Parent:
- 2:836c3793cd68
- Child:
- 4:1e55b4a715da
--- a/main.cpp Mon Aug 10 13:10:57 2020 +0000 +++ b/main.cpp Wed Aug 12 20:02:32 2020 +0000 @@ -1,5 +1,5 @@ /******************************************************************************* -* Copyright (C) 2018 Maxim Integrated Products, Inc., All Rights Reserved. +* Copyright (C) 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"), @@ -29,7 +29,12 @@ * property whatsoever. Maxim Integrated Products, Inc. retains all * ownership rights. ******************************************************************************* -*/ +* @file MAX30208LibTest.cpp +* @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. +* @version 1.0 +* @notes This is a test program for the MAX30208 MBed Library. Both MAX30208.h and MAX30208.cpp need to be imported into the project. +*****************************************************************************/ + #include "mbed.h" #include "max32630fthr.h" #include "USBSerial.h" @@ -53,13 +58,11 @@ int main() { - microUSB.printf("micro USB serial port\r\n"); rLED = LED_ON; gLED = LED_ON; bLED = LED_OFF; - - rLED = LED_OFF; + //Initialize Configuration Registers MAX30208::Configuration_InterruptEnable InterruptEnable; MAX30208::Configuration_FIFOConfig2 FIFOConfig2; MAX30208::Configuration_GPIOSetup GPIOSetup; @@ -71,95 +74,92 @@ 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); + TempSensor.takeDataMeasurment(); //Send temperature record signal + wait_ms(50); //Maximum temperature record time + TempSensor.readData(val); //Read the data + float temp = TempSensor.toCelsius(val); //Convert raw data to celsius microUSB.printf("Temp C = %f\r\n",temp); - temp = TempSensor.toFahrenheit(temp); + temp = TempSensor.toFahrenheit(temp); //Conver celsius to fahrenheit microUSB.printf("Temp F = %f\r\n",temp); //readInterruptRegister - if (TempSensor.readInterruptRegister(InterruptEnable) == 0){ + if (TempSensor.readInterruptRegister(InterruptEnable) == 0){ microUSB.printf("InterruptRegister intial config = %d\r\n", InterruptEnable.all); } + + //Set Interrupt Config Register Values 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"); } + if (TempSensor.readInterruptRegister(InterruptEnable) == 0){ + microUSB.printf("InterruptRegister new config = %d\r\n", InterruptEnable.all); + } + microUSB.printf("\r\n\r\n"); //readFIFOConfig2 if (TempSensor.readFIFOConfig2(FIFOConfig2) == 0){ microUSB.printf("FIFOConfig2 initial config = %d\r\n", FIFOConfig2.all); } - FIFOConfig2.config.FIFO_RO = 1; + + //Set FIFO Config 2 Register Values + 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"); } + if (TempSensor.readFIFOConfig2(FIFOConfig2) == 0){ + microUSB.printf("FIFOConfig2 new config = %d\r\n", FIFOConfig2.all); + } + + microUSB.printf("\r\n\r\n"); + //readGPIOSetup if (TempSensor.readGPIOSetup(GPIOSetup) == 0){ microUSB.printf("GPIOSetup initial config = %d\r\n", GPIOSetup.all); } + + //Set GPIO Setup Register Values GPIOSetup.config.GPIO0_MODE = 2; GPIOSetup.config.GPIO1_MODE = 3; if (TempSensor.writeGPIOSetup(GPIOSetup) != 0){ microUSB.printf("Error writing GPIO Setup register\r\n"); } + if (TempSensor.readGPIOSetup(GPIOSetup) == 0){ + microUSB.printf("GPIOSetup new config = %d\r\n", GPIOSetup.all); + } + + microUSB.printf("\r\n\r\n"); + //readGPIOControl if (TempSensor.readGPIOControl(GPIOControl) == 0){ microUSB.printf("GPIOControl initial config = %d\r\n", GPIOControl.all); } + + //Set GPIO Control Register Values 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"); + if (TempSensor.readGPIOControl(GPIOControl) == 0){ + microUSB.printf("GPIOControl new config = %d\r\n", GPIOControl.all); } -//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"); - } - - TempSensor.resetDevice(); + TempSensor.resetDevice(); //Reset Device Registers microUSB.printf("\r\n\r\n"); uint16_t PointerValue; - //Write Pointer Test + //Write Data Pointer Test (Read Only) TempSensor.readWritePointer(PointerValue); microUSB.printf("Current Write Pointer Value: %d\r\n",PointerValue); microUSB.printf("New Value Measured\r\n"); @@ -170,7 +170,7 @@ microUSB.printf("\r\n\r\n"); - //Read Pointer Test + //Read Data Pointer Test (Read and Write) TempSensor.readReadPointer(PointerValue); microUSB.printf("Current Read Pointer Value: %d\r\n",PointerValue); TempSensor.readData(val); @@ -184,8 +184,10 @@ microUSB.printf("\r\n\r\n"); + + TempSensor.resetDevice(); //Reset Device Registers + uint16_t Counter; - TempSensor.resetDevice(); //Data Counter TempSensor.readDataCounter(Counter); @@ -195,22 +197,31 @@ TempSensor.takeDataMeasurment(); wait_ms(50); } + + //Read Number of Data Points Collected TempSensor.readDataCounter(Counter); microUSB.printf("Curent Data Read: %d\r\n",Counter); + microUSB.printf("\r\n\r\n"); - microUSB.printf("\r\n\r\n"); //Data Overflow microUSB.printf("Reading 30 temperatures\r\n"); + + //Overflow data registers for (int i =0;i<30;i++){ TempSensor.takeDataMeasurment(); wait_ms(50); } + + //Read Overflow Register TempSensor.readOverflow(Counter); microUSB.printf("Overflow Counter: %d\r\n",Counter); microUSB.printf("\r\n\r\n"); uint16_t config; - TempSensor.resetDevice(); + + TempSensor.resetDevice(); //Reset Device Registers + + //Config1 TempSensor.readFIFOConfig1(config); microUSB.printf("FIFO Config init Value: %d\r\n",config); @@ -220,8 +231,9 @@ microUSB.printf("FIFO Config Value: %d\r\n",config); microUSB.printf("\r\n\r\n"); - TempSensor.resetDevice(); - //read/write alarm + TempSensor.resetDevice(); //Reset Device Registers + + //Read Alarm Register uint16_t HI; uint16_t LO; TempSensor.readAlarmHigh(HI); @@ -231,8 +243,12 @@ 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"); + + //Write Alarm Registers TempSensor.writeAlarmHigh(0x10E1); TempSensor.writeAlarmLow(0x04D2); + + //Read Alarm Registers TempSensor.readAlarmHigh(HI); TempSensor.readAlarmLow(LO); @@ -240,7 +256,7 @@ microUSB.printf("Alarm Low: %d\r\n",LO); microUSB.printf("\r\n\r\n\r\n\r\n"); - TempSensor.resetDevice(); + TempSensor.resetDevice(); //Reset Device Registers wait(5); } }