Sample host software for the Maxim Integrated MAX31875 Low Power Small Package Temperature Sensor. Hosted on the MAX32630FTHR. The MAX31875 may be used in wearables, thermostats, thermometers, and hardware temperature supervisors.

Dependencies:   MAX31875_Temperature_Sensor_Low_Power max32630fthr USBDevice

Committer:
phonemacro
Date:
Sun Feb 03 23:56:45 2019 +0000
Revision:
0:77036686489d
initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
phonemacro 0:77036686489d 1 /*******************************************************************************
phonemacro 0:77036686489d 2 * Copyright (C) 2019 Maxim Integrated Products, Inc., All Rights Reserved.
phonemacro 0:77036686489d 3 *
phonemacro 0:77036686489d 4 * Permission is hereby granted, free of charge, to any person obtaining a
phonemacro 0:77036686489d 5 * copy of this software and associated documentation files (the "Software"),
phonemacro 0:77036686489d 6 * to deal in the Software without restriction, including without limitation
phonemacro 0:77036686489d 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
phonemacro 0:77036686489d 8 * and/or sell copies of the Software, and to permit persons to whom the
phonemacro 0:77036686489d 9 * Software is furnished to do so, subject to the following conditions:
phonemacro 0:77036686489d 10 *
phonemacro 0:77036686489d 11 * The above copyright notice and this permission notice shall be included
phonemacro 0:77036686489d 12 * in all copies or substantial portions of the Software.
phonemacro 0:77036686489d 13 *
phonemacro 0:77036686489d 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
phonemacro 0:77036686489d 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
phonemacro 0:77036686489d 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
phonemacro 0:77036686489d 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
phonemacro 0:77036686489d 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
phonemacro 0:77036686489d 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
phonemacro 0:77036686489d 20 * OTHER DEALINGS IN THE SOFTWARE.
phonemacro 0:77036686489d 21 *
phonemacro 0:77036686489d 22 * Except as contained in this notice, the name of Maxim Integrated
phonemacro 0:77036686489d 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
phonemacro 0:77036686489d 24 * Products, Inc. Branding Policy.
phonemacro 0:77036686489d 25 *
phonemacro 0:77036686489d 26 * The mere transfer of this software does not imply any licenses
phonemacro 0:77036686489d 27 * of trade secrets, proprietary technology, copyrights, patents,
phonemacro 0:77036686489d 28 * trademarks, maskwork rights, or any other form of intellectual
phonemacro 0:77036686489d 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
phonemacro 0:77036686489d 30 * ownership rights.
phonemacro 0:77036686489d 31 *******************************************************************************
phonemacro 0:77036686489d 32 */
phonemacro 0:77036686489d 33 #include "mbed.h"
phonemacro 0:77036686489d 34 #include "max32630fthr.h"
phonemacro 0:77036686489d 35 #include "max31875.h"
phonemacro 0:77036686489d 36 #include "USBSerial.h"
phonemacro 0:77036686489d 37
phonemacro 0:77036686489d 38 MAX32630FTHR pegasus(MAX32630FTHR::VIO_1V8);
phonemacro 0:77036686489d 39
phonemacro 0:77036686489d 40 DigitalOut rLED(LED1);
phonemacro 0:77036686489d 41 DigitalOut gLED(LED2);
phonemacro 0:77036686489d 42 DigitalOut bLED(LED3);
phonemacro 0:77036686489d 43
phonemacro 0:77036686489d 44 I2C i2cBus(P3_4, P3_5);
phonemacro 0:77036686489d 45
phonemacro 0:77036686489d 46 // main() runs in its own thread in the OS
phonemacro 0:77036686489d 47 // (note the calls to Thread::wait below for delays)
phonemacro 0:77036686489d 48 /**
phonemacro 0:77036686489d 49 * @brief Sample main program for MAX31875
phonemacro 0:77036686489d 50 * @version 1.0000.0000
phonemacro 0:77036686489d 51 *
phonemacro 0:77036686489d 52 * @details Sample main program for MAX31875
phonemacro 0:77036686489d 53 * The prints are sent to the terminal window (9600, 8n1).
phonemacro 0:77036686489d 54 * The program sets the GPIOs to 1.8V and the program
phonemacro 0:77036686489d 55 * configures the chip and reads temperatures.
phonemacro 0:77036686489d 56 * To run the program, drag and drop the .bin file into the
phonemacro 0:77036686489d 57 * DAPLINK folder. After it finishes flashing, cycle the power or
phonemacro 0:77036686489d 58 * reset the Pegasus (MAX32630FTHR) after flashing by pressing the button on
phonemacro 0:77036686489d 59 * the Pegasus next to the battery connector or the button
phonemacro 0:77036686489d 60 * on the MAXREFDES100HDK.
phonemacro 0:77036686489d 61 */
phonemacro 0:77036686489d 62 int main()
phonemacro 0:77036686489d 63 {
phonemacro 0:77036686489d 64 uint32_t i;
phonemacro 0:77036686489d 65 float temperature;
phonemacro 0:77036686489d 66 uint16_t cfg;
phonemacro 0:77036686489d 67 DigitalOut rLED(LED1, LED_OFF);
phonemacro 0:77036686489d 68 DigitalOut gLED(LED2, LED_OFF);
phonemacro 0:77036686489d 69 DigitalOut bLED(LED3, LED_OFF);
phonemacro 0:77036686489d 70 gLED = LED_ON;
phonemacro 0:77036686489d 71 printf("MAX31875 Small Package Temperature Sensor example source code.\r\n");
phonemacro 0:77036686489d 72 printf("\r\n");
phonemacro 0:77036686489d 73
phonemacro 0:77036686489d 74 MAX31875 temp_sensor(i2cBus, MAX31875_I2C_SLAVE_ADR_R0);
phonemacro 0:77036686489d 75 i2cBus.frequency(1000000);
phonemacro 0:77036686489d 76
phonemacro 0:77036686489d 77 /* Configure for fault filter 1, comparator, continuous,
phonemacro 0:77036686489d 78 * normal format, 8 sps, 12 bit resolution
phonemacro 0:77036686489d 79 */
phonemacro 0:77036686489d 80 temp_sensor.write_cfg(uint16_t(MAX31875_CFG_FAULT_FILTER_1 |
phonemacro 0:77036686489d 81 MAX31875_CFG_COMPARATOR_MODE | MAX31875_CFG_CONTINUOUS |
phonemacro 0:77036686489d 82 MAX31875_CFG_NORMAL_FORMAT | MAX31875_CFG_CONV_RATE_8 |
phonemacro 0:77036686489d 83 MAX31875_CFG_RESOLUTION_12BIT));
phonemacro 0:77036686489d 84 for (i = 0; i < 10; i++) {
phonemacro 0:77036686489d 85 wait(MAX31875_WAIT_CONV_RATE_8);
phonemacro 0:77036686489d 86 temperature = temp_sensor.read_reg_as_temperature(MAX31875_REG_TEMPERATURE);
phonemacro 0:77036686489d 87 printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n",
phonemacro 0:77036686489d 88 temperature, temp_sensor.celsius_to_fahrenheit(temperature));
phonemacro 0:77036686489d 89 }
phonemacro 0:77036686489d 90 temp_sensor.read_reg(&cfg, MAX31875_REG_CONFIGURATION);
phonemacro 0:77036686489d 91 printf("Configuration Register = 0x%04Xh \r\n", cfg);
phonemacro 0:77036686489d 92
phonemacro 0:77036686489d 93 printf("\r\n");
phonemacro 0:77036686489d 94
phonemacro 0:77036686489d 95
phonemacro 0:77036686489d 96 /* Configure for fault filter 4, interrupt, shutdown,
phonemacro 0:77036686489d 97 * extended format, 0.25 sps, 10 bit resolution, start one-shot
phonemacro 0:77036686489d 98 */
phonemacro 0:77036686489d 99 for (i = 0; i < 5; i++) {
phonemacro 0:77036686489d 100 temp_sensor.write_cfg(uint16_t(MAX31875_CFG_FAULT_FILTER_4 |
phonemacro 0:77036686489d 101 MAX31875_CFG_INTERRUPT_MODE | MAX31875_CFG_SHUTDOWN |
phonemacro 0:77036686489d 102 MAX31875_CFG_EXTENDED_FORMAT| MAX31875_CFG_CONV_RATE_0_25 |
phonemacro 0:77036686489d 103 MAX31875_CFG_RESOLUTION_10BIT | MAX31875_CFG_ONE_SHOT_START));
phonemacro 0:77036686489d 104 wait(MAX31875_WAIT_CONV_RATE_0_25);
phonemacro 0:77036686489d 105 temperature = temp_sensor.read_reg_as_temperature(MAX31875_REG_TEMPERATURE);
phonemacro 0:77036686489d 106 printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n",
phonemacro 0:77036686489d 107 temperature, temp_sensor.celsius_to_fahrenheit(temperature));
phonemacro 0:77036686489d 108 }
phonemacro 0:77036686489d 109 temp_sensor.read_reg(&cfg, MAX31875_REG_CONFIGURATION);
phonemacro 0:77036686489d 110 printf("Configuration Register = 0x%04Xh \r\n", cfg);
phonemacro 0:77036686489d 111
phonemacro 0:77036686489d 112 printf("\r\n\r\n");
phonemacro 0:77036686489d 113 #if 0
phonemacro 0:77036686489d 114 temp_sensor.write_trip_low(3.0625f);
phonemacro 0:77036686489d 115 temp_sensor.read_reg(&cfg, MAX31875_REG_CONFIGURATION);
phonemacro 0:77036686489d 116 temperature = temp_sensor.read_reg_as_temperature(MAX31875_REG_THYST);
phonemacro 0:77036686489d 117 printf("Thyst Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n",
phonemacro 0:77036686489d 118 temperature, temp_sensor.celsius_to_fahrenheit(temperature));
phonemacro 0:77036686489d 119
phonemacro 0:77036686489d 120 temp_sensor.write_trip_high(129.0625f);
phonemacro 0:77036686489d 121 temperature = temp_sensor.read_reg_as_temperature(MAX31875_REG_TOS);
phonemacro 0:77036686489d 122 printf("TOS Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n",
phonemacro 0:77036686489d 123 temperature, temp_sensor.celsius_to_fahrenheit(temperature));
phonemacro 0:77036686489d 124 printf("\r\n\r\n");
phonemacro 0:77036686489d 125 #endif
phonemacro 0:77036686489d 126 while (true) { // Blink the green LED
phonemacro 0:77036686489d 127 gLED = !gLED;
phonemacro 0:77036686489d 128 wait(0.5);
phonemacro 0:77036686489d 129 }
phonemacro 0:77036686489d 130 }
phonemacro 0:77036686489d 131
phonemacro 0:77036686489d 132