Example host software for the Maxim Integrated MAX31723/MAX31722 Device Temperature Sensor. Hosted on the MAX32630FTHR. The MAX31723 may be used in thermostats, thermometers, and hardware temperature supervisors.
Dependencies: MAX31723_Digital_Temperature_Sensor max32630fthr USBDevice
main.cpp@15:2ab1415b0896, 2019-02-14 (annotated)
- Committer:
- phonemacro
- Date:
- Thu Feb 14 09:15:58 2019 +0000
- Revision:
- 15:2ab1415b0896
- Parent:
- 14:a976a6a00f7f
Use latest max31723 library.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
phonemacro | 0:a3f9ce6b99f5 | 1 | /******************************************************************************* |
phonemacro | 8:5bbefd9bce9f | 2 | * Copyright (C) 2019 Maxim Integrated Products, Inc., All Rights Reserved. |
phonemacro | 0:a3f9ce6b99f5 | 3 | * |
phonemacro | 0:a3f9ce6b99f5 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
phonemacro | 0:a3f9ce6b99f5 | 5 | * copy of this software and associated documentation files (the "Software"), |
phonemacro | 0:a3f9ce6b99f5 | 6 | * to deal in the Software without restriction, including without limitation |
phonemacro | 0:a3f9ce6b99f5 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
phonemacro | 0:a3f9ce6b99f5 | 8 | * and/or sell copies of the Software, and to permit persons to whom the |
phonemacro | 0:a3f9ce6b99f5 | 9 | * Software is furnished to do so, subject to the following conditions: |
phonemacro | 0:a3f9ce6b99f5 | 10 | * |
phonemacro | 0:a3f9ce6b99f5 | 11 | * The above copyright notice and this permission notice shall be included |
phonemacro | 0:a3f9ce6b99f5 | 12 | * in all copies or substantial portions of the Software. |
phonemacro | 0:a3f9ce6b99f5 | 13 | * |
phonemacro | 0:a3f9ce6b99f5 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
phonemacro | 0:a3f9ce6b99f5 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
phonemacro | 0:a3f9ce6b99f5 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
phonemacro | 0:a3f9ce6b99f5 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES |
phonemacro | 0:a3f9ce6b99f5 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
phonemacro | 0:a3f9ce6b99f5 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
phonemacro | 0:a3f9ce6b99f5 | 20 | * OTHER DEALINGS IN THE SOFTWARE. |
phonemacro | 0:a3f9ce6b99f5 | 21 | * |
phonemacro | 0:a3f9ce6b99f5 | 22 | * Except as contained in this notice, the name of Maxim Integrated |
phonemacro | 0:a3f9ce6b99f5 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated |
phonemacro | 0:a3f9ce6b99f5 | 24 | * Products, Inc. Branding Policy. |
phonemacro | 0:a3f9ce6b99f5 | 25 | * |
phonemacro | 0:a3f9ce6b99f5 | 26 | * The mere transfer of this software does not imply any licenses |
phonemacro | 0:a3f9ce6b99f5 | 27 | * of trade secrets, proprietary technology, copyrights, patents, |
phonemacro | 0:a3f9ce6b99f5 | 28 | * trademarks, maskwork rights, or any other form of intellectual |
phonemacro | 0:a3f9ce6b99f5 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all |
phonemacro | 0:a3f9ce6b99f5 | 30 | * ownership rights. |
phonemacro | 0:a3f9ce6b99f5 | 31 | ******************************************************************************* |
phonemacro | 0:a3f9ce6b99f5 | 32 | */ |
phonemacro | 0:a3f9ce6b99f5 | 33 | #include "mbed.h" |
phonemacro | 0:a3f9ce6b99f5 | 34 | #include "max32630fthr.h" |
phonemacro | 8:5bbefd9bce9f | 35 | #include "max31723.h" |
phonemacro | 0:a3f9ce6b99f5 | 36 | #include "USBSerial.h" |
phonemacro | 0:a3f9ce6b99f5 | 37 | |
phonemacro | 11:36f82087066e | 38 | MAX32630FTHR pegasus(MAX32630FTHR::VIO_1V8); /* Pegasus, MAX31723: use 1.8V */ |
phonemacro | 0:a3f9ce6b99f5 | 39 | |
phonemacro | 0:a3f9ce6b99f5 | 40 | DigitalOut rLED(LED1); |
phonemacro | 0:a3f9ce6b99f5 | 41 | DigitalOut gLED(LED2); |
phonemacro | 0:a3f9ce6b99f5 | 42 | DigitalOut bLED(LED3); |
phonemacro | 1:a7990c969d1a | 43 | |
phonemacro | 8:5bbefd9bce9f | 44 | DigitalOut selectPin(P3_0); /* Pin 3_0 is used to drive chip enable low */ |
phonemacro | 8:5bbefd9bce9f | 45 | SPI spi(P5_1, P5_2, P5_0); /* mosi, miso, sclk */ |
phonemacro | 1:a7990c969d1a | 46 | |
phonemacro | 8:5bbefd9bce9f | 47 | |
phonemacro | 4:51c1a4c4f762 | 48 | /** main() runs in its own thread in the OS */ |
phonemacro | 4:51c1a4c4f762 | 49 | /** (note the calls to Thread::wait below for delays) */ |
phonemacro | 2:07fde4ba8e91 | 50 | /** |
phonemacro | 8:5bbefd9bce9f | 51 | * @brief Sample main program for Maxim Integrated MAX31723 |
phonemacro | 15:2ab1415b0896 | 52 | * @version 1.0000.0004 |
phonemacro | 4:51c1a4c4f762 | 53 | * |
phonemacro | 8:5bbefd9bce9f | 54 | * @details Sample main program for MAX31723/MAX31722 |
phonemacro | 4:51c1a4c4f762 | 55 | * The prints are sent to the terminal window (9600, 8n1). |
phonemacro | 8:5bbefd9bce9f | 56 | * The program configures the SPI buss and then it performs |
phonemacro | 8:5bbefd9bce9f | 57 | * 5 one shot readings. |
phonemacro | 8:5bbefd9bce9f | 58 | * The program then blinks the green LED. |
phonemacro | 4:51c1a4c4f762 | 59 | * To run the program, drag and drop the .bin file into the |
phonemacro | 4:51c1a4c4f762 | 60 | * DAPLINK folder. After it finishes flashing, cycle the power or |
phonemacro | 4:51c1a4c4f762 | 61 | * reset the Pegasus (MAX32630FTHR) after flashing by pressing the button on |
phonemacro | 4:51c1a4c4f762 | 62 | * the Pegasus next to the battery connector or the button |
phonemacro | 4:51c1a4c4f762 | 63 | * on the MAXREFDES100HDK. |
phonemacro | 4:51c1a4c4f762 | 64 | */ |
phonemacro | 8:5bbefd9bce9f | 65 | |
phonemacro | 8:5bbefd9bce9f | 66 | |
phonemacro | 0:a3f9ce6b99f5 | 67 | int main() |
phonemacro | 0:a3f9ce6b99f5 | 68 | { |
phonemacro | 13:052296efd9e3 | 69 | int i, ret; |
phonemacro | 8:5bbefd9bce9f | 70 | float temperature; |
phonemacro | 0:a3f9ce6b99f5 | 71 | DigitalOut rLED(LED1, LED_OFF); |
phonemacro | 0:a3f9ce6b99f5 | 72 | DigitalOut gLED(LED2, LED_OFF); |
phonemacro | 0:a3f9ce6b99f5 | 73 | DigitalOut bLED(LED3, LED_OFF); |
phonemacro | 13:052296efd9e3 | 74 | printf("MAX31723 Temperature Sensor example code.\r\n"); |
phonemacro | 13:052296efd9e3 | 75 | printf("\r\n"); |
phonemacro | 0:a3f9ce6b99f5 | 76 | |
phonemacro | 0:a3f9ce6b99f5 | 77 | gLED = LED_ON; |
phonemacro | 0:a3f9ce6b99f5 | 78 | |
phonemacro | 13:052296efd9e3 | 79 | MAX31723 temp_sensor(spi, selectPin); |
phonemacro | 8:5bbefd9bce9f | 80 | spi.format(8,3); /* 8-bit, SPI mode 3 */ |
phonemacro | 8:5bbefd9bce9f | 81 | spi.frequency(5000000); /* Use 5 MHz SPI bus */ |
phonemacro | 8:5bbefd9bce9f | 82 | /* Jumpers (JP1) on MAX31723PMB should be set to SPI mode configuration |
phonemacro | 8:5bbefd9bce9f | 83 | * or SERMODE pin should be set to VDD for SPI mode |
phonemacro | 8:5bbefd9bce9f | 84 | */ |
phonemacro | 13:052296efd9e3 | 85 | ret = temp_sensor.perform_one_shot_int(MAX31723_CFG_RESOLUTION_12BIT); |
phonemacro | 10:e315ecdb7bcd | 86 | |
phonemacro | 8:5bbefd9bce9f | 87 | for (i = 0; i < 5; i++) { |
phonemacro | 13:052296efd9e3 | 88 | ret = temp_sensor.perform_one_shot_int(MAX31723_CFG_RESOLUTION_12BIT); |
phonemacro | 8:5bbefd9bce9f | 89 | wait(MAX31723_CONV_TIME_MSEC_12BIT); |
phonemacro | 13:052296efd9e3 | 90 | temperature = temp_sensor.read_temperature(); |
phonemacro | 8:5bbefd9bce9f | 91 | printf("Temperature = %4.4f Celsius, %4.4f Fahrenheit\r\n", |
phonemacro | 13:052296efd9e3 | 92 | temperature, temp_sensor.celsius_to_fahrenheit(temperature)); |
phonemacro | 8:5bbefd9bce9f | 93 | wait(2); |
phonemacro | 8:5bbefd9bce9f | 94 | } |
phonemacro | 13:052296efd9e3 | 95 | printf("Configuration Register = 0x%02Xh \r\n", temp_sensor.read_cfg()); |
phonemacro | 10:e315ecdb7bcd | 96 | |
phonemacro | 7:bf8c91e28a3b | 97 | printf("\r\n"); |
phonemacro | 11:36f82087066e | 98 | |
phonemacro | 13:052296efd9e3 | 99 | |
phonemacro | 13:052296efd9e3 | 100 | // temp_sensor.write_trip_low(-25.0625f); |
phonemacro | 13:052296efd9e3 | 101 | temperature = temp_sensor.read_trip_low(); |
phonemacro | 13:052296efd9e3 | 102 | printf("Tlow Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", |
phonemacro | 13:052296efd9e3 | 103 | temperature, temp_sensor.celsius_to_fahrenheit(temperature)); |
phonemacro | 13:052296efd9e3 | 104 | |
phonemacro | 13:052296efd9e3 | 105 | // temp_sensor.write_trip_high(25.5625f); |
phonemacro | 13:052296efd9e3 | 106 | temperature = temp_sensor.read_trip_high(); |
phonemacro | 13:052296efd9e3 | 107 | printf("Thigh Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", |
phonemacro | 13:052296efd9e3 | 108 | temperature, temp_sensor.celsius_to_fahrenheit(temperature)); |
phonemacro | 13:052296efd9e3 | 109 | printf("\r\n\r\n"); |
phonemacro | 13:052296efd9e3 | 110 | |
phonemacro | 13:052296efd9e3 | 111 | |
phonemacro | 8:5bbefd9bce9f | 112 | while (true) { // Blink the green LED |
phonemacro | 0:a3f9ce6b99f5 | 113 | gLED = !gLED; |
phonemacro | 0:a3f9ce6b99f5 | 114 | wait(1.0); |
phonemacro | 0:a3f9ce6b99f5 | 115 | } |
phonemacro | 0:a3f9ce6b99f5 | 116 | } |