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@8:5bbefd9bce9f, 2019-01-27 (annotated)
- Committer:
- phonemacro
- Date:
- Sun Jan 27 00:22:32 2019 +0000
- Revision:
- 8:5bbefd9bce9f
- Parent:
- 7:bf8c91e28a3b
- Child:
- 10:e315ecdb7bcd
Initial commit for one-shot temperature readings.
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 | 0:a3f9ce6b99f5 | 38 | MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); |
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 | 8:5bbefd9bce9f | 52 | * @version 1.0000.0000 |
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 | 0:a3f9ce6b99f5 | 69 | int ret, i; |
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 | 0:a3f9ce6b99f5 | 74 | |
phonemacro | 0:a3f9ce6b99f5 | 75 | gLED = LED_ON; |
phonemacro | 0:a3f9ce6b99f5 | 76 | |
phonemacro | 8:5bbefd9bce9f | 77 | MAX31723 max31723_temp(spi, selectPin); |
phonemacro | 8:5bbefd9bce9f | 78 | spi.format(8,3); /* 8-bit, SPI mode 3 */ |
phonemacro | 8:5bbefd9bce9f | 79 | spi.frequency(5000000); /* Use 5 MHz SPI bus */ |
phonemacro | 8:5bbefd9bce9f | 80 | /* Jumpers (JP1) on MAX31723PMB should be set to SPI mode configuration |
phonemacro | 8:5bbefd9bce9f | 81 | * or SERMODE pin should be set to VDD for SPI mode |
phonemacro | 8:5bbefd9bce9f | 82 | */ |
phonemacro | 0:a3f9ce6b99f5 | 83 | |
phonemacro | 8:5bbefd9bce9f | 84 | for (i = 0; i < 5; i++) { |
phonemacro | 8:5bbefd9bce9f | 85 | ret = max31723_temp.perform_one_shot(MAX31723_CONV_TIME_MSEC_12BIT); |
phonemacro | 8:5bbefd9bce9f | 86 | wait(MAX31723_CONV_TIME_MSEC_12BIT); |
phonemacro | 8:5bbefd9bce9f | 87 | temperature = max31723_temp.read_temp(); |
phonemacro | 8:5bbefd9bce9f | 88 | printf("Temperature = %4.4f Celsius, %4.4f Fahrenheit\r\n", |
phonemacro | 8:5bbefd9bce9f | 89 | temperature, max31723_temp.celsius_to_fahrenheit(temperature)); |
phonemacro | 8:5bbefd9bce9f | 90 | wait(2); |
phonemacro | 8:5bbefd9bce9f | 91 | } |
phonemacro | 7:bf8c91e28a3b | 92 | printf("\r\n"); |
phonemacro | 8:5bbefd9bce9f | 93 | while (true) { // Blink the green LED |
phonemacro | 0:a3f9ce6b99f5 | 94 | gLED = !gLED; |
phonemacro | 0:a3f9ce6b99f5 | 95 | wait(1.0); |
phonemacro | 0:a3f9ce6b99f5 | 96 | } |
phonemacro | 0:a3f9ce6b99f5 | 97 | } |