A feature complete driver for the LM75B temperature sensor from NXP.
Dependents:
app-board-TempAlarm
LM75B
IoTWorkshopSensors
EduRobot
... more
« Back to documentation index
LM75B Class Reference
LM75B class.
More...
#include <LM75B.h >
Public Types
enum Address {
ADDRESS_0 = (0x48 << 1),
ADDRESS_1 = (0x49 << 1),
ADDRESS_2 = (0x4A << 1),
ADDRESS_3 = (0x4B << 1),
ADDRESS_4 = (0x4C << 1),
ADDRESS_5 = (0x4D << 1),
ADDRESS_6 = (0x4E << 1),
ADDRESS_7 = (0x4F << 1)
}
Represents the different I2C address possibilities for the LM75B .
More...
enum PowerMode { POWER_NORMAL ,
POWER_SHUTDOWN
}
Represents the power mode of the LM75B .
More...
enum OSMode { OS_COMPARATOR ,
OS_INTERRUPT
}
Represents OS pin mode of the LM75B .
More...
enum OSPolarity { OS_ACTIVE_LOW ,
OS_ACTIVE_HIGH
}
Represents OS pin polarity of the LM75B .
More...
enum OSFaultQueue { OS_FAULT_QUEUE_1 ,
OS_FAULT_QUEUE_2 ,
OS_FAULT_QUEUE_4 ,
OS_FAULT_QUEUE_6
}
Represents OS pin fault queue length of the LM75B .
More...
Public Member Functions
LM75B (PinName sda, PinName scl, Address addr=ADDRESS_0, int hz=400000)
Create an LM75B object connected to the specified I2C pins with the specified I2C slave address.
bool open ()
Probe for the LM75B and indicate if it's present on the bus.
LM75B::PowerMode powerMode ()
Get the current power mode of the LM75B .
void powerMode (PowerMode mode)
Set the power mode of the LM75B .
LM75B::OSMode osMode ()
Get the current OS pin mode of the LM75B .
void osMode (OSMode mode)
Set the OS pin mode of the LM75B .
LM75B::OSPolarity osPolarity ()
Get the current OS pin polarity of the LM75B .
void osPolarity (OSPolarity polarity)
Set the OS pin polarity of the LM75B .
LM75B::OSFaultQueue osFaultQueue ()
Get the current OS pin fault queue length of the LM75B .
void osFaultQueue (OSFaultQueue queue)
Set the OS pin fault queue length of the LM75B .
float alertTemp ()
Get the current alert temperature threshold of the LM75B .
void alertTemp (float temp)
Set the alert temperature threshold of the LM75B .
float alertHyst ()
Get the current alert temperature hysteresis threshold of the LM75B .
void alertHyst (float temp)
Set the alert temperature hysteresis threshold of the LM75B .
float temp ()
Get the current temperature measurement of the LM75B .
operator float ()
A shorthand for temp()
Detailed Description
LM75B class.
Used for controlling an LM75B temperature sensor connected via I2C.
Example:
#include "mbed.h"
#include "LM75B.h"
LM75B sensor(p28, p27);
int main()
{
if (sensor.open()) {
printf("Device detected!\n" );
while (1) {
printf("Temp = %.3f\n" , (float )sensor);
wait(0.5);
}
} else {
error("Device not detected!\n" );
}
}
Definition at line 52 of file LM75B.h .
Member Enumeration Documentation
Represents the different I2C address possibilities for the LM75B .
Enumerator:
ADDRESS_0
A[2:0] pins = 000.
ADDRESS_1
A[2:0] pins = 001.
ADDRESS_2
A[2:0] pins = 010.
ADDRESS_3
A[2:0] pins = 011.
ADDRESS_4
A[2:0] pins = 100.
ADDRESS_5
A[2:0] pins = 101.
ADDRESS_6
A[2:0] pins = 110.
ADDRESS_7
A[2:0] pins = 111.
Definition at line 57 of file LM75B.h .
Represents OS pin fault queue length of the LM75B .
Enumerator:
OS_FAULT_QUEUE_1
OS is asserted after 1 fault.
OS_FAULT_QUEUE_2
OS is asserted after 2 consecutive faults.
OS_FAULT_QUEUE_4
OS is asserted after 4 consecutive faults.
OS_FAULT_QUEUE_6
OS is asserted after 6 consecutive faults.
Definition at line 91 of file LM75B.h .
Represents OS pin mode of the LM75B .
Enumerator:
OS_COMPARATOR
OS is asserted when the temperature reaches the alert threshold, and de-asserted when the temperature drops below the alert hysteresis threshold.
OS_INTERRUPT
OS is asserted when the temperature reaches the alert threshold, or drops below the alert hysteresis threshold, and only de-asserted when a register has been read.
Definition at line 77 of file LM75B.h .
Represents OS pin polarity of the LM75B .
Enumerator:
OS_ACTIVE_LOW
OS is a logic low when asserted, and a logic high when de-asserted.
OS_ACTIVE_HIGH
OS is a logic high when asserted, and a logic low when de-asserted.
Definition at line 84 of file LM75B.h .
Represents the power mode of the LM75B .
Enumerator:
POWER_NORMAL
Chip is enabled and samples every 100ms.
POWER_SHUTDOWN
Chip is in low-power shutdown mode.
Definition at line 70 of file LM75B.h .
Constructor & Destructor Documentation
LM75B
(
PinName
sda ,
PinName
scl ,
Address
addr = ADDRESS_0
,
int
hz = 400000
)
Create an LM75B object connected to the specified I2C pins with the specified I2C slave address.
Parameters:
sda The I2C data pin.
scl The I2C clock pin.
addr The I2C slave address (defaults to ADDRESS_0).
hz The I2C bus frequency (defaults to 400kHz).
Definition at line 19 of file LM75B.cpp .
Member Function Documentation
Get the current alert temperature hysteresis threshold of the LM75B .
Returns: The current alert temperature hysteresis threshold in °C.
Definition at line 166 of file LM75B.cpp .
void alertHyst
(
float
temp )
Set the alert temperature hysteresis threshold of the LM75B .
Parameters:
temp The new alert temperature hysteresis threshold in °C.
Definition at line 172 of file LM75B.cpp .
void alertTemp
(
float
temp )
Set the alert temperature threshold of the LM75B .
Parameters:
temp The new alert temperature threshold in °C.
Definition at line 160 of file LM75B.cpp .
Get the current alert temperature threshold of the LM75B .
Returns: The current alert temperature threshold in °C.
Definition at line 154 of file LM75B.cpp .
Probe for the LM75B and indicate if it's present on the bus.
Returns: 'true' if the device exists on the bus, 'false' if the device doesn't exist on the bus.
Definition at line 25 of file LM75B.cpp .
A shorthand for temp()
Returns: The current temperature measurement in °C.
Definition at line 195 of file LM75B.cpp .
Set the OS pin fault queue length of the LM75B .
Parameters:
queue The new OS pin fault queue length as an OSFaultQueue enum.
Definition at line 134 of file LM75B.cpp .
Get the current OS pin fault queue length of the LM75B .
Returns: The current OS pin fault queue length as an OSFaultQueue enum.
Definition at line 118 of file LM75B.cpp .
Get the current OS pin mode of the LM75B .
Returns: The current OS pin mode as an OSMode enum.
Definition at line 64 of file LM75B.cpp .
Set the OS pin mode of the LM75B .
Parameters:
mode The new OS pin mode as an OSMode enum.
Definition at line 76 of file LM75B.cpp .
Get the current OS pin polarity of the LM75B .
Returns: The current OS pin polarity as an OSPolarity enum.
Definition at line 91 of file LM75B.cpp .
Set the OS pin polarity of the LM75B .
Parameters:
polarity The new OS pin polarity as an OSPolarity enum.
Definition at line 103 of file LM75B.cpp .
Set the power mode of the LM75B .
Parameters:
mode The new power mode as a PowerMode enum.
Definition at line 49 of file LM75B.cpp .
Get the current power mode of the LM75B .
Returns: The current power mode as a PowerMode enum.
Definition at line 37 of file LM75B.cpp .
Get the current temperature measurement of the LM75B .
Returns: The current temperature measurement in °C.
Definition at line 178 of file LM75B.cpp .