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.h File Reference
#include "main.h"
#include "i2c.h"

Go to the source code of this file.

Data Structures

struct  tmp42x
 Class (struct) that stores variables for interacting with TMP42x. More...
 
union  tmp42x::_reg16
 
struct  tmp42x::_reg16::_temp_register
 
union  tmp42x::_reg8
 
struct  tmp42x::_reg8::_status_register
 
struct  tmp42x::_reg8::_temp_int_register
 
struct  tmp42x::_reg8::_temp_frac_register
 
struct  tmp42x::_reg8::_config1_register
 
struct  tmp42x::_reg8::_config2_register
 
struct  tmp42x::_reg8::_conversion_rate_register
 
struct  tmp42x::_reg8::_n_correction_register
 
struct  tmp42x::_reg8::_man_id_register
 
struct  tmp42x::_reg8::_dev_id_register
 

Macros

#define LOCAL_TEMP_MSB   0x00
 
#define REMOTE1_TEMP_MSB   0x01
 
#define REMOTE2_TEMP_MSB   0x02
 
#define REMOTE3_TEMP_MSB   0x03
 
#define STATUS_REGISTER   0x08
 
#define CONFIG1_REGISTER   0x09
 
#define CONFIG2_REGISTER   0x0A
 
#define CONVERSION_RATE_REGISTER   0x0B
 
#define ONE_SHOT_START_REGISTER   0x0F
 
#define LOCAL_TEMP_LSB   0x10
 
#define REMOTE1_TEMP_LSB   0x11
 
#define REMOTE2_TEMP_LSB   0x12
 
#define REMOTE3_TEMP_LSB   0x13
 
#define nCORRECTION1_REGISTER   0x21
 
#define nCORRECTION2_REGISTER   0x22
 
#define nCORRECTION3_REGISTER   0x23
 
#define SOFTWARE_RESET_REGISTER   0xFC
 
#define MAN_ID_REGISTER   0xFE
 
#define DEVICE_ID_REGISTER   0xFF
 

Typedefs

typedef enum TMP42x_Type TMP42x_Type
 
typedef enum TMP42x_Status TMP42x_Status
 
typedef enum TMP42x_Range TMP42x_Range
 
typedef enum TMP42x_Shutdown TMP42x_Shutdown
 
typedef enum TMP42x_ConversionRate TMP42x_ConversionRate
 
typedef struct tmp42x TMP42x
 Class (struct) that stores variables for interacting with TMP42x.
 

Enumerations

enum  TMP42x_Type { TMP421 , TMP422 , TMP423 }
 
enum  TMP42x_Status { TMP42x_OK , TMP42x_TimeOut , TMP42x_Arg_Error }
 
enum  TMP42x_Range { TMP42x_Normal , TMP42x_Extended }
 
enum  TMP42x_Shutdown { TMP42x_Run , TMP42x_ShutDown }
 
enum  TMP42x_ConversionRate {
  TMP42x_0_0625 , TMP42x_0_125 , TMP42x_0_25 , TMP42x_0_5 ,
  TMP42x_1 , TMP42x_2 , TMP42x_4 , TMP42x_8
}
 

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_readTwoBytes (TMP42x *self, uint8_t MemAddress)
 Read two bytes of data from TMP42x and stores in the tmp42x::_reg16::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_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_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.
 
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.
 
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.
 

Macro Definition Documentation

◆ CONFIG1_REGISTER

#define CONFIG1_REGISTER   0x09

Definition at line 44 of file TMP42x.h.

◆ CONFIG2_REGISTER

#define CONFIG2_REGISTER   0x0A

Definition at line 45 of file TMP42x.h.

◆ CONVERSION_RATE_REGISTER

#define CONVERSION_RATE_REGISTER   0x0B

Definition at line 46 of file TMP42x.h.

◆ DEVICE_ID_REGISTER

#define DEVICE_ID_REGISTER   0xFF

Definition at line 57 of file TMP42x.h.

◆ LOCAL_TEMP_LSB

#define LOCAL_TEMP_LSB   0x10

Definition at line 48 of file TMP42x.h.

◆ LOCAL_TEMP_MSB

#define LOCAL_TEMP_MSB   0x00

Definition at line 39 of file TMP42x.h.

◆ MAN_ID_REGISTER

#define MAN_ID_REGISTER   0xFE

Definition at line 56 of file TMP42x.h.

◆ nCORRECTION1_REGISTER

#define nCORRECTION1_REGISTER   0x21

Definition at line 52 of file TMP42x.h.

◆ nCORRECTION2_REGISTER

#define nCORRECTION2_REGISTER   0x22

Definition at line 53 of file TMP42x.h.

◆ nCORRECTION3_REGISTER

#define nCORRECTION3_REGISTER   0x23

Definition at line 54 of file TMP42x.h.

◆ ONE_SHOT_START_REGISTER

#define ONE_SHOT_START_REGISTER   0x0F

Definition at line 47 of file TMP42x.h.

◆ REMOTE1_TEMP_LSB

#define REMOTE1_TEMP_LSB   0x11

Definition at line 49 of file TMP42x.h.

◆ REMOTE1_TEMP_MSB

#define REMOTE1_TEMP_MSB   0x01

Definition at line 40 of file TMP42x.h.

◆ REMOTE2_TEMP_LSB

#define REMOTE2_TEMP_LSB   0x12

Definition at line 50 of file TMP42x.h.

◆ REMOTE2_TEMP_MSB

#define REMOTE2_TEMP_MSB   0x02

Definition at line 41 of file TMP42x.h.

◆ REMOTE3_TEMP_LSB

#define REMOTE3_TEMP_LSB   0x13

Definition at line 51 of file TMP42x.h.

◆ REMOTE3_TEMP_MSB

#define REMOTE3_TEMP_MSB   0x03

Definition at line 42 of file TMP42x.h.

◆ SOFTWARE_RESET_REGISTER

#define SOFTWARE_RESET_REGISTER   0xFC

Definition at line 55 of file TMP42x.h.

◆ STATUS_REGISTER

#define STATUS_REGISTER   0x08

Definition at line 43 of file TMP42x.h.

Typedef Documentation

◆ TMP42x

typedef struct tmp42x TMP42x

Class (struct) that stores variables for interacting with TMP42x.

◆ TMP42x_ConversionRate

◆ TMP42x_Range

typedef enum TMP42x_Range TMP42x_Range

◆ TMP42x_Shutdown

◆ TMP42x_Status

◆ TMP42x_Type

typedef enum TMP42x_Type TMP42x_Type

Enumeration Type Documentation

◆ TMP42x_ConversionRate

Enumerator
TMP42x_0_0625 
TMP42x_0_125 
TMP42x_0_25 
TMP42x_0_5 
TMP42x_1 
TMP42x_2 
TMP42x_4 
TMP42x_8 

Definition at line 63 of file TMP42x.h.

◆ TMP42x_Range

Enumerator
TMP42x_Normal 
TMP42x_Extended 

Definition at line 61 of file TMP42x.h.

◆ TMP42x_Shutdown

Enumerator
TMP42x_Run 
TMP42x_ShutDown 

Definition at line 62 of file TMP42x.h.

◆ TMP42x_Status

Enumerator
TMP42x_OK 
TMP42x_TimeOut 
TMP42x_Arg_Error 

Definition at line 60 of file TMP42x.h.

◆ TMP42x_Type

Enumerator
TMP421 
TMP422 
TMP423 

Definition at line 59 of file TMP42x.h.

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.