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
Go to the documentation of this file.
1
32
33#ifndef __TMP42x_H_
34#define __TMP42x_H_
35
36#include "main.h"
37#include "i2c.h"
38
39#define LOCAL_TEMP_MSB 0x00
40#define REMOTE1_TEMP_MSB 0x01
41#define REMOTE2_TEMP_MSB 0x02
42#define REMOTE3_TEMP_MSB 0x03
43#define STATUS_REGISTER 0x08
44#define CONFIG1_REGISTER 0x09
45#define CONFIG2_REGISTER 0x0A
46#define CONVERSION_RATE_REGISTER 0x0B
47#define ONE_SHOT_START_REGISTER 0x0F
48#define LOCAL_TEMP_LSB 0x10
49#define REMOTE1_TEMP_LSB 0x11
50#define REMOTE2_TEMP_LSB 0x12
51#define REMOTE3_TEMP_LSB 0x13
52#define nCORRECTION1_REGISTER 0x21
53#define nCORRECTION2_REGISTER 0x22
54#define nCORRECTION3_REGISTER 0x23
55#define SOFTWARE_RESET_REGISTER 0xFC
56#define MAN_ID_REGISTER 0xFE
57#define DEVICE_ID_REGISTER 0xFF
58
64
132
133// Privates ----------------------------------
134TMP42x_Status __TMP42x_readByte(TMP42x* self, uint8_t MemAddress);
135TMP42x_Status __TMP42x_readTwoBytes(TMP42x* self, uint8_t MemAddress);
136TMP42x_Status __TMP42x_writeByte(TMP42x* self, uint8_t MemAddress);
137
138// Public ------------------------------------
139TMP42x_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);
140double TMP42x_getLocalTemp(TMP42x* self);
141int8_t TMP42x_getLocalTemp_Int(TMP42x* self);
142double TMP42x_getRemoteTemp(TMP42x* self, uint8_t channel_number);
143int8_t TMP42x_getRemoteTemp_Int(TMP42x* self, uint8_t channel_number);
146uint8_t TMP42x_getManID(TMP42x* self);
147uint8_t TMP42x_getDevID(TMP42x* self);
148
149#endif
TMP42x_Type
Definition TMP42x.h:59
@ TMP422
Definition TMP42x.h:59
@ TMP421
Definition TMP42x.h:59
@ TMP423
Definition TMP42x.h:59
TMP42x_Status __TMP42x_readByte(TMP42x *self, uint8_t MemAddress)
Read a byte of data from TMP42x and stores in the tmp42x::_reg8::raw_data.
Definition TMP42x.c:48
uint8_t TMP42x_getManID(TMP42x *self)
Get the manufacturer ID.
Definition TMP42x.c:320
uint8_t TMP42x_getDevID(TMP42x *self)
Get the device ID.
Definition TMP42x.c:331
TMP42x_ConversionRate
Definition TMP42x.h:63
@ TMP42x_2
Definition TMP42x.h:63
@ TMP42x_0_5
Definition TMP42x.h:63
@ TMP42x_0_25
Definition TMP42x.h:63
@ TMP42x_8
Definition TMP42x.h:63
@ TMP42x_4
Definition TMP42x.h:63
@ TMP42x_0_0625
Definition TMP42x.h:63
@ TMP42x_1
Definition TMP42x.h:63
@ TMP42x_0_125
Definition TMP42x.h:63
double TMP42x_getLocalTemp(TMP42x *self)
Reads the full (floating-point) local temperature from a specified channel.
Definition TMP42x.c:262
TMP42x_Status __TMP42x_readTwoBytes(TMP42x *self, uint8_t MemAddress)
Read two bytes of data from TMP42x and stores in the tmp42x::_reg16::raw_data.
Definition TMP42x.c:82
TMP42x_Status TMP42x_oneShotStart(TMP42x *self)
Starts a single conversion if the device is in shutdown mode.
Definition TMP42x.c:294
TMP42x_Status
Definition TMP42x.h:60
@ TMP42x_TimeOut
Definition TMP42x.h:60
@ TMP42x_OK
Definition TMP42x.h:60
@ TMP42x_Arg_Error
Definition TMP42x.h:60
TMP42x_Range
Definition TMP42x.h:61
@ TMP42x_Extended
Definition TMP42x.h:61
@ TMP42x_Normal
Definition TMP42x.h:61
int8_t TMP42x_getRemoteTemp_Int(TMP42x *self, uint8_t channel_number)
Reads the integer part of the remote temperature from a specified channel.
Definition TMP42x.c:244
TMP42x_Shutdown
Definition TMP42x.h:62
@ TMP42x_ShutDown
Definition TMP42x.h:62
@ TMP42x_Run
Definition TMP42x.h:62
struct tmp42x TMP42x
Class (struct) that stores variables for interacting with TMP42x.
TMP42x_Status TMP42x_softwareReset(TMP42x *self)
Resets the device.
Definition TMP42x.c:309
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.
Definition TMP42x.c:138
double TMP42x_getRemoteTemp(TMP42x *self, uint8_t channel_number)
Reads the full (floating-point) remote temperature from a specified channel.
Definition TMP42x.c:217
int8_t TMP42x_getLocalTemp_Int(TMP42x *self)
Reads the integer part of the local temperature.
Definition TMP42x.c:279
TMP42x_Status __TMP42x_writeByte(TMP42x *self, uint8_t MemAddress)
Write a byte of data to TMP42x from the tmp42x::_reg8::raw_data.
Definition TMP42x.c:65
Class (struct) that stores variables for interacting with TMP42x.
Definition TMP42x.h:68
union tmp42x::_reg8 reg8
TMP42x_Shutdown shutdown
Definition TMP42x.h:74
TMP42x_ConversionRate conversion_rate
Definition TMP42x.h:76
union tmp42x::_reg16 reg16
float n_eff1
Definition TMP42x.h:77
I2C_HandleTypeDef * hi2c
Definition TMP42x.h:70
uint8_t I2C_ADDR
Definition TMP42x.h:71
TMP42x_Range range
Definition TMP42x.h:75
TMP42x_Type type
Definition TMP42x.h:73
float n_eff3
Definition TMP42x.h:79
float n_eff2
Definition TMP42x.h:78
uint8_t raw_data[2]
Definition TMP42x.h:82
struct tmp42x::_reg16::_temp_register temp_register
struct tmp42x::_reg8::_n_correction_register n_correction_register
uint8_t raw_data
Definition TMP42x.h:91
struct tmp42x::_reg8::_man_id_register man_id_register
struct tmp42x::_reg8::_status_register status_register
struct tmp42x::_reg8::_dev_id_register dev_id_register
struct tmp42x::_reg8::_conversion_rate_register conversion_rate_register
struct tmp42x::_reg8::_temp_frac_register temp_frac_register
struct tmp42x::_reg8::_config2_register _config2_register
struct tmp42x::_reg8::_temp_int_register temp_int_register
struct tmp42x::_reg8::_config1_register config1_register