TMP42x HAL Based Library 1.0.2
This library is a software library that works with the TMP42x remote and local temperature sensor with N-Factor and series-R correction. This library provides a convenient and efficient way to access the I2C interfaces of the chip, allowing developers to easily integrate this power meter into their systems.
Loading...
Searching...
No Matches
TMP42x.c File Reference
#include "TMP42x.h"

Go to the source code of this file.

Functions

TMP42x_Status __TMP42x_readByte (TMP42x *self, uint8_t MemAddress)
 Read a byte of data from TMP42x and stores in the tmp42x::_reg8::raw_data.
 
TMP42x_Status __TMP42x_writeByte (TMP42x *self, uint8_t MemAddress)
 Write a byte of data to TMP42x from the tmp42x::_reg8::raw_data.
 
TMP42x_Status __TMP42x_readTwoBytes (TMP42x *self, uint8_t MemAddress)
 Read two bytes of data from TMP42x and stores in the tmp42x::_reg16::raw_data.
 
TMP42x_Status TMP42x_init (TMP42x *self, TMP42x_Type type, I2C_HandleTypeDef *hi2c, uint8_t I2C_ADDR, TMP42x_Shutdown shutdown, TMP42x_Range range, TMP42x_ConversionRate conversion_rate, float n_eff1, float n_eff2, float n_eff3)
 Initialize the TMP42x with the given config.
 
double TMP42x_getRemoteTemp (TMP42x *self, uint8_t channel_number)
 Reads the full (floating-point) remote temperature from a specified channel.
 
int8_t TMP42x_getRemoteTemp_Int (TMP42x *self, uint8_t channel_number)
 Reads the integer part of the remote temperature from a specified channel.
 
double TMP42x_getLocalTemp (TMP42x *self)
 Reads the full (floating-point) local temperature from a specified channel.
 
int8_t TMP42x_getLocalTemp_Int (TMP42x *self)
 Reads the integer part of the local temperature.
 
TMP42x_Status TMP42x_oneShotStart (TMP42x *self)
 Starts a single conversion if the device is in shutdown mode.
 
TMP42x_Status TMP42x_softwareReset (TMP42x *self)
 Resets the device.
 
uint8_t TMP42x_getManID (TMP42x *self)
 Get the manufacturer ID.
 
uint8_t TMP42x_getDevID (TMP42x *self)
 Get the device ID.
 

Function Documentation

◆ __TMP42x_readByte()

TMP42x_Status __TMP42x_readByte ( TMP42x * self,
uint8_t MemAddress )

Read a byte of data from TMP42x and stores in the tmp42x::_reg8::raw_data.

Parameters
selfPointer to a TMP42x structure representing the sensor instance.
MemAddressAddress of the target register
Returns
The status of initialization
Return values
TMP42x_OKin case of success
TMP42x_TimeOutin case of failure

Definition at line 48 of file TMP42x.c.

◆ __TMP42x_readTwoBytes()

TMP42x_Status __TMP42x_readTwoBytes ( TMP42x * self,
uint8_t MemAddress )

Read two bytes of data from TMP42x and stores in the tmp42x::_reg16::raw_data.

Parameters
selfPointer to a TMP42x structure representing the sensor instance.
MemAddressAddress of the target register
Returns
The status of initialization
Return values
TMP42x_OKin case of success
TMP42x_TimeOutin case of failure

Definition at line 82 of file TMP42x.c.

◆ __TMP42x_writeByte()

TMP42x_Status __TMP42x_writeByte ( TMP42x * self,
uint8_t MemAddress )

Write a byte of data to TMP42x from the tmp42x::_reg8::raw_data.

Parameters
selfPointer to a TMP42x structure representing the sensor instance.
MemAddressAddress of the target register
Returns
The status of initialization
Return values
TMP42x_OKin case of success
TMP42x_TimeOutin case of failure

Definition at line 65 of file TMP42x.c.

◆ TMP42x_getDevID()

uint8_t TMP42x_getDevID ( TMP42x * self)

Get the device ID.

Parameters
selfPointer to a TMP42x structure representing the sensor instance.
Returns
a 8bit device ID

Definition at line 331 of file TMP42x.c.

◆ TMP42x_getLocalTemp()

double TMP42x_getLocalTemp ( TMP42x * self)

Reads the full (floating-point) local temperature from a specified channel.

This function retrieves the temperature (in degrees Celsius) from the TMP42x sensor series. The returned value includes both integer and fractional parts.

Parameters
selfPointer to a TMP42x structure representing the sensor instance.
Returns
Temperature value in degrees Celsius as a floating-point number if successful.

Definition at line 262 of file TMP42x.c.

◆ TMP42x_getLocalTemp_Int()

int8_t TMP42x_getLocalTemp_Int ( TMP42x * self)

Reads the integer part of the local temperature.

This function retrieves the temperature (in degrees Celsius) from the TMP42x sensor series. It only returns the integer part of the temperature.

Parameters
selfPointer to a TMP42x structure representing the sensor instance.
Returns
Temperature value (integer part only) in degrees Celsius if successful.

Definition at line 279 of file TMP42x.c.

◆ TMP42x_getManID()

uint8_t TMP42x_getManID ( TMP42x * self)

Get the manufacturer ID.

Parameters
selfPointer to a TMP42x structure representing the sensor instance.
Returns
a 8bit manufacturer ID

Definition at line 320 of file TMP42x.c.

◆ TMP42x_getRemoteTemp()

double TMP42x_getRemoteTemp ( TMP42x * self,
uint8_t channel_number )

Reads the full (floating-point) remote temperature from a specified channel.

This function retrieves the temperature (in degrees Celsius) from a specified remote channel of the TMP42x sensor series. The returned value includes both integer and fractional parts.

Parameters
selfPointer to a TMP42x structure representing the sensor instance.
channel_numberIndex of the remote channel to read from. Valid values are:
  • 1 : Channel 1
  • 2 : Channel 2 (only available on TMP422 or TMP423)
  • 3 : Channel 3 (only available on TMP423)
Returns
Temperature value in degrees Celsius as a floating-point number if successful.
Return values
-999Returned if the requested channel number does not exist for the device type.

Definition at line 217 of file TMP42x.c.

◆ TMP42x_getRemoteTemp_Int()

int8_t TMP42x_getRemoteTemp_Int ( TMP42x * self,
uint8_t channel_number )

Reads the integer part of the remote temperature from a specified channel.

This function retrieves the temperature (in degrees Celsius) from a specified remote channel of the TMP42x sensor series. It only returns the integer part of the temperature.

Parameters
selfPointer to a TMP42x structure representing the sensor instance.
channel_numberIndex of the remote channel to read from. Valid values are:
  • 1 : Channel 1
  • 2 : Channel 2 (only available on TMP422 or TMP423)
  • 3 : Channel 3 (only available on TMP423)
Returns
Temperature value (integer part only) in degrees Celsius if successful.
Return values
-128Returned if the requested channel number does not exist for the device type.

Definition at line 244 of file TMP42x.c.

◆ TMP42x_init()

TMP42x_Status TMP42x_init ( TMP42x * self,
TMP42x_Type type,
I2C_HandleTypeDef * hi2c,
uint8_t I2C_ADDR,
TMP42x_Shutdown shutdown,
TMP42x_Range range,
TMP42x_ConversionRate conversion_rate,
float n_eff1,
float n_eff2,
float n_eff3 )

Initialize the TMP42x with the given config.

Parameters
selfPointer to a TMP42x structure representing the sensor instance.
typeChip part number.
hi2cA pointer to the I2C handler that is connected to TMP42x
I2C_ADDRThe I2C address of the TMP42x. It depends on the state of A0 and A1 of the chip (TMP421), DXx pins status (TMP422), or the part number (TMP423)
shutdownOperating mode:
rangeTemperature range:
conversion_rateRate of the temperature conversion:
  • TMP42x_0_0625 0.0625 conversions per second (each 16 seconds)
  • TMP42x_0_125 0.125 conversions per second (each 8 seconds)
  • TMP42x_0_25 0.25 conversions per second (each 4 seconds)
  • TMP42x_0_5 0.5 conversions per second (each 1 seconds)
  • TMP42x_1 1 conversion per second (each second)
  • TMP42x_2 2 conversions per second (each 0.5 seconds)
  • TMP42x_4 4 conversions per second (each 0.25 seconds) NOTE: Conversion rate shown is for only one or two enabled measurement channels. When three channels are enabled, the conversion rate is 2 and 2/3 conversions-per-second. When four channels are enabled, the conversion rate is 2 per second.
  • TMP42x_8 8 conversions per second (each 0.125 seconds) NOTE: Conversion rate shown is for only one enabled measurement channel. When two channels are enabled, the conversion rate is 4 conversions-per-second. When three channels are enabled, the conversion rate is 2 and 2/3 conversions-per-second. When four channels are enabled, the conversion rate is 2 conversions-per-second.
n_eff1Effective n value for channel1. From 0.706542 to 1.747977.
n_eff2Effective n value for channel2 (TMP422 or TMP423). From 0.706542 to 1.747977.
n_eff3Effective n value for channel3 (TMP423). From 0.706542 to 1.747977.
Returns
The status of initialization
Return values
TMP42x_OKin case of success
TMP42x_TimeOutin case of failure

Definition at line 138 of file TMP42x.c.

◆ TMP42x_oneShotStart()

TMP42x_Status TMP42x_oneShotStart ( TMP42x * self)

Starts a single conversion if the device is in shutdown mode.

Parameters
selfPointer to a TMP42x structure representing the sensor instance.
Returns
The status of start
Return values
TMP42x_OKin case of success
TMP42x_TimeOutin case of failure

Definition at line 294 of file TMP42x.c.

◆ TMP42x_softwareReset()

TMP42x_Status TMP42x_softwareReset ( TMP42x * self)

Resets the device.

Parameters
selfPointer to a TMP42x structure representing the sensor instance.
Returns
The status of start
Return values
TMP42x_OKin case of success
TMP42x_TimeOutin case of failure

Definition at line 309 of file TMP42x.c.