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
main.cpp
00001 /******************************************************************************* 00002 * Copyright (C) 2019 Maxim Integrated Products, Inc., All Rights Reserved. 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a 00005 * copy of this software and associated documentation files (the "Software"), 00006 * to deal in the Software without restriction, including without limitation 00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00008 * and/or sell copies of the Software, and to permit persons to whom the 00009 * Software is furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included 00012 * in all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00020 * OTHER DEALINGS IN THE SOFTWARE. 00021 * 00022 * Except as contained in this notice, the name of Maxim Integrated 00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated 00024 * Products, Inc. Branding Policy. 00025 * 00026 * The mere transfer of this software does not imply any licenses 00027 * of trade secrets, proprietary technology, copyrights, patents, 00028 * trademarks, maskwork rights, or any other form of intellectual 00029 * property whatsoever. Maxim Integrated Products, Inc. retains all 00030 * ownership rights. 00031 ******************************************************************************* 00032 */ 00033 #include "mbed.h" 00034 #include "max32630fthr.h" 00035 #include "max31875.h" 00036 #include "USBSerial.h" 00037 00038 MAX32630FTHR pegasus(MAX32630FTHR::VIO_1V8); 00039 00040 DigitalOut rLED(LED1); 00041 DigitalOut gLED(LED2); 00042 DigitalOut bLED(LED3); 00043 00044 I2C i2cBus(P3_4, P3_5); 00045 00046 // main() runs in its own thread in the OS 00047 // (note the calls to Thread::wait below for delays) 00048 /** 00049 * @brief Sample main program for MAX31875 00050 * @version 1.0000.0000 00051 * 00052 * @details Sample main program for MAX31875 00053 * The prints are sent to the terminal window (9600, 8n1). 00054 * The program sets the GPIOs to 1.8V and the program 00055 * configures the chip and reads temperatures. 00056 * To run the program, drag and drop the .bin file into the 00057 * DAPLINK folder. After it finishes flashing, cycle the power or 00058 * reset the Pegasus (MAX32630FTHR) after flashing by pressing the button on 00059 * the Pegasus next to the battery connector or the button 00060 * on the MAXREFDES100HDK. 00061 */ 00062 int main() 00063 { 00064 uint32_t i; 00065 float temperature; 00066 uint16_t cfg; 00067 DigitalOut rLED(LED1, LED_OFF); 00068 DigitalOut gLED(LED2, LED_OFF); 00069 DigitalOut bLED(LED3, LED_OFF); 00070 gLED = LED_ON; 00071 printf("MAX31875 Small Package Temperature Sensor example source code.\r\n"); 00072 printf("\r\n"); 00073 00074 MAX31875 temp_sensor(i2cBus, MAX31875_I2C_SLAVE_ADR_R0); 00075 i2cBus.frequency(1000000); 00076 00077 /* Configure for fault filter 1, comparator, continuous, 00078 * normal format, 8 sps, 12 bit resolution 00079 */ 00080 temp_sensor.write_cfg(uint16_t(MAX31875_CFG_FAULT_FILTER_1 | 00081 MAX31875_CFG_COMPARATOR_MODE | MAX31875_CFG_CONTINUOUS | 00082 MAX31875_CFG_NORMAL_FORMAT | MAX31875_CFG_CONV_RATE_8 | 00083 MAX31875_CFG_RESOLUTION_12BIT)); 00084 for (i = 0; i < 10; i++) { 00085 wait(MAX31875_WAIT_CONV_RATE_8); 00086 temperature = temp_sensor.read_reg_as_temperature(MAX31875_REG_TEMPERATURE); 00087 printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 00088 temperature, temp_sensor.celsius_to_fahrenheit(temperature)); 00089 } 00090 temp_sensor.read_reg(&cfg, MAX31875_REG_CONFIGURATION); 00091 printf("Configuration Register = 0x%04Xh \r\n", cfg); 00092 00093 printf("\r\n"); 00094 00095 00096 /* Configure for fault filter 4, interrupt, shutdown, 00097 * extended format, 0.25 sps, 10 bit resolution, start one-shot 00098 */ 00099 for (i = 0; i < 5; i++) { 00100 temp_sensor.write_cfg(uint16_t(MAX31875_CFG_FAULT_FILTER_4 | 00101 MAX31875_CFG_INTERRUPT_MODE | MAX31875_CFG_SHUTDOWN | 00102 MAX31875_CFG_EXTENDED_FORMAT| MAX31875_CFG_CONV_RATE_0_25 | 00103 MAX31875_CFG_RESOLUTION_10BIT | MAX31875_CFG_ONE_SHOT_START)); 00104 wait(MAX31875_WAIT_CONV_RATE_0_25); 00105 temperature = temp_sensor.read_reg_as_temperature(MAX31875_REG_TEMPERATURE); 00106 printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 00107 temperature, temp_sensor.celsius_to_fahrenheit(temperature)); 00108 } 00109 temp_sensor.read_reg(&cfg, MAX31875_REG_CONFIGURATION); 00110 printf("Configuration Register = 0x%04Xh \r\n", cfg); 00111 00112 printf("\r\n\r\n"); 00113 #if 0 00114 temp_sensor.write_trip_low(3.0625f); 00115 temp_sensor.read_reg(&cfg, MAX31875_REG_CONFIGURATION); 00116 temperature = temp_sensor.read_reg_as_temperature(MAX31875_REG_THYST); 00117 printf("Thyst Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 00118 temperature, temp_sensor.celsius_to_fahrenheit(temperature)); 00119 00120 temp_sensor.write_trip_high(129.0625f); 00121 temperature = temp_sensor.read_reg_as_temperature(MAX31875_REG_TOS); 00122 printf("TOS Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 00123 temperature, temp_sensor.celsius_to_fahrenheit(temperature)); 00124 printf("\r\n\r\n"); 00125 #endif 00126 while (true) { // Blink the green LED 00127 gLED = !gLED; 00128 wait(0.5); 00129 } 00130 } 00131 00132
Generated on Thu Jul 21 2022 20:45:34 by 1.7.2