Example main.c host software for the Maxim Integrated MAX30205 Extremely Accurate High Precision Human Body Temperature Sensor. Code example uses the MAX32630FTHR.

Dependencies:   MAX30205_Clinical_Temperature_Sensor max32630fthr USBDevice

Files at this revision

API Documentation at this revision

Comitter:
phonemacro
Date:
Mon Apr 15 21:18:43 2019 +0000
Parent:
0:f205abc96ff9
Child:
2:9670fb20b9a2
Commit message:
Initial converstion to c, c++ code

Changed in this revision

MAX30205.lib Show diff for this revision Revisions of this file
MAX30205_Clinical_Temperature_Sensor.lib Show annotated file Show diff for this revision Revisions of this file
USBDevice.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
max32630fthr.lib Show annotated file Show diff for this revision Revisions of this file
--- a/MAX30205.lib	Tue May 15 19:13:28 2018 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://os.mbed.com/teams/MaximIntegrated/code/MAX30205/#2aeb45dd2bb9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MAX30205_Clinical_Temperature_Sensor.lib	Mon Apr 15 21:18:43 2019 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/teams/MaximIntegrated/code/MAX30205/#d98e4a80a866
--- a/USBDevice.lib	Tue May 15 19:13:28 2018 +0000
+++ b/USBDevice.lib	Mon Apr 15 21:18:43 2019 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/teams/MaximIntegrated/code/USBDevice/#17ac7abb27a7
+https://developer.mbed.org/teams/MaximIntegrated/code/USBDevice/#dad310740b28
--- a/main.cpp	Tue May 15 19:13:28 2018 +0000
+++ b/main.cpp	Mon Apr 15 21:18:43 2019 +0000
@@ -32,37 +32,44 @@
 */
 #include "mbed.h"
 #include "max32630fthr.h"
+#include "max30205.h"
+#include "max30205_cpp.h"
+#include "max30205_c.h"
 #include "USBSerial.h"
-#include "MAX30205.h"
 
-MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
+Serial pc(USBTX, USBRX);          // Use USB debug probe for serial link
+Serial uart(P2_1, P2_0);
+void wait_sec_prompt(uint8_t time)
+{
+   // Ports and serial connections
+    uint32_t i;
+    for (i = 0; i < time; i++) {
+        pc.printf(".");
+        wait(1);
+    }
+    pc.printf("\r\n");
+}
 
-// Virtual serial port over USB
-USBSerial microUSB; 
 
+MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); 
+ 
 DigitalOut rLED(LED1);
 DigitalOut gLED(LED2);
 DigitalOut bLED(LED3);
-
-//Get I2C instance
-I2C i2cBus(I2C1_SDA, I2C1_SCL);
  
-//Get temp sensor instance
-MAX30205 bodyTempSensor(i2cBus, (0x90 >> 1));
+I2C i2cBus(P3_4, P3_5);
 
 // main() runs in its own thread in the OS
 // (note the calls to Thread::wait below for delays)
 
 /**
 * @brief Sample main program for MAX30205
-* @version 1.0000.0
+* @version 1.0001.0
 *
 * @details Sample main program for MAX30205.
 * The prints are sent to the terminal window (9600, 8n1).
-* The program initially flashes yellow once, then it
-* blinks green if it's able to communicate with
-* the MAX30205, otherwise, it blinks red.
-* The temperature is read out every half second.
+* The temperature is read in continous mode, then in shutdown mode for
+* C++ and C calls.
 * To run the program, drag and drop the .bin file into the 
 * DAPLINK folder. After it finishes flashing, cycle the power or 
 * reset the Pegasus after flashing by pressing the button on
@@ -72,44 +79,172 @@
 
 int main()
 {
-    int32_t ret;
-    uint16_t hystValue = 0;
-    uint16_t temperatureValue;
-    uint32_t expandTemperatureValue=0;
-    float Celsius;
-
+    uint32_t i;
+    float temperature;
+    uint8_t cfg;
+    DigitalOut rLED(LED1, LED_OFF);
+    DigitalOut gLED(LED2, LED_OFF);
+    DigitalOut bLED(LED3, LED_OFF);
     gLED = LED_ON;
-    rLED = LED_ON;  // init LED to yellow
-    bLED = LED_OFF;
-    wait(0.05);
-    
-    printf("Example program for MAX20305.\r\n");
-    ret = bodyTempSensor.readTHYST(hystValue);
-    if (ret != 0) {
-        printf("Communications to MAX20305 Failed: ret=%d, Thyst=0x%04X\r\n",ret, hystValue);
-        rLED = LED_ON;
+    pc.baud(9600);                    // Baud rate = 115200
+    pc.printf("MAX30205 Digital Thermometer and "
+        "Thermostat example source code.\r\n");
+    pc.printf("\r\n");
+    uint8_t i2c_addr = MAX30205_I2C_SLAVE_ADR_00;
+    uint8_t wait_shut = 90;
+    MAX30205 temp_sensor(i2cBus, i2c_addr);
+    i2cBus.frequency(400000);
+    /* Configure for time out enabled, normal format, fault filter 6,
+       active low polarity, comparator mode, continuous
+     */
+    temp_sensor.write_cfg_reg(uint8_t(MAX30205_CFG_TIMEOUT_ENABLE |
+        MAX30205_CFG_NORMAL_FORMAT| MAX30205_CFG_FAULT_FILTER_6 |
+        MAX30205_CFG_OS_POLARITY_ACT_LOW | MAX30205_CFG_COMPARATOR_MODE |
+        MAX30205_CFG_CONTINUOUS));
+    for (i = 0; i < 5; i++) {
+        wait(MAX30205_WAIT_CONV_TIME);
+        temperature =
+            temp_sensor.read_reg_as_temperature(MAX30205_REG_TEMPERATURE);
+        pc.printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
+            temperature, temp_sensor.celsius_to_fahrenheit(temperature));
     }
- 
-    while(true) {
-        ret=bodyTempSensor.readTemperature(temperatureValue);
-        if(!ret)
-        {
-            expandTemperatureValue = (uint32_t)temperatureValue;
-            Celsius = bodyTempSensor.toCelsius(expandTemperatureValue);
-            printf("The temperature is %f Celsius, ",Celsius);
-            printf("%f Fahrenheit\r\n",bodyTempSensor.toFahrenheit(Celsius));
+    temp_sensor.read_cfg_reg(&cfg);
+    pc.printf("Configuration Register = 0x%02Xh \r\n", cfg);
+#if 1
+    temp_sensor.write_trip_low_thyst(-63.9375);
+    temperature =
+        temp_sensor.read_reg_as_temperature(MAX30205_REG_THYST_LOW_TRIP);
+    pc.printf("Thyst Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
+            temperature, temp_sensor.celsius_to_fahrenheit(temperature));
+
+    temp_sensor.write_trip_high_tos(64.0625f);
+    temperature = temp_sensor.read_reg_as_temperature(MAX30205_REG_TOS_HIGH_TRIP);
+    pc.printf("TOS Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
+            temperature, temp_sensor.celsius_to_fahrenheit(temperature));
+    pc.printf("\r\n\r\n");
+#endif
 
-            rLED = LED_OFF;
-            gLED = !gLED;  // blink the green red
-            bLED = LED_OFF;
-        } else {
-            rLED = !rLED;  // blink the LED red
-            gLED = LED_OFF;
-            bLED = LED_OFF;
-        }
-        wait(0.5);
-    
+    pc.printf("\r\n");
+    temp_sensor.write_cfg_reg(uint8_t(MAX30205_CFG_ONE_SHOT_START |
+        MAX30205_CFG_TIMEOUT_DISABLE | MAX30205_CFG_EXTENDED_FORMAT |
+        MAX30205_CFG_FAULT_FILTER_4 | MAX30205_CFG_OS_POLARITY_ACT_LOW |
+        MAX30205_CFG_COMPARATOR_MODE | MAX30205_CFG_SHUTDOWN));
+    for (i = 0; i < 8; i++) {
+        wait_sec_prompt(wait_shut); /*  leave it in shutdown mode for a while */
+        /* Configure for one shot, time out disabled, extended format, fault filter 4,
+           active low polarity, comparator mode, shutdown
+         */
+        temp_sensor.write_cfg_reg(uint8_t(MAX30205_CFG_ONE_SHOT_START |
+            MAX30205_CFG_TIMEOUT_DISABLE | MAX30205_CFG_EXTENDED_FORMAT |
+            MAX30205_CFG_FAULT_FILTER_4 | MAX30205_CFG_OS_POLARITY_ACT_LOW |
+            MAX30205_CFG_COMPARATOR_MODE | MAX30205_CFG_SHUTDOWN));
+        wait(MAX30205_WAIT_CONV_TIME);
+        temperature =
+            temp_sensor.read_reg_as_temperature(MAX30205_REG_TEMPERATURE);
+        pc.printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
+            temperature, temp_sensor.celsius_to_fahrenheit(temperature));
+    }
+    temp_sensor.read_cfg_reg(&cfg);
+    pc.printf("Configuration Register = 0x%02Xh \r\n", cfg);
+
+    pc.printf("\r\n\r\n");
+
+#if 1
+    temp_sensor.write_trip_low_thyst(-55.0f);
+    temperature = 
+        temp_sensor.read_reg_as_temperature(MAX30205_REG_THYST_LOW_TRIP);
+    pc.printf("Thyst Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
+            temperature, temp_sensor.celsius_to_fahrenheit(temperature));
+
+    temp_sensor.write_trip_high_tos(125.0f);
+    temperature = temp_sensor.read_reg_as_temperature(MAX30205_REG_TOS_HIGH_TRIP);
+    pc.printf("TOS Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
+            temperature, temp_sensor.celsius_to_fahrenheit(temperature));
+    pc.printf("\r\n\r\n");
+#endif
+
+    /***************************************************************************
+     * Call the C code version of the driver
+     ***************************************************************************
+     */
+#include "max30205_c.h"
+    pc.printf("C implementation of the code\r\n");
+    max30205_init(i2c_addr);
+    /* Configure for time out enabled, normal format, fault filter 6,
+       active low polarity, comparator mode, continuous
+     */
+    max30205_write_cfg_reg(uint8_t(MAX30205_CFG_TIMEOUT_ENABLE |
+        MAX30205_CFG_NORMAL_FORMAT | MAX30205_CFG_FAULT_FILTER_6 |
+        MAX30205_CFG_OS_POLARITY_ACT_LOW | MAX30205_CFG_COMPARATOR_MODE |
+        MAX30205_CFG_CONTINUOUS), i2cBus);
+    for (i = 0; i < 5; i++) {
+        wait(MAX30205_WAIT_CONV_TIME);
+        temperature = max30205_read_reg_as_temperature(MAX30205_REG_TEMPERATURE,
+            i2cBus);
+        pc.printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
+            temperature, temp_sensor.celsius_to_fahrenheit(temperature));
     }
 
+    max30205_read_cfg_reg(&cfg, i2cBus);
+    pc.printf("Configuration Register = 0x%02Xh \r\n", cfg);
+
+#if 1
+    max30205_write_trip_low_thyst(-63.9375, i2cBus);
+    temperature = max30205_read_reg_as_temperature(MAX30205_REG_THYST_LOW_TRIP,
+        i2cBus);
+    pc.printf("Thyst Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
+            temperature, max30205_celsius_to_fahrenheit(temperature));
+
+    max30205_write_trip_high_tos(64.0625f, i2cBus);
+    temperature = max30205_read_reg_as_temperature(MAX30205_REG_TOS_HIGH_TRIP,
+        i2cBus);
+    pc.printf("TOS Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
+            temperature, max30205_celsius_to_fahrenheit(temperature));
+#endif
+
+    pc.printf("\r\n");
+    max30205_write_cfg_reg(uint8_t(MAX30205_CFG_ONE_SHOT_START |
+        MAX30205_CFG_TIMEOUT_DISABLE | MAX30205_CFG_EXTENDED_FORMAT |
+        MAX30205_CFG_FAULT_FILTER_4 | MAX30205_CFG_OS_POLARITY_ACT_LOW |
+        MAX30205_CFG_COMPARATOR_MODE | MAX30205_CFG_SHUTDOWN), i2cBus);
+    for (i = 0; i < 8; i++) {
+        wait_sec_prompt(wait_shut); /*  leave it in shutdown mode for a while */
+        /* Configure for one shot, time out disabled, extended format, fault filter 4,
+           active low polarity, comparator mode, shutdown
+         */
+        max30205_write_cfg_reg(uint8_t(MAX30205_CFG_ONE_SHOT_START |
+            MAX30205_CFG_TIMEOUT_DISABLE | MAX30205_CFG_EXTENDED_FORMAT |
+            MAX30205_CFG_FAULT_FILTER_4 | MAX30205_CFG_OS_POLARITY_ACT_LOW |
+            MAX30205_CFG_COMPARATOR_MODE | MAX30205_CFG_SHUTDOWN), i2cBus);
+        wait(MAX30205_WAIT_CONV_TIME);
+        temperature = max30205_read_reg_as_temperature(MAX30205_REG_TEMPERATURE,
+            i2cBus);
+        pc.printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
+            temperature, temp_sensor.celsius_to_fahrenheit(temperature));
+    }
+    max30205_read_cfg_reg(&cfg, i2cBus);
+    pc.printf("Configuration Register = 0x%02Xh \r\n", cfg);
+
+#if 1
+    max30205_write_trip_low_thyst(-55, i2cBus);
+    temperature = max30205_read_reg_as_temperature(MAX30205_REG_THYST_LOW_TRIP,
+        i2cBus);
+    pc.printf("Thyst Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
+            temperature, max30205_celsius_to_fahrenheit(temperature));
+
+    max30205_write_trip_high_tos(125.0f, i2cBus);
+    temperature = max30205_read_reg_as_temperature(MAX30205_REG_TOS_HIGH_TRIP,
+        i2cBus);
+    pc.printf("TOS Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
+            temperature, max30205_celsius_to_fahrenheit(temperature));
+#endif
+    pc.printf("\r\n\r\n\r\n");
+
+
+    while (true) {  // Blink the green LED 
+        gLED = !gLED;
+        wait(0.5);
+    }
 }
-
+ 
+ 
\ No newline at end of file
--- a/max32630fthr.lib	Tue May 15 19:13:28 2018 +0000
+++ b/max32630fthr.lib	Mon Apr 15 21:18:43 2019 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/teams/MaximIntegrated/code/max32630fthr/#9eb360063579
+http://developer.mbed.org/teams/MaximIntegrated/code/max32630fthr/#8f6e6a800f2f