C++ library, driver software code for the low-power small WLP package MAX31875 temperature sensor. Code supports one-shot, shut-down/standby, hysteresis, alarm limits.
Dependents: MAX31875_Temperature_Sensor_Small_Package
MAX31875 Class Reference
Extremely small low-power temperature sensor. More...
#include <max31875.h>
Data Structures | |
union | max31875_raw_data |
union data structure for byte word manipulations More... | |
Public Member Functions | |
MAX31875 (I2C &i2c_bus, uint8_t slaveAddress) | |
Constructor for MAX31875 Class. | |
~MAX31875 () | |
Default destructor for MAX31875 Class. | |
int | read_reg (uint16_t *value, char reg) |
Read register of device at slave address. | |
float | read_reg_as_temperature (uint8_t reg) |
Reads the temperature registers. | |
int | write_cfg (uint16_t cfg) |
Writes to the configuration register. | |
int | write_trip_low (float temperature) |
Writes to the THYST register. | |
int | write_trip_high (float temperature) |
Writes to the TOS register. | |
float | celsius_to_fahrenheit (float temp_c) |
Converts Celsius degrees to Fahrenheit. | |
Protected Member Functions | |
int | write_reg (uint16_t value, char reg) |
Write a value to a register. |
Detailed Description
Extremely small low-power temperature sensor.
- Version:
- 1.0000.0000
The MAX31875 is a small WLP package temperature sensor. It supports high, low triggers stored in EEPROM for hystersis or limit alarms using comparator or interrupt mode. The MAX31875 can operate in shutdown and one-shot mode for extremely low power applications. Tiny size of 0.84 x 0.84 x 0.35 mm. Accuracy is +-1.5°C from +10°C to +45°C (±0.5°C Typical), +-2.0°C from -10°C to +100°C (±0.6°C Typical), +-3.0°C from -20°C to +125°C (±1.0°C Typical), I2C data rate of up to 1 MHz.
#include "mbed.h" #include "max32630fthr.h" #include "max31875.h" #include "USBSerial.h" MAX32630FTHR pegasus(MAX32630FTHR::VIO_1V8); I2C i2cBus(P3_4, P3_5); int main() { uint16_t raw; float temperature; DigitalOut rLED(LED1, LED_OFF); DigitalOut gLED(LED2, LED_OFF); DigitalOut bLED(LED3, LED_OFF); gLED = LED_ON; MAX31875 temp_sensor(i2cBus, MAX31875_I2C_SLAVE_ADR_R0); i2cBus.frequency(1000000); temp_sensor.write_reg(uint16_t(MAX31875_CFG_CONV_RATE_8 | MAX31875_CFG_RESOLUTION_12BIT), MAX31875_REG_CONFIGURATION); wait(MAX31875_WAIT_CONV_RATE_8); temperature = temp_sensor.read_reg_as_temperature(MAX31875_REG_TEMPERATURE); printf("Temperature = %3.4f Celsius, %3.4f Fahrenheit\r\n", temperature, temp_sensor.celsius_to_fahrenheit(temperature)); }
Definition at line 136 of file max31875.h.
Constructor & Destructor Documentation
MAX31875 | ( | I2C & | i2c_bus, |
uint8_t | slaveAddress | ||
) |
Constructor for MAX31875 Class.
Allows user to use existing I2C object
On Entry:
- Parameters:
-
[in] i2c_bus - pointer to existing I2C object [in] i2c_adrs - 7-bit slave address of MAX31875
On Exit:
- Returns:
- None
Definition at line 39 of file max31875.cpp.
~MAX31875 | ( | void | ) |
Default destructor for MAX31875 Class.
Destroys I2C object if owner
On Entry:
On Exit:
- Returns:
- None
empty block
Definition at line 49 of file max31875.cpp.
Member Function Documentation
float celsius_to_fahrenheit | ( | float | temp_c ) |
Converts Celsius degrees to Fahrenheit.
- Parameters:
-
temp_c - the temperature in Celsius degrees
- Returns:
- temperature in Celsius degrees
Definition at line 169 of file max31875.cpp.
int read_reg | ( | uint16_t * | value, |
char | reg | ||
) |
Read register of device at slave address.
- Parameters:
-
[out] value - Read data on success reg - Register address
- Returns:
- 0 on success, negative number on failure
Definition at line 56 of file max31875.cpp.
float read_reg_as_temperature | ( | uint8_t | reg ) |
Reads the temperature registers.
- Parameters:
-
reg - the address of the temperature register
- Returns:
- temprature in degrees Celsius
Definition at line 89 of file max31875.cpp.
int write_cfg | ( | uint16_t | cfg ) |
Writes to the configuration register.
- Parameters:
-
cfg - configurate word
- Returns:
- 0 on success, negative number on failure
Definition at line 139 of file max31875.cpp.
int write_reg | ( | uint16_t | value, |
char | reg | ||
) | [protected] |
Write a value to a register.
- Parameters:
-
value - value to write to the register reg - register address
- Returns:
- 0 on success, negative number on failure
Definition at line 110 of file max31875.cpp.
int write_trip_high | ( | float | temperature ) |
Writes to the TOS register.
- Parameters:
-
temperature - the temperature in Celsius degrees
- Returns:
- 0 on success, negative number on failure
Definition at line 157 of file max31875.cpp.
int write_trip_low | ( | float | temperature ) |
Writes to the THYST register.
- Parameters:
-
temperature - the temperature in Celsius degrees
- Returns:
- 0 on success, negative number on failure
Definition at line 145 of file max31875.cpp.
Generated on Wed Jul 13 2022 19:22:43 by 1.7.2