Sample host software for the Maxim Integrated DS1775, DS75 Digital Thermometer Thermostat IC hosted on the MAX32630FTHR. The DS1775 is suitable for PCs, cell phones, and other thermally sensitive systems.

Dependencies:   max32630fthr DS1775_Digitial_Thermometer_Thermostat USBDevice

Committer:
phonemacro
Date:
Wed Apr 10 18:08:38 2019 +0000
Revision:
17:7de7da8c21c3
Parent:
16:1ebf8a6248be
Child:
18:0e25544cb810
change waits in shutdown to 5 sec

Who changed what in which revision?

UserRevisionLine numberNew contents of line
phonemacro 0:252077cb2ac5 1 /*******************************************************************************
phonemacro 0:252077cb2ac5 2 * Copyright (C) 2019 Maxim Integrated Products, Inc., All Rights Reserved.
phonemacro 0:252077cb2ac5 3 *
phonemacro 0:252077cb2ac5 4 * Permission is hereby granted, free of charge, to any person obtaining a
phonemacro 0:252077cb2ac5 5 * copy of this software and associated documentation files (the "Software"),
phonemacro 0:252077cb2ac5 6 * to deal in the Software without restriction, including without limitation
phonemacro 0:252077cb2ac5 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
phonemacro 0:252077cb2ac5 8 * and/or sell copies of the Software, and to permit persons to whom the
phonemacro 0:252077cb2ac5 9 * Software is furnished to do so, subject to the following conditions:
phonemacro 0:252077cb2ac5 10 *
phonemacro 0:252077cb2ac5 11 * The above copyright notice and this permission notice shall be included
phonemacro 0:252077cb2ac5 12 * in all copies or substantial portions of the Software.
phonemacro 0:252077cb2ac5 13 *
phonemacro 0:252077cb2ac5 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
phonemacro 0:252077cb2ac5 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
phonemacro 0:252077cb2ac5 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
phonemacro 0:252077cb2ac5 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
phonemacro 0:252077cb2ac5 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
phonemacro 0:252077cb2ac5 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
phonemacro 0:252077cb2ac5 20 * OTHER DEALINGS IN THE SOFTWARE.
phonemacro 0:252077cb2ac5 21 *
phonemacro 0:252077cb2ac5 22 * Except as contained in this notice, the name of Maxim Integrated
phonemacro 0:252077cb2ac5 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
phonemacro 0:252077cb2ac5 24 * Products, Inc. Branding Policy.
phonemacro 0:252077cb2ac5 25 *
phonemacro 0:252077cb2ac5 26 * The mere transfer of this software does not imply any licenses
phonemacro 0:252077cb2ac5 27 * of trade secrets, proprietary technology, copyrights, patents,
phonemacro 0:252077cb2ac5 28 * trademarks, maskwork rights, or any other form of intellectual
phonemacro 0:252077cb2ac5 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
phonemacro 0:252077cb2ac5 30 * ownership rights.
phonemacro 0:252077cb2ac5 31 *******************************************************************************
phonemacro 0:252077cb2ac5 32 */
phonemacro 0:252077cb2ac5 33 #include "mbed.h"
phonemacro 0:252077cb2ac5 34 #include "max32630fthr.h"
phonemacro 1:72ad3ee71812 35 #include "ds1775.h"
phonemacro 1:72ad3ee71812 36 #include "ds1775_cpp.h"
phonemacro 0:252077cb2ac5 37 #include "USBSerial.h"
phonemacro 0:252077cb2ac5 38
phonemacro 0:252077cb2ac5 39 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3);
phonemacro 0:252077cb2ac5 40
phonemacro 0:252077cb2ac5 41 DigitalOut rLED(LED1);
phonemacro 0:252077cb2ac5 42 DigitalOut gLED(LED2);
phonemacro 0:252077cb2ac5 43 DigitalOut bLED(LED3);
phonemacro 0:252077cb2ac5 44
phonemacro 0:252077cb2ac5 45 I2C i2cBus(P3_4, P3_5);
phonemacro 0:252077cb2ac5 46
phonemacro 0:252077cb2ac5 47 // main() runs in its own thread in the OS
phonemacro 0:252077cb2ac5 48 // (note the calls to Thread::wait below for delays)
phonemacro 0:252077cb2ac5 49 /**
phonemacro 1:72ad3ee71812 50 * @brief Sample main program for DS1775
phonemacro 14:8ca56fd6b35e 51 * @version 1.0000.0002
phonemacro 0:252077cb2ac5 52 *
phonemacro 1:72ad3ee71812 53 * @details Sample main program for DS1775
phonemacro 0:252077cb2ac5 54 * The prints are sent to the terminal window (9600, 8n1).
phonemacro 1:72ad3ee71812 55 * The program sets the GPIOs to 3.3V and the program
phonemacro 0:252077cb2ac5 56 * configures the chip and reads temperatures.
phonemacro 0:252077cb2ac5 57 * To run the program, drag and drop the .bin file into the
phonemacro 0:252077cb2ac5 58 * DAPLINK folder. After it finishes flashing, cycle the power or
phonemacro 0:252077cb2ac5 59 * reset the Pegasus (MAX32630FTHR) after flashing by pressing the button on
phonemacro 0:252077cb2ac5 60 * the Pegasus next to the battery connector or the button
phonemacro 0:252077cb2ac5 61 * on the MAXREFDES100HDK.
phonemacro 0:252077cb2ac5 62 */
phonemacro 0:252077cb2ac5 63 int main()
phonemacro 0:252077cb2ac5 64 {
phonemacro 0:252077cb2ac5 65 uint32_t i;
phonemacro 0:252077cb2ac5 66 float temperature;
phonemacro 2:aa39032bf778 67 uint8_t cfg;
phonemacro 0:252077cb2ac5 68 DigitalOut rLED(LED1, LED_OFF);
phonemacro 0:252077cb2ac5 69 DigitalOut gLED(LED2, LED_OFF);
phonemacro 0:252077cb2ac5 70 DigitalOut bLED(LED3, LED_OFF);
phonemacro 0:252077cb2ac5 71 gLED = LED_ON;
phonemacro 5:af38bfffd6d3 72 printf("DS1775 DS75 Digital Thermometer and "
phonemacro 5:af38bfffd6d3 73 "Thermostat example source code.\r\n");
phonemacro 0:252077cb2ac5 74 printf("\r\n");
phonemacro 0:252077cb2ac5 75
phonemacro 1:72ad3ee71812 76 DS1775 temp_sensor(i2cBus, DS1775_I2C_SLAVE_ADR_R0);
phonemacro 0:252077cb2ac5 77 i2cBus.frequency(400000);
phonemacro 2:aa39032bf778 78 /* Configure for 9 bit resolution, fault filter 1,
phonemacro 2:aa39032bf778 79 active low, comparator, continuous,
phonemacro 0:252077cb2ac5 80 */
phonemacro 11:505d7cf8587a 81 temp_sensor.write_cfg_reg(uint8_t(DS1775_CFG_RESOLUTION_9BIT |
phonemacro 2:aa39032bf778 82 DS1775_CFG_FAULT_FILTER_6 | DS1775_CFG_OS_POLARITY_ACT_LOW |
phonemacro 2:aa39032bf778 83 DS1775_CFG_COMPARATOR_MODE | DS1775_CFG_CONTINUOUS));
phonemacro 0:252077cb2ac5 84 for (i = 0; i < 10; i++) {
phonemacro 1:72ad3ee71812 85 wait(DS1775_WAIT_CONV_TIME_9BIT);
phonemacro 5:af38bfffd6d3 86 temperature =
phonemacro 5:af38bfffd6d3 87 temp_sensor.read_reg_as_temperature(DS1775_REG_TEMPERATURE);
phonemacro 0:252077cb2ac5 88 printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n",
phonemacro 0:252077cb2ac5 89 temperature, temp_sensor.celsius_to_fahrenheit(temperature));
phonemacro 0:252077cb2ac5 90 }
phonemacro 2:aa39032bf778 91 temp_sensor.read_cfg_reg(&cfg);
phonemacro 2:aa39032bf778 92 printf("Configuration Register = 0x%02Xh \r\n", cfg);
phonemacro 2:aa39032bf778 93
phonemacro 9:a22549dfaf5f 94 #if 0
phonemacro 14:8ca56fd6b35e 95 temp_sensor.write_trip_low_thyst(-63.9375);
phonemacro 5:af38bfffd6d3 96 temperature =
phonemacro 5:af38bfffd6d3 97 temp_sensor.read_reg_as_temperature(DS1775_REG_THYST_LOW_TRIP);
phonemacro 0:252077cb2ac5 98 printf("Thyst Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n",
phonemacro 0:252077cb2ac5 99 temperature, temp_sensor.celsius_to_fahrenheit(temperature));
phonemacro 0:252077cb2ac5 100
phonemacro 14:8ca56fd6b35e 101 temp_sensor.write_trip_high_tos(64.0625f);
phonemacro 1:72ad3ee71812 102 temperature = temp_sensor.read_reg_as_temperature(DS1775_REG_TOS_HIGH_TRIP);
phonemacro 0:252077cb2ac5 103 printf("TOS Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n",
phonemacro 0:252077cb2ac5 104 temperature, temp_sensor.celsius_to_fahrenheit(temperature));
phonemacro 0:252077cb2ac5 105 printf("\r\n\r\n");
phonemacro 0:252077cb2ac5 106 #endif
phonemacro 0:252077cb2ac5 107
phonemacro 0:252077cb2ac5 108 printf("\r\n");
phonemacro 0:252077cb2ac5 109
phonemacro 2:aa39032bf778 110 for (i = 0; i < 8; i++) {
phonemacro 17:7de7da8c21c3 111 temp_sensor.write_cfg_reg(uint8_t(DS1775_CFG_RESOLUTION_12BIT |
phonemacro 17:7de7da8c21c3 112 DS1775_CFG_FAULT_FILTER_6 | DS1775_CFG_OS_POLARITY_ACT_LOW |
phonemacro 17:7de7da8c21c3 113 DS1775_CFG_INTERRUPT_MODE | DS1775_CFG_SHUTDOWN));
phonemacro 17:7de7da8c21c3 114 wait(5); /* leave it in shutdown mode for a while */
phonemacro 16:1ebf8a6248be 115 /* Configure for 12 bit resolution, fault filter 6,
phonemacro 2:aa39032bf778 116 active low, interrupt, continous,
phonemacro 2:aa39032bf778 117 */
phonemacro 11:505d7cf8587a 118 temp_sensor.write_cfg_reg(uint8_t(DS1775_CFG_RESOLUTION_12BIT |
phonemacro 2:aa39032bf778 119 DS1775_CFG_FAULT_FILTER_6 | DS1775_CFG_OS_POLARITY_ACT_LOW |
phonemacro 2:aa39032bf778 120 DS1775_CFG_INTERRUPT_MODE | DS1775_CFG_CONTINUOUS));
phonemacro 2:aa39032bf778 121 wait(DS1775_WAIT_CONV_TIME_9BIT);
phonemacro 5:af38bfffd6d3 122 temperature =
phonemacro 5:af38bfffd6d3 123 temp_sensor.read_reg_as_temperature(DS1775_REG_TEMPERATURE);
phonemacro 0:252077cb2ac5 124 printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n",
phonemacro 0:252077cb2ac5 125 temperature, temp_sensor.celsius_to_fahrenheit(temperature));
phonemacro 0:252077cb2ac5 126 }
phonemacro 17:7de7da8c21c3 127 temp_sensor.write_cfg_reg(uint8_t(DS1775_CFG_RESOLUTION_12BIT |
phonemacro 17:7de7da8c21c3 128 DS1775_CFG_FAULT_FILTER_6 | DS1775_CFG_OS_POLARITY_ACT_LOW |
phonemacro 17:7de7da8c21c3 129 DS1775_CFG_INTERRUPT_MODE | DS1775_CFG_SHUTDOWN));
phonemacro 2:aa39032bf778 130 temp_sensor.read_cfg_reg(&cfg);
phonemacro 2:aa39032bf778 131 printf("Configuration Register = 0x%02Xh \r\n", cfg);
phonemacro 0:252077cb2ac5 132
phonemacro 0:252077cb2ac5 133 printf("\r\n\r\n");
phonemacro 0:252077cb2ac5 134
phonemacro 9:a22549dfaf5f 135 #if 0
phonemacro 14:8ca56fd6b35e 136 temp_sensor.write_trip_low_thyst(-55.0f);
phonemacro 5:af38bfffd6d3 137 temperature =
phonemacro 5:af38bfffd6d3 138 temp_sensor.read_reg_as_temperature(DS1775_REG_THYST_LOW_TRIP);
phonemacro 0:252077cb2ac5 139 printf("Thyst Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n",
phonemacro 0:252077cb2ac5 140 temperature, temp_sensor.celsius_to_fahrenheit(temperature));
phonemacro 0:252077cb2ac5 141
phonemacro 14:8ca56fd6b35e 142 temp_sensor.write_trip_high_tos(125.0f);
phonemacro 1:72ad3ee71812 143 temperature = temp_sensor.read_reg_as_temperature(DS1775_REG_TOS_HIGH_TRIP);
phonemacro 0:252077cb2ac5 144 printf("TOS Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n",
phonemacro 0:252077cb2ac5 145 temperature, temp_sensor.celsius_to_fahrenheit(temperature));
phonemacro 0:252077cb2ac5 146 printf("\r\n\r\n");
phonemacro 0:252077cb2ac5 147 #endif
phonemacro 5:af38bfffd6d3 148
phonemacro 0:252077cb2ac5 149 /***************************************************************************
phonemacro 0:252077cb2ac5 150 * Call the C code version of the driver
phonemacro 0:252077cb2ac5 151 ***************************************************************************
phonemacro 0:252077cb2ac5 152 */
phonemacro 1:72ad3ee71812 153 #include "ds1775_c.h"
phonemacro 0:252077cb2ac5 154 printf("C implementation of the code\r\n");
phonemacro 1:72ad3ee71812 155 ds1775_init(DS1775_I2C_SLAVE_ADR_R0);
phonemacro 4:d3171636a86b 156 /* Configure for 9 bit resolution, fault filter 1,
phonemacro 4:d3171636a86b 157 active low, comparator, continuous,
phonemacro 0:252077cb2ac5 158 */
phonemacro 4:d3171636a86b 159 ds1775_write_cfg_reg(uint8_t(DS1775_CFG_RESOLUTION_9BIT |
phonemacro 4:d3171636a86b 160 DS1775_CFG_FAULT_FILTER_6 | DS1775_CFG_OS_POLARITY_ACT_LOW |
phonemacro 4:d3171636a86b 161 DS1775_CFG_COMPARATOR_MODE | DS1775_CFG_CONTINUOUS), i2cBus);
phonemacro 0:252077cb2ac5 162 for (i = 0; i < 10; i++) {
phonemacro 4:d3171636a86b 163 wait(DS1775_WAIT_CONV_TIME_9BIT);
phonemacro 1:72ad3ee71812 164 temperature = ds1775_read_reg_as_temperature(DS1775_REG_TEMPERATURE,
phonemacro 0:252077cb2ac5 165 i2cBus);
phonemacro 0:252077cb2ac5 166 printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n",
phonemacro 0:252077cb2ac5 167 temperature, temp_sensor.celsius_to_fahrenheit(temperature));
phonemacro 0:252077cb2ac5 168 }
phonemacro 4:d3171636a86b 169
phonemacro 4:d3171636a86b 170 ds1775_read_cfg_reg(&cfg, i2cBus);
phonemacro 5:af38bfffd6d3 171 printf("Configuration Register = 0x%02Xh \r\n", cfg);
phonemacro 0:252077cb2ac5 172
phonemacro 9:a22549dfaf5f 173 #if 0
phonemacro 14:8ca56fd6b35e 174 ds1775_write_trip_low_thyst(-63.9375, i2cBus);
phonemacro 5:af38bfffd6d3 175 temperature = ds1775_read_reg_as_temperature(DS1775_REG_THYST_LOW_TRIP,
phonemacro 5:af38bfffd6d3 176 i2cBus);
phonemacro 0:252077cb2ac5 177 printf("Thyst Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n",
phonemacro 1:72ad3ee71812 178 temperature, ds1775_celsius_to_fahrenheit(temperature));
phonemacro 0:252077cb2ac5 179
phonemacro 14:8ca56fd6b35e 180 ds1775_write_trip_high_tos(64.0625f, i2cBus);
phonemacro 5:af38bfffd6d3 181 temperature = ds1775_read_reg_as_temperature(DS1775_REG_TOS_HIGH_TRIP,
phonemacro 5:af38bfffd6d3 182 i2cBus);
phonemacro 0:252077cb2ac5 183 printf("TOS Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n",
phonemacro 1:72ad3ee71812 184 temperature, ds1775_celsius_to_fahrenheit(temperature));
phonemacro 0:252077cb2ac5 185 #endif
phonemacro 0:252077cb2ac5 186
phonemacro 0:252077cb2ac5 187 printf("\r\n");
phonemacro 5:af38bfffd6d3 188 for (i = 0; i < 8; i++) {
phonemacro 17:7de7da8c21c3 189 ds1775_write_cfg_reg(uint8_t(DS1775_CFG_RESOLUTION_12BIT |
phonemacro 17:7de7da8c21c3 190 DS1775_CFG_FAULT_FILTER_6 | DS1775_CFG_OS_POLARITY_ACT_LOW |
phonemacro 17:7de7da8c21c3 191 DS1775_CFG_INTERRUPT_MODE | DS1775_CFG_SHUTDOWN), i2cBus);
phonemacro 17:7de7da8c21c3 192 wait(5); /* leave it in shutdown mode for a while */
phonemacro 16:1ebf8a6248be 193 /* Configure for 12 bit resolution, fault filter 6,
phonemacro 5:af38bfffd6d3 194 active low, interrupt, continous,
phonemacro 5:af38bfffd6d3 195 */
phonemacro 5:af38bfffd6d3 196 ds1775_write_cfg_reg(uint8_t(DS1775_CFG_RESOLUTION_12BIT |
phonemacro 5:af38bfffd6d3 197 DS1775_CFG_FAULT_FILTER_6 | DS1775_CFG_OS_POLARITY_ACT_LOW |
phonemacro 5:af38bfffd6d3 198 DS1775_CFG_INTERRUPT_MODE | DS1775_CFG_CONTINUOUS),
phonemacro 0:252077cb2ac5 199 i2cBus);
phonemacro 5:af38bfffd6d3 200 wait(DS1775_WAIT_CONV_TIME_9BIT);
phonemacro 1:72ad3ee71812 201 temperature = ds1775_read_reg_as_temperature(DS1775_REG_TEMPERATURE,
phonemacro 0:252077cb2ac5 202 i2cBus);
phonemacro 0:252077cb2ac5 203 printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n",
phonemacro 0:252077cb2ac5 204 temperature, temp_sensor.celsius_to_fahrenheit(temperature));
phonemacro 0:252077cb2ac5 205 }
phonemacro 17:7de7da8c21c3 206 ds1775_write_cfg_reg(uint8_t(DS1775_CFG_RESOLUTION_12BIT |
phonemacro 17:7de7da8c21c3 207 DS1775_CFG_FAULT_FILTER_6 | DS1775_CFG_OS_POLARITY_ACT_LOW |
phonemacro 17:7de7da8c21c3 208 DS1775_CFG_INTERRUPT_MODE | DS1775_CFG_SHUTDOWN), i2cBus);
phonemacro 5:af38bfffd6d3 209 ds1775_read_cfg_reg(&cfg, i2cBus);
phonemacro 5:af38bfffd6d3 210 printf("Configuration Register = 0x%02Xh \r\n", cfg);
phonemacro 0:252077cb2ac5 211
phonemacro 9:a22549dfaf5f 212 #if 0
phonemacro 14:8ca56fd6b35e 213 ds1775_write_trip_low_thyst(-55, i2cBus);
phonemacro 5:af38bfffd6d3 214 temperature = ds1775_read_reg_as_temperature(DS1775_REG_THYST_LOW_TRIP,
phonemacro 5:af38bfffd6d3 215 i2cBus);
phonemacro 0:252077cb2ac5 216 printf("Thyst Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n",
phonemacro 1:72ad3ee71812 217 temperature, ds1775_celsius_to_fahrenheit(temperature));
phonemacro 0:252077cb2ac5 218
phonemacro 14:8ca56fd6b35e 219 ds1775_write_trip_high_tos(125.0f, i2cBus);
phonemacro 5:af38bfffd6d3 220 temperature = ds1775_read_reg_as_temperature(DS1775_REG_TOS_HIGH_TRIP,
phonemacro 5:af38bfffd6d3 221 i2cBus);
phonemacro 0:252077cb2ac5 222 printf("TOS Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n",
phonemacro 1:72ad3ee71812 223 temperature, ds1775_celsius_to_fahrenheit(temperature));
phonemacro 0:252077cb2ac5 224 #endif
phonemacro 0:252077cb2ac5 225 printf("\r\n\r\n\r\n");
phonemacro 0:252077cb2ac5 226
phonemacro 0:252077cb2ac5 227
phonemacro 0:252077cb2ac5 228 while (true) { // Blink the green LED
phonemacro 0:252077cb2ac5 229 gLED = !gLED;
phonemacro 0:252077cb2ac5 230 wait(0.5);
phonemacro 0:252077cb2ac5 231 }
phonemacro 0:252077cb2ac5 232 }
phonemacro 0:252077cb2ac5 233
phonemacro 0:252077cb2ac5 234