NXP LM75A

The LM75A is a digital temperature sensor with an integrated thermal watchdog. The driver is implemented in source files lm75a.c/.h and provides communications support with the device over an I²C bus.

Device Information

Basic Usage

The code snippet below shows how to create and initialize an instance of the driver for the LM75A sensor.
#include "Drivers/NXP/lm75a.h"
#include <assert.h>

static I2C i2c;                         /* Allocate an I2C port for communicating with the device */
static LM75A driver;                    /* Allocate an instance of the driver */

void APP_Function(void)
{
    STATUS status;


    status = I2C_Open(&i2c,             /* Open the I2C port */
                      0,                /* Port number (0) */
                      400000);          /* Clock rate (400khz) */

    assert(status == SUCCESS);

    status = LM75A_Open(&driver,        /* Open the driver */
                        &i2c,           /* Provide the I2C port to be used by the driver */
                        0);             /* The bottom address value (A0-A2 on board) */

    assert(status == SUCCESS);
}
Once the driver has been initialized, values can be read from and written to the device. The code snippet below shows how to read the current temperature value from the device.
void APP_Function(void)
{
    STATUS status;
    float tempC;


    status = LM75A_ReadTemp(&driver, &tempC);       /* Read the current temperature */
    if (status == SUCCESS) {                        /* No errors? */

        printf("Temp = %.3f\n", tempC);             /* Print the temperature in celsius */
    }
}

API Reference

STATUS LM75A_Open(LM75A* driver, I2C* port, BYTE addr)
Creates and initializes a driver for the NXP LM75A digital temperature sensor.
PARAMETERS
driver A pointer to a caller allocated driver instance to be initialized.
port A pointer to an open I2C port to be used for communications.
addr The value of the external address pins (3 lower bits A0-A2).
RETURNS
SUCCESS The driver has been initialized and is ready for communications.
ERR_NULLREFERENCE The argument 'driver' or 'port' was found to be NULL.
STATUS LM75A_SetTimeout(LM75A* driver, UINT32 timeout)
Sets a new timeout value, in kernel ticks, to be used for I/O operations. The default is 1000 milliseconds.
PARAMETERS
driver A pointer to the driver to be updated.
timeout The new maximum amount of time, in kernel ticks, to block and wait for I/O operations to complete. Must be larger than zero and use 'INFINITE' to wait indefinitely.
RETURNS
SUCCESS The driver timeout value has been changed.
ERR_NULLREFERENCE The argument 'driver' was found to be NULL.
STATUS LM75A_Read(LM75A* driver, BYTE reg, void* buf, UINT32 nbytes)
Reads and returns register values from the device.
PARAMETERS
driver A pointer to the driver to be used.
reg The register address to be read. Valid registers are 0 thru 3.
buf A pointer to a caller allocated buffer to receive the returned values.
nbytes The number of bytes to be read from the device.
RETURNS
SUCCESS The values have been read and returned.
ERR_NULLREFERENCE The argument 'driver' or 'buf' was found to be NULL.
ERR_DEVICENAK The target device returned a NAK.
ERR_INCOMPLETE An error occurred while transferring the data and the transfer did not complete.
STATUS LM75A_Read16(LM75A* driver, BYTE reg, INT16* value)
Reads and returns a 16-bit value from the device.
PARAMETERS
driver A pointer to the driver to be used.
reg The register address to be read. Valid registers are 0 thru 3.
value A pointer to a caller allocated variable to receive the value.
RETURNS
SUCCESS The value has been read and returned.
ERR_NULLREFERENCE The argument 'driver' or 'value' was found to be NULL.
ERR_DEVICENAK The target device returned a NAK.
ERR_INCOMPLETE An error occurred while transferring the data and the transfer did not complete.
STATUS LM75A_Write(LM75A* driver, void* data, UINT32 nbytes)
Writes values to the registers within the device.
PARAMETERS
driver A pointer to the driver to be used.
data A pointer to the data to be written to the device. The first byte is the starting register address to be written.
nbytes The number of bytes to be written to the device.
RETURNS
SUCCESS The values have been written to the device.
ERR_NULLREFERENCE The argument 'driver' or 'data' was found to be NULL.
ERR_DEVICENAK The target device returned a NAK.
ERR_INCOMPLETE An error occurred while transferring the data and the transfer did not complete.
STATUS LM75A_Write16(LM75A* driver, BYTE reg, UINT16 value)
Writes a 16-bit value to the device.
PARAMETERS
driver A pointer to the driver to be used.
reg The register address to be written. Valid registers are 0 thru 3.
value The value to be written to the specified register.
RETURNS
SUCCESS The value has been written.
ERR_NULLREFERENCE The argument 'driver' was found to be NULL.
ERR_DEVICENAK The target device returned a NAK.
ERR_INCOMPLETE An error occurred while transferring the data and the transfer did not complete.
STATUS LM75A_Configuration(LM75A* driver, BYTE* cfg)
Reads and returns the configuration value from within the device.
PARAMETERS
driver A pointer to the driver to be used.
cfg A pointer to a caller allocated variable to receive the configuration.
RETURNS
SUCCESS The configuration value has been returned.
ERR_NULLREFERENCE The argument 'driver' or 'cfg' was found to be NULL.
ERR_DEVICENAK The target device returned a NAK.
ERR_INCOMPLETE An error occurred while transferring the data and the transfer did not complete.
STATUS LM75A_SetConfiguration(LM75A* driver, BYTE cfg)
Sets a new configuration value within the device.
PARAMETERS
driver A pointer to the driver to be used.
cfg The new configuration value for the device.
RETURNS
SUCCESS The configuration value has been updated.
ERR_NULLREFERENCE The argument 'driver' was found to be NULL.
ERR_DEVICENAK The target device returned a NAK.
ERR_INCOMPLETE An error occurred while transferring the data and the transfer did not complete.
STATUS LM75A_Threshold(LM75A* driver, float* threshC)
Reads and returns the threshold level, in units of degrees celsius, within the device.
PARAMETERS
driver A pointer to the driver to be used.
threshC A pointer to a caller allocated variable to receive the threshold level.
RETURNS
SUCCESS The threshold level has been returned.
ERR_NULLREFERENCE The argument 'driver' or 'threshC' was found to be NULL.
ERR_DEVICENAK The target device returned a NAK.
ERR_INCOMPLETE An error occurred while transferring the data and the transfer did not complete.
STATUS LM75A_SetThreshold(LM75A* driver, float threshC)
Sets a new threshold level, in units of degrees celsius, within the device.
PARAMETERS
driver A pointer to the driver to be used.
threshC The new threshold level for the device.
RETURNS
SUCCESS The threshold level has been updated.
ERR_NULLREFERENCE The argument 'driver' was found to be NULL.
ERR_DEVICENAK The target device returned a NAK.
ERR_INCOMPLETE An error occurred while transferring the data and the transfer did not complete.
STATUS LM75A_Hysteresis(LM75A* driver, float* hystC)
Reads and returns the hysteresis value, in units of degrees celsius, within the device.
PARAMETERS
driver A pointer to the driver to be used.
hystC A pointer to a caller allocated variable to receive the hysteresis value.
RETURNS
SUCCESS The hysteresis value has been returned.
ERR_NULLREFERENCE The argument 'driver' or 'hystC' was found to be NULL.
ERR_DEVICENAK The target device returned a NAK.
ERR_INCOMPLETE An error occurred while transferring the data and the transfer did not complete.
STATUS LM75A_SetHysteresis(LM75A* driver, float hystC)
Sets a new hysteresis level, in units of degrees celsius, within the device.
PARAMETERS
driver A pointer to the driver to be used.
hystC The new hysteresis level for the device.
RETURNS
SUCCESS The hysteresis level has been updated.
ERR_NULLREFERENCE The argument 'driver' was found to be NULL.
ERR_DEVICENAK The target device returned a NAK.
ERR_INCOMPLETE An error occurred while transferring the data and the transfer did not complete.
STATUS LM75A_ReadTemp(LM75A* driver, float* tempC)
Reads and returns the most recent temperature reading from the device.
PARAMETERS
driver A pointer to the driver to be used.
tempC A pointer to a value to receive the temperature value, in degrees celsius.
RETURNS
SUCCESS The temperature value has been returned.
ERR_NULLREFERENCE The argument 'driver' or 'tempC' was found to be NULL.
ERR_DEVICENAK The target device returned a NAK.
ERR_INCOMPLETE An error occurred while transferring the data and the transfer did not complete.