Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: MAX31723_Thermostat_Thermometer_Sensor
Diff: max31723.cpp
- Revision:
- 3:f39791139435
- Parent:
- 2:7a20e65da621
- Child:
- 4:ac75d4d62471
--- a/max31723.cpp Sun Jan 27 07:26:37 2019 +0000
+++ b/max31723.cpp Mon Jan 28 00:39:50 2019 +0000
@@ -31,6 +31,14 @@
*******************************************************************************
*/
#include "max31723.h"
+
+union max31723_raw_data {
+ struct {
+ uint8_t lsb;
+ uint8_t msb;
+ };
+ uint16_t wrd;
+};
MAX31723::MAX31723(SPI &spi, DigitalOut &ce_pin) : m_spi(spi), m_chip_enable(ce_pin)
{
@@ -55,11 +63,11 @@
return MAX31723_NO_ERROR;
}
-int MAX31723::perform_one_shot_int(uint8_t resolution)
+int MAX31723::perform_one_shot(uint8_t resolution, uint8_t interrupt_mode)
{
if (resolution <= MAX31723_CFG_RESOLUTION_12BIT) {
write_reg(0, MAX31723_REG_CFG | MAX31723_WRITE_MASK);
- write_reg(MAX31723_CFG_TM_MODE_INTERRUPT | MAX31723_CFG_1SHOT |
+ write_reg(interrupt_mode | MAX31723_CFG_1SHOT |
resolution | MAX31723_CFG_STANDBY,
MAX31723_REG_CFG | MAX31723_WRITE_MASK);
} else
@@ -67,20 +75,43 @@
return MAX31723_NO_ERROR;
}
-float MAX31723::read_temp()
+int MAX31723::perform_one_shot_int(uint8_t resolution)
{
- uint8_t lsb, msb;
- uint16_t raw_temp;
- float temperature;
- wait(0.2);
- read_reg(lsb, MAX31723_REG_TEMP_LSB);
- read_reg(msb, MAX31723_REG_TEMP_MSB);
- raw_temp = int16_t((msb << 8) | (lsb));
- raw_temp = raw_temp >> 4;
- temperature = raw_temp * 0.0625 ;
- return temperature;
+ int ret;
+ ret = perform_one_shot(resolution, MAX31723_CFG_TM_MODE_INTERRUPT);
+ return ret;
+}
+
+int MAX31723::perform_one_shot_comparator(uint8_t resolution)
+{
+ int ret;
+ ret = perform_one_shot(resolution, 0);
+ return ret;
}
+uint8_t MAX31723::read_cfg()
+{
+ uint8_t cfg;
+ read_reg(cfg, MAX31723_REG_CFG);
+ return cfg;
+}
+
+float MAX31723::read_reg_as_temperature(uint8_t reg)
+{
+ max31723_raw_data raw;
+ float temperature;
+ if (reg >= MAX31723_REG_TEMP_LSB && reg <= MAX31723_REG_MAX) {
+ read_reg(raw.lsb, reg);
+ read_reg(raw.msb, reg+1);
+ raw.wrd = raw.wrd >> MAX31723_UNUSED_BITS;
+ temperature = raw.wrd * MAX31723_CF_LSB;
+ return temperature;
+ } else {
+ printf("Input read_registers_as_temperature is invalid, %d r\n",
+ reg);
+ return 0;
+ }
+}
float MAX31723::celsius_to_fahrenheit(float temp_c)
{