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

Revision:
5:af38bfffd6d3
Parent:
4:d3171636a86b
Child:
8:2b1ab5937e95
--- a/main.cpp	Sun Apr 07 09:55:34 2019 +0000
+++ b/main.cpp	Sun Apr 07 11:01:25 2019 +0000
@@ -69,34 +69,33 @@
     DigitalOut gLED(LED2, LED_OFF);
     DigitalOut bLED(LED3, LED_OFF);
     gLED = LED_ON;
-    printf("DS1775 DS75 Digital Thermometer and Thermostat example source code.\r\n");
+    printf("DS1775 DS75 Digital Thermometer and "
+        "Thermostat example source code.\r\n");
     printf("\r\n");
 
     DS1775 temp_sensor(i2cBus, DS1775_I2C_SLAVE_ADR_R0);
     i2cBus.frequency(400000);
-  #if 0   
     /* Configure for 9 bit resolution, fault filter 1, 
        active low, comparator, continuous,
      */
-    temp_sensor.write_cfg(uint16_t(DS1775_CFG_RESOLUTION_9BIT |
+    temp_sensor.write_cfg(uint8_t(DS1775_CFG_RESOLUTION_9BIT |
         DS1775_CFG_FAULT_FILTER_6 | DS1775_CFG_OS_POLARITY_ACT_LOW |
         DS1775_CFG_COMPARATOR_MODE | DS1775_CFG_CONTINUOUS));
     for (i = 0; i < 10; i++) {
         wait(DS1775_WAIT_CONV_TIME_9BIT);
-        temperature = temp_sensor.read_reg_as_temperature(DS1775_REG_TEMPERATURE);
+        temperature =
+            temp_sensor.read_reg_as_temperature(DS1775_REG_TEMPERATURE);
         printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
             temperature, temp_sensor.celsius_to_fahrenheit(temperature));
     }
-    temperature = temp_sensor.read_reg_as_temperature(DS1775_REG_TOS_HIGH_TRIP);
-        printf("TOS 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);
     
 #if 0
     temp_sensor.write_trip_low(-63.9375);
     wait(0.03);
-    temperature = temp_sensor.read_reg_as_temperature(DS1775_REG_THYST_LOW_TRIP);
+    temperature =
+        temp_sensor.read_reg_as_temperature(DS1775_REG_THYST_LOW_TRIP);
     printf("Thyst Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
             temperature, temp_sensor.celsius_to_fahrenheit(temperature));
 
@@ -110,21 +109,19 @@
 
     printf("\r\n");
 
-
-    temp_sensor.read_cfg_reg(&cfg);
-    printf("Configuration Register = 0x%02Xh \r\n", cfg);
     for (i = 0; i < 8; i++) {
         /* Configure for 12 bit resolution, fault filter 2, 
            active low, interrupt, continous,
         */
-        temp_sensor.write_cfg(uint16_t(DS1775_CFG_RESOLUTION_12BIT |
+        temp_sensor.write_cfg(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);
-        temperature = temp_sensor.read_reg_as_temperature(DS1775_REG_TEMPERATURE);
+        temperature =
+            temp_sensor.read_reg_as_temperature(DS1775_REG_TEMPERATURE);
         printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
             temperature, temp_sensor.celsius_to_fahrenheit(temperature));
-        temp_sensor.write_cfg(uint16_t(DS1775_CFG_RESOLUTION_12BIT |
+        temp_sensor.write_cfg(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(2); /*  leave it in shutdown mode for a while */
@@ -134,11 +131,11 @@
 
     printf("\r\n\r\n");
 
-
 #if 0
     temp_sensor.write_trip_low(-55.0f);
     wait(0.03);
-    temperature = temp_sensor.read_reg_as_temperature(DS1775_REG_THYST_LOW_TRIP);
+    temperature = 
+        temp_sensor.read_reg_as_temperature(DS1775_REG_THYST_LOW_TRIP);
     printf("Thyst Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
             temperature, temp_sensor.celsius_to_fahrenheit(temperature));
 
@@ -149,7 +146,7 @@
             temperature, temp_sensor.celsius_to_fahrenheit(temperature));
     printf("\r\n\r\n");
 #endif
-  #endif
+
     /***************************************************************************
      * Call the C code version of the driver
      ***************************************************************************
@@ -172,54 +169,61 @@
     }
 
     ds1775_read_cfg_reg(&cfg, i2cBus);
-    printf("Configuration Register = 0x%04Xh \r\n", cfg);
-#if 0
+    printf("Configuration Register = 0x%02Xh \r\n", cfg);
 
 #if 0
     ds1775_write_trip_low(-63.9375, i2cBus);
     wait(0.03);
-    temperature = ds1775_read_reg_as_temperature(DS1775_REG_THYST_LOW_TRIP, i2cBus);
+    temperature = ds1775_read_reg_as_temperature(DS1775_REG_THYST_LOW_TRIP,
+        i2cBus);
     printf("Thyst Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
             temperature, ds1775_celsius_to_fahrenheit(temperature));
 
     ds1775_write_trip_high(64.0625f, i2cBus);
     wait(0.03);
-    temperature = ds1775_read_reg_as_temperature(DS1775_REG_TOS_HIGH_TRIP, i2cBus);
+    temperature = ds1775_read_reg_as_temperature(DS1775_REG_TOS_HIGH_TRIP,
+        i2cBus);
     printf("TOS Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
             temperature, ds1775_celsius_to_fahrenheit(temperature));
 #endif
 
     printf("\r\n");
-    for (i = 0; i < 2; i++) {
-        ds1775_write_cfg(uint16_t(DS1775_CFG_FAULT_FILTER_4 | 
-            DS1775_CFG_INTERRUPT_MODE | DS1775_CFG_SHUTDOWN |
-            DS1775_CFG_EXTENDED_FORMAT| DS1775_CFG_CONV_RATE_0_25 | 
-            DS1775_CFG_RESOLUTION_10BIT | DS1775_CFG_ONE_SHOT_START),
+    for (i = 0; i < 8; i++) {
+        /* Configure for 12 bit resolution, fault filter 2, 
+           active low, interrupt, continous,
+        */
+        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_CONTINUOUS),
             i2cBus);
-        wait(DS1775_WAIT_CONV_RATE_0_25);
+        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", 
             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);
+        wait(2); /*  leave it in shutdown mode for a while */
     }
-    ds1775_read_reg(&cfg, DS1775_REG_CONFIGURATION, i2cBus);
-    printf("Configuration Register = 0x%04Xh \r\n", cfg);
+    ds1775_read_cfg_reg(&cfg, i2cBus);
+    printf("Configuration Register = 0x%02Xh \r\n", cfg);
 
 #if 0
-    temp_sensor.write_trip_low(-127.9375);
-    ds1775_write_trip_low(-127.9375, i2cBus);
+    ds1775_write_trip_low(-55, i2cBus);
     wait(0.03);
-    temperature = ds1775_read_reg_as_temperature(DS1775_REG_THYST_LOW_TRIP, i2cBus);
+    temperature = ds1775_read_reg_as_temperature(DS1775_REG_THYST_LOW_TRIP,
+        i2cBus);
     printf("Thyst Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
             temperature, ds1775_celsius_to_fahrenheit(temperature));
 
-    ds1775_write_trip_high(129.0625f, i2cBus);
+    ds1775_write_trip_high(125.0f, i2cBus);
     wait(0.03);
-    temperature = ds1775_read_reg_as_temperature(DS1775_REG_TOS_HIGH_TRIP, i2cBus);
+    temperature = ds1775_read_reg_as_temperature(DS1775_REG_TOS_HIGH_TRIP,
+        i2cBus);
     printf("TOS Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", 
             temperature, ds1775_celsius_to_fahrenheit(temperature));
 #endif
-  #endif 
     printf("\r\n\r\n\r\n");