Sample main.c/cpp code for the Maxim Integrated MAX31725, MAX31726 high temperature sensor with accuracy of to +-0.5°C. Hosted on the MAX32630FTHR. Typical applications are for thermometers, thermostats, and high temperature alarm monitoring.
Dependencies: MAX31725_Accurate_Temperature_Sensor max32630fthr USBDevice
Revision 2:1890f1449f7c, committed 2019-04-10
- Comitter:
- phonemacro
- Date:
- Wed Apr 10 19:30:46 2019 +0000
- Parent:
- 1:5d32aeb8387e
- Commit message:
- updated waits for one-shots
Changed in this revision
MAX31725_Accurate_Temperature_Sensor.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 5d32aeb8387e -r 1890f1449f7c MAX31725_Accurate_Temperature_Sensor.lib --- a/MAX31725_Accurate_Temperature_Sensor.lib Tue Apr 09 22:58:23 2019 +0000 +++ b/MAX31725_Accurate_Temperature_Sensor.lib Wed Apr 10 19:30:46 2019 +0000 @@ -1,1 +1,1 @@ -https://os.mbed.com/users/phonemacro/code/MAX31725_Accurate_Temperature_Sensor/#692515ac2bb7 +https://os.mbed.com/users/phonemacro/code/MAX31725_Accurate_Temperature_Sensor/#3fa31b45fa1a
diff -r 5d32aeb8387e -r 1890f1449f7c main.cpp --- a/main.cpp Tue Apr 09 22:58:23 2019 +0000 +++ b/main.cpp Wed Apr 10 19:30:46 2019 +0000 @@ -35,7 +35,21 @@ #include "max31725.h" #include "max31725_cpp.h" #include "USBSerial.h" - + + Serial pc(USBTX, USBRX); // Use USB debug probe for serial link + Serial uart(P2_1, P2_0); +void wait_sec_prompt(uint8_t time) +{ + // Ports and serial connections + uint32_t i; + for (i = 0; i < time; i++) { + pc.printf("."); + wait(1); + } + pc.printf("\r\n"); +} + + MAX32630FTHR pegasus(MAX32630FTHR::VIO_3V3); DigitalOut rLED(LED1); @@ -69,9 +83,10 @@ DigitalOut gLED(LED2, LED_OFF); DigitalOut bLED(LED3, LED_OFF); gLED = LED_ON; - printf("MAX31725 Digital Thermometer and " + pc.baud(9600); // Baud rate = 115200 + pc.printf("MAX31725 Digital Thermometer and " "Thermostat example source code.\r\n"); - printf("\r\n"); + pc.printf("\r\n"); uint8_t i2c_addr = MAX31725_I2C_SLAVE_ADR_21; MAX31725 temp_sensor(i2cBus, i2c_addr); i2cBus.frequency(400000); @@ -86,28 +101,32 @@ wait(MAX31725_WAIT_CONV_TIME); temperature = temp_sensor.read_reg_as_temperature(MAX31725_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(MAX31725_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(MAX31725_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"); + temp_sensor.write_cfg_reg(uint8_t(MAX31725_CFG_ONE_SHOT_START | + MAX31725_CFG_TIMEOUT_DISABLE | MAX31725_CFG_EXTENDED_FORMAT | + MAX31725_CFG_FAULT_FILTER_4 | MAX31725_CFG_OS_POLARITY_ACT_LOW | + MAX31725_CFG_COMPARATOR_MODE | MAX31725_CFG_SHUTDOWN)); for (i = 0; i < 8; i++) { + wait_sec_prompt(10); /* leave it in shutdown mode for a while */ /* Configure for one shot, time out disabled, extended format, fault filter 4, active low polarity, comparator mode, shutdown */ @@ -118,27 +137,26 @@ wait(MAX31725_WAIT_CONV_TIME); temperature = temp_sensor.read_reg_as_temperature(MAX31725_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)); - wait(2); /* leave it in shutdown mode for a while */ } 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(MAX31725_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(MAX31725_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 /*************************************************************************** @@ -146,7 +164,7 @@ *************************************************************************** */ #include "max31725_c.h" - printf("C implementation of the code\r\n"); + pc.printf("C implementation of the code\r\n"); max31725_init(i2c_addr); /* Configure for time out enabled, normal format, fault filter 6, active low polarity, comparator mode, continuous @@ -162,29 +180,34 @@ wait(MAX31725_WAIT_CONV_TIME); temperature = max31725_read_reg_as_temperature(MAX31725_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)); } max31725_read_cfg_reg(&cfg, i2cBus); - printf("Configuration Register = 0x%02Xh \r\n", cfg); + pc.printf("Configuration Register = 0x%02Xh \r\n", cfg); #if 0 max31725_write_trip_low_thyst(-63.9375, i2cBus); temperature = max31725_read_reg_as_temperature(MAX31725_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, max31725_celsius_to_fahrenheit(temperature)); max31725_write_trip_high_tos(64.0625f, i2cBus); temperature = max31725_read_reg_as_temperature(MAX31725_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, max31725_celsius_to_fahrenheit(temperature)); #endif - printf("\r\n"); + pc.printf("\r\n"); + max31725_write_cfg_reg(uint8_t(MAX31725_CFG_ONE_SHOT_START | + MAX31725_CFG_TIMEOUT_DISABLE | MAX31725_CFG_EXTENDED_FORMAT | + MAX31725_CFG_FAULT_FILTER_4 | MAX31725_CFG_OS_POLARITY_ACT_LOW | + MAX31725_CFG_COMPARATOR_MODE | MAX31725_CFG_SHUTDOWN), i2cBus); for (i = 0; i < 8; i++) { + wait_sec_prompt(10); /* leave it in shutdown mode for a while */ /* Configure for one shot, time out disabled, extended format, fault filter 4, active low polarity, comparator mode, shutdown */ @@ -195,27 +218,26 @@ wait(MAX31725_WAIT_CONV_TIME); temperature = max31725_read_reg_as_temperature(MAX31725_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)); - wait(2); /* leave it in shutdown mode for a while */ } max31725_read_cfg_reg(&cfg, i2cBus); - printf("Configuration Register = 0x%02Xh \r\n", cfg); + pc.printf("Configuration Register = 0x%02Xh \r\n", cfg); #if 0 max31725_write_trip_low_thyst(-55, i2cBus); temperature = max31725_read_reg_as_temperature(MAX31725_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, max31725_celsius_to_fahrenheit(temperature)); max31725_write_trip_high_tos(125.0f, i2cBus); temperature = max31725_read_reg_as_temperature(MAX31725_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, max31725_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