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

Files at this revision

API Documentation at this revision

Comitter:
phonemacro
Date:
Thu Apr 11 21:50:18 2019 +0000
Parent:
17:7de7da8c21c3
Commit message:
Updated to blink the LED various colors during shutdown. Corrected the 12 bit conversion wait time.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 7de7da8c21c3 -r 0e25544cb810 main.cpp
--- a/main.cpp	Wed Apr 10 18:08:38 2019 +0000
+++ b/main.cpp	Thu Apr 11 21:50:18 2019 +0000
@@ -35,7 +35,7 @@
 #include "ds1775.h"
 #include "ds1775_cpp.h"
 #include "USBSerial.h"
- 
+
 MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); 
  
 DigitalOut rLED(LED1);
@@ -44,11 +44,41 @@
  
 I2C i2cBus(P3_4, P3_5);
 
+Serial pc(USBTX, USBRX);    /* Use USB debug probe for serial link */
+Serial uart(P2_1, P2_0);
+uint32_t blink_cnt;         /* counter for blinking the colors */       
+void wait_blink_colors(uint8_t dly) {
+    uint32_t i;
+    for (i = 0; i < dly; i++) {
+        wait(.5);
+        if (blink_cnt & 1)
+            gLED = !gLED;
+        if (blink_cnt & 2)
+            bLED = !bLED;
+        if (blink_cnt & 4)
+            rLED = !rLED;
+        blink_cnt++;
+            wait(.5);
+    }
+}
+
+void wait_sec_prompt(uint8_t time)
+{
+   // Ports and serial connections
+    uint32_t i;
+    for (i = 0; i < time; i++) {
+        pc.printf(".");
+        wait_blink_colors(1);
+    }
+    pc.printf("\r\n");
+}
+
+
 // main() runs in its own thread in the OS
 // (note the calls to Thread::wait below for delays)
 /**
 * @brief Sample main program for DS1775
-* @version 1.0000.0002
+* @version 1.0000.0003
 *
 * @details Sample main program for DS1775
 * The prints are sent to the terminal window (9600, 8n1).
@@ -65,13 +95,15 @@
     uint32_t i;
     float temperature;
     uint8_t cfg;
+    uint8_t delay = 30;  /* shutdown wait time */
     DigitalOut rLED(LED1, LED_OFF);
     DigitalOut gLED(LED2, LED_OFF);
     DigitalOut bLED(LED3, LED_OFF);
     gLED = LED_ON;
-    printf("DS1775 DS75 Digital Thermometer and "
+    pc.baud(9600);                    // Baud rate = 115200
+    pc.printf("DS1775 DS75 Digital Thermometer and "
         "Thermostat example source code.\r\n");
-    printf("\r\n");
+    pc.printf("\r\n");
 
     DS1775 temp_sensor(i2cBus, DS1775_I2C_SLAVE_ADR_R0);
     i2cBus.frequency(400000);
@@ -85,65 +117,65 @@
         wait(DS1775_WAIT_CONV_TIME_9BIT);
         temperature =
             temp_sensor.read_reg_as_temperature(DS1775_REG_TEMPERATURE);
-        printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
+        pc.printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
             temperature, temp_sensor.celsius_to_fahrenheit(temperature));
     }
     temp_sensor.read_cfg_reg(&cfg);
-    printf("Configuration Register = 0x%02Xh \r\n", cfg);
+    pc.printf("Configuration Register = 0x%02Xh \r\n", cfg);
     
 #if 0
     temp_sensor.write_trip_low_thyst(-63.9375);
     temperature =
         temp_sensor.read_reg_as_temperature(DS1775_REG_THYST_LOW_TRIP);
-    printf("Thyst Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
+    pc.printf("Thyst Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
             temperature, temp_sensor.celsius_to_fahrenheit(temperature));
 
     temp_sensor.write_trip_high_tos(64.0625f);
     temperature = temp_sensor.read_reg_as_temperature(DS1775_REG_TOS_HIGH_TRIP);
-    printf("TOS Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
+    pc.printf("TOS Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
             temperature, temp_sensor.celsius_to_fahrenheit(temperature));
-    printf("\r\n\r\n");
+    pc.printf("\r\n\r\n");
 #endif
 
-    printf("\r\n");
+    pc.printf("\r\n");
 
     for (i = 0; i < 8; i++) {
         temp_sensor.write_cfg_reg(uint8_t(DS1775_CFG_RESOLUTION_12BIT |
             DS1775_CFG_FAULT_FILTER_6 | DS1775_CFG_OS_POLARITY_ACT_LOW |
             DS1775_CFG_INTERRUPT_MODE | DS1775_CFG_SHUTDOWN));
-        wait(5); /*  leave it in shutdown mode for a while */
+        wait_sec_prompt(delay); /*  leave it in shutdown mode for a while */
         /* Configure for 12 bit resolution, fault filter 6, 
            active low, interrupt, continous,
         */
         temp_sensor.write_cfg_reg(uint8_t(DS1775_CFG_RESOLUTION_12BIT |
             DS1775_CFG_FAULT_FILTER_6 | DS1775_CFG_OS_POLARITY_ACT_LOW |
             DS1775_CFG_INTERRUPT_MODE | DS1775_CFG_CONTINUOUS));
-        wait(DS1775_WAIT_CONV_TIME_9BIT);
+        wait(DS1775_WAIT_CONV_TIME_12BIT);
         temperature =
             temp_sensor.read_reg_as_temperature(DS1775_REG_TEMPERATURE);
-        printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
+        pc.printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
             temperature, temp_sensor.celsius_to_fahrenheit(temperature));
     }
     temp_sensor.write_cfg_reg(uint8_t(DS1775_CFG_RESOLUTION_12BIT |
         DS1775_CFG_FAULT_FILTER_6 | DS1775_CFG_OS_POLARITY_ACT_LOW |
         DS1775_CFG_INTERRUPT_MODE | DS1775_CFG_SHUTDOWN));
     temp_sensor.read_cfg_reg(&cfg);
-    printf("Configuration Register = 0x%02Xh \r\n", cfg);
+    pc.printf("Configuration Register = 0x%02Xh \r\n", cfg);
 
-    printf("\r\n\r\n");
+    pc.printf("\r\n\r\n");
 
 #if 0
     temp_sensor.write_trip_low_thyst(-55.0f);
     temperature = 
         temp_sensor.read_reg_as_temperature(DS1775_REG_THYST_LOW_TRIP);
-    printf("Thyst Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
+    pc.printf("Thyst Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
             temperature, temp_sensor.celsius_to_fahrenheit(temperature));
 
     temp_sensor.write_trip_high_tos(125.0f);
     temperature = temp_sensor.read_reg_as_temperature(DS1775_REG_TOS_HIGH_TRIP);
-    printf("TOS Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
+    pc.printf("TOS Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
             temperature, temp_sensor.celsius_to_fahrenheit(temperature));
-    printf("\r\n\r\n");
+    pc.printf("\r\n\r\n");
 #endif
 
     /***************************************************************************
@@ -151,7 +183,7 @@
      ***************************************************************************
      */
 #include "ds1775_c.h"
-    printf("C implementation of the code\r\n");
+    pc.printf("C implementation of the code\r\n");
     ds1775_init(DS1775_I2C_SLAVE_ADR_R0);
     /* Configure for 9 bit resolution, fault filter 1, 
        active low, comparator, continuous,
@@ -163,33 +195,33 @@
         wait(DS1775_WAIT_CONV_TIME_9BIT);
         temperature = ds1775_read_reg_as_temperature(DS1775_REG_TEMPERATURE,
             i2cBus);
-        printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
+        pc.printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
             temperature, temp_sensor.celsius_to_fahrenheit(temperature));
     }
 
     ds1775_read_cfg_reg(&cfg, i2cBus);
-    printf("Configuration Register = 0x%02Xh \r\n", cfg);
+    pc.printf("Configuration Register = 0x%02Xh \r\n", cfg);
 
 #if 0
     ds1775_write_trip_low_thyst(-63.9375, i2cBus);
     temperature = ds1775_read_reg_as_temperature(DS1775_REG_THYST_LOW_TRIP,
         i2cBus);
-    printf("Thyst Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
+    pc.printf("Thyst Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
             temperature, ds1775_celsius_to_fahrenheit(temperature));
 
     ds1775_write_trip_high_tos(64.0625f, i2cBus);
     temperature = ds1775_read_reg_as_temperature(DS1775_REG_TOS_HIGH_TRIP,
         i2cBus);
-    printf("TOS Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
+    pc.printf("TOS Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
             temperature, ds1775_celsius_to_fahrenheit(temperature));
 #endif
 
-    printf("\r\n");
+    pc.printf("\r\n");
     for (i = 0; i < 8; i++) {
         ds1775_write_cfg_reg(uint8_t(DS1775_CFG_RESOLUTION_12BIT |
             DS1775_CFG_FAULT_FILTER_6 | DS1775_CFG_OS_POLARITY_ACT_LOW |
             DS1775_CFG_INTERRUPT_MODE | DS1775_CFG_SHUTDOWN), i2cBus);
-        wait(5); /*  leave it in shutdown mode for a while */
+        wait_sec_prompt(delay); /*  leave it in shutdown mode for a while */
         /* Configure for 12 bit resolution, fault filter 6, 
            active low, interrupt, continous,
         */
@@ -197,32 +229,32 @@
             DS1775_CFG_FAULT_FILTER_6 | DS1775_CFG_OS_POLARITY_ACT_LOW |
             DS1775_CFG_INTERRUPT_MODE | DS1775_CFG_CONTINUOUS),
             i2cBus);
-        wait(DS1775_WAIT_CONV_TIME_9BIT);
+        wait(DS1775_WAIT_CONV_TIME_12BIT);
         temperature = ds1775_read_reg_as_temperature(DS1775_REG_TEMPERATURE,
             i2cBus);
-        printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
+        pc.printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
             temperature, temp_sensor.celsius_to_fahrenheit(temperature));
     }
     ds1775_write_cfg_reg(uint8_t(DS1775_CFG_RESOLUTION_12BIT |
         DS1775_CFG_FAULT_FILTER_6 | DS1775_CFG_OS_POLARITY_ACT_LOW |
         DS1775_CFG_INTERRUPT_MODE | DS1775_CFG_SHUTDOWN), i2cBus);
     ds1775_read_cfg_reg(&cfg, i2cBus);
-    printf("Configuration Register = 0x%02Xh \r\n", cfg);
+    pc.printf("Configuration Register = 0x%02Xh \r\n", cfg);
 
 #if 0
     ds1775_write_trip_low_thyst(-55, i2cBus);
     temperature = ds1775_read_reg_as_temperature(DS1775_REG_THYST_LOW_TRIP,
         i2cBus);
-    printf("Thyst Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
+    pc.printf("Thyst Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
             temperature, ds1775_celsius_to_fahrenheit(temperature));
 
     ds1775_write_trip_high_tos(125.0f, i2cBus);
     temperature = ds1775_read_reg_as_temperature(DS1775_REG_TOS_HIGH_TRIP,
         i2cBus);
-    printf("TOS Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
+    pc.printf("TOS Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
             temperature, ds1775_celsius_to_fahrenheit(temperature));
 #endif
-    printf("\r\n\r\n\r\n");
+    pc.printf("\r\n\r\n\r\n");
 
 
     while (true) {  // Blink the green LED