Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
MCP980X Temperature Sensor

See Quickstart guide for MCP980X module.

Purpose

The module provides useful API of MCP980X temperature sensor through a TWI interface.

Dependencies

This driver depends on the following module:

Modules

 Quick Start Guide(s)
 In this section you can find a list of all Quick Start guides related to the MCP980X Temperature Sensor.
 

Macros

#define MCP980X_CONF_REG   (0x01) /* Configuration Register */
 
#define MCP980X_DEC_UNIT   (625)
 
#define MCP980X_HYST_REG   (0x02) /* Temperature Hysteresis Register */
 
#define MCP980X_LIMT_REG   (0x03) /* Temperature Limit-set Register */
 
#define MCP980X_TEMP_REG   (0x00) /* Temperature Register */
 
#define TWI_SPEED   (400000ul) /* 400KHz TWI bus frequency */
 

Functions

uint32_t mcp980x_disable (void)
 Disable the sensor. More...
 
uint32_t mcp980x_enable (void)
 Enable the sensor. More...
 
uint32_t mcp980x_get_configuration (uint8_t *p_config)
 Get MCP980X configuration. More...
 
uint32_t mcp980x_get_temperature (int8_t *p_integer, uint32_t *p_decimal)
 Get ambient temperature. More...
 
uint32_t mcp980x_get_temperature_hysteresis (int8_t *p_integer, uint32_t *p_decimal)
 Get temperature hysteresis. More...
 
uint32_t mcp980x_get_temperature_limit (int8_t *p_integer, uint32_t *p_decimal)
 Get temperature limit. More...
 
static void mcp980x_hex_to_temperature_dec (uint8_t uc_hex, uint32_t *p_decimal)
 Convert hexadecimal value to decimal part of temperature. More...
 
static void mcp980x_hex_to_temperature_int (uint8_t uc_hex, int8_t *p_integer)
 Convert hexadecimal value to integer part of temperature. More...
 
uint32_t mcp980x_init (void)
 Init the sensor. More...
 
static uint32_t mcp980x_interface_init (void)
 Initialize the hardware interface to the controller. More...
 
uint32_t mcp980x_one_shot_mode (void)
 Enable One-Shot mode and perform a single temperature measure. More...
 
static uint32_t mcp980x_read_register (uint32_t ul_reg_index, uint8_t *p_reg_value)
 Read the MCP980X register specified by ul_reg_index. More...
 
uint32_t mcp980x_set_configuration (uint8_t uc_config)
 Set MCP980X configuration. More...
 
uint32_t mcp980x_set_temperature_hysteresis (int8_t c_integer, uint32_t ul_decimal)
 Set temperature hysteresis. More...
 
uint32_t mcp980x_set_temperature_limit (int8_t c_integer, uint32_t ul_decimal)
 Set temperature limit. More...
 
static void mcp980x_temperature_to_hex_dec (uint32_t ul_decimal, uint8_t *p_hex)
 Convert decimal part of temperature to hexadecimal value. More...
 
static void mcp980x_temperature_to_hex_int (int8_t c_integer, uint8_t *p_hex)
 Convert integer part of temperature to hexadecimal value. More...
 
static uint32_t mcp980x_write_register (uint32_t ul_reg_index, uint8_t *p_reg_value)
 Write the MCP980X register specified by ul_reg_index. More...
 

#define MCP980X_CONF_REG   (0x01) /* Configuration Register */
#define MCP980X_DEC_UNIT   (625)
#define MCP980X_HYST_REG   (0x02) /* Temperature Hysteresis Register */
#define MCP980X_LIMT_REG   (0x03) /* Temperature Limit-set Register */
#define MCP980X_TEMP_REG   (0x00) /* Temperature Register */

Referenced by mcp980x_get_temperature().

#define TWI_SPEED   (400000ul) /* 400KHz TWI bus frequency */

Referenced by mcp980x_interface_init().

uint32_t mcp980x_disable ( void  )

Disable the sensor.

Returns
TWI bus operation result.

References MCP980X_CONF_REG, MCP980X_CONFIG_SHUTDOWN_ENABLE, mcp980x_read_register(), mcp980x_write_register(), and TWI_SUCCESS.

Referenced by mcp980x_one_shot_mode().

uint32_t mcp980x_enable ( void  )

Enable the sensor.

Returns
TWI bus operation result.

References MCP980X_CONF_REG, MCP980X_CONFIG_SHUTDOWN_ENABLE, mcp980x_read_register(), mcp980x_write_register(), and TWI_SUCCESS.

uint32_t mcp980x_get_configuration ( uint8_t *  p_config)

Get MCP980X configuration.

Parameters
p_configPointer to the configuration of sensor.
Returns
TWI bus operation result.

References MCP980X_CONF_REG, and mcp980x_read_register().

Referenced by mcp980x_one_shot_mode().

uint32_t mcp980x_get_temperature ( int8_t *  p_integer,
uint32_t *  p_decimal 
)

Get ambient temperature.

Parameters
p_integerPointer to the integer part of ambient temperature in degree Celsius.
p_decimalPointer to the decimal part of ambient temperature in 10 ^ -4 degree Celsius.
Returns
TWI bus operation result.

References mcp980x_hex_to_temperature_dec(), mcp980x_hex_to_temperature_int(), mcp980x_read_register(), MCP980X_TEMP_REG, and TWI_SUCCESS.

uint32_t mcp980x_get_temperature_hysteresis ( int8_t *  p_integer,
uint32_t *  p_decimal 
)

Get temperature hysteresis.

Parameters
p_integerPointer to the integer part of temperature hysteresis in degree Celsius.
p_decimalPointer to the decimal part of temperature hysteresis in 10 ^ -4 degree Celsius.
Returns
TWI bus operation result.

References mcp980x_hex_to_temperature_dec(), mcp980x_hex_to_temperature_int(), MCP980X_HYST_REG, mcp980x_read_register(), and TWI_SUCCESS.

uint32_t mcp980x_get_temperature_limit ( int8_t *  p_integer,
uint32_t *  p_decimal 
)

Get temperature limit.

Parameters
p_integerPointer to the integer part of temperature limit in degree Celsius.
p_decimalPointer to the decimal part of temperature limit in 10 ^ -4 degree Celsius.
Returns
TWI bus operation result.

References mcp980x_hex_to_temperature_dec(), mcp980x_hex_to_temperature_int(), MCP980X_LIMT_REG, mcp980x_read_register(), and TWI_SUCCESS.

static void mcp980x_hex_to_temperature_dec ( uint8_t  uc_hex,
uint32_t *  p_decimal 
)
static

Convert hexadecimal value to decimal part of temperature.

Parameters
uc_hexThe hexadecimal value.
p_decimalPointer to the decimal part of temperature.

References MCP980X_DEC_UNIT.

Referenced by mcp980x_get_temperature(), mcp980x_get_temperature_hysteresis(), and mcp980x_get_temperature_limit().

static void mcp980x_hex_to_temperature_int ( uint8_t  uc_hex,
int8_t *  p_integer 
)
static

Convert hexadecimal value to integer part of temperature.

Parameters
uc_hexThe hexadecimal value.
p_integerPointer to the integer part of temperature.

Referenced by mcp980x_get_temperature(), mcp980x_get_temperature_hysteresis(), and mcp980x_get_temperature_limit().

uint32_t mcp980x_init ( void  )

Init the sensor.

Returns
TWI bus operation result.

References mcp980x_interface_init().

static uint32_t mcp980x_interface_init ( void  )
static

Initialize the hardware interface to the controller.

This will initialize the module used for communication with the controller. Currently supported interface by this driver is the TWI module in master mode.

Returns
TWI bus operation result.

References BOARD_MCP980X_ADDR, BOARD_MCP980X_TWI_INSTANCE, twi_options::speed, twi_master_setup(), and TWI_SPEED.

Referenced by mcp980x_init().

uint32_t mcp980x_one_shot_mode ( void  )

Enable One-Shot mode and perform a single temperature measure.

Returns
TWI bus operation result.

References MCP980X_CONFIG_ONE_SHOT_ENABLE, MCP980X_CONFIG_SHUTDOWN_ENABLE, mcp980x_disable(), mcp980x_get_configuration(), mcp980x_set_configuration(), and TWI_SUCCESS.

static uint32_t mcp980x_read_register ( uint32_t  ul_reg_index,
uint8_t *  p_reg_value 
)
static

Read the MCP980X register specified by ul_reg_index.

Parameters
ul_reg_indexThe index of MCP980X register.
p_reg_valuePointer to the value read from the specified MCP980X register.
Returns
TWI bus operation result.

References BOARD_MCP980X_ADDR, BOARD_MCP980X_TWI_INSTANCE, twi_packet::chip, twi_packet::length, MCP980X_CONF_REG, and twi_master_read().

Referenced by mcp980x_disable(), mcp980x_enable(), mcp980x_get_configuration(), mcp980x_get_temperature(), mcp980x_get_temperature_hysteresis(), and mcp980x_get_temperature_limit().

uint32_t mcp980x_set_configuration ( uint8_t  uc_config)

Set MCP980X configuration.

Parameters
uc_configThe configuration of sensor.
Returns
TWI bus operation result.

References MCP980X_CONF_REG, and mcp980x_write_register().

Referenced by mcp980x_one_shot_mode().

uint32_t mcp980x_set_temperature_hysteresis ( int8_t  c_integer,
uint32_t  ul_decimal 
)

Set temperature hysteresis.

Parameters
c_integerThe integer part of temperature hysteresis in degree Celsius.
ul_decimalThe decimal part of temperature hysteresis in 10 ^ -4 degree Celsius.
Returns
TWI bus operation result.

References MCP980X_HYST_REG, mcp980x_temperature_to_hex_dec(), mcp980x_temperature_to_hex_int(), and mcp980x_write_register().

uint32_t mcp980x_set_temperature_limit ( int8_t  c_integer,
uint32_t  ul_decimal 
)

Set temperature limit.

Parameters
c_integerThe integer part of temperature limit in degree Celsius.
ul_decimalThe decimal part of temperature limit in 10 ^ -4 degree Celsius.
Returns
TWI bus operation result.

References MCP980X_LIMT_REG, mcp980x_temperature_to_hex_dec(), mcp980x_temperature_to_hex_int(), and mcp980x_write_register().

static void mcp980x_temperature_to_hex_dec ( uint32_t  ul_decimal,
uint8_t *  p_hex 
)
static

Convert decimal part of temperature to hexadecimal value.

Parameters
ul_decimalThe decimal part of temperature.
p_hexPointer to the hexadecimal value.

References MCP980X_DEC_UNIT.

Referenced by mcp980x_set_temperature_hysteresis(), and mcp980x_set_temperature_limit().

static void mcp980x_temperature_to_hex_int ( int8_t  c_integer,
uint8_t *  p_hex 
)
static

Convert integer part of temperature to hexadecimal value.

Parameters
c_integerThe integer part of temperature.
p_hexPointer to the hexadecimal value.

Referenced by mcp980x_set_temperature_hysteresis(), and mcp980x_set_temperature_limit().

static uint32_t mcp980x_write_register ( uint32_t  ul_reg_index,
uint8_t *  p_reg_value 
)
static

Write the MCP980X register specified by ul_reg_index.

Parameters
ul_reg_indexThe index of MCP980X register.
p_reg_valuePointer to the value to be written to the specified MCP980X register.
Returns
TWI bus operation result.

References BOARD_MCP980X_ADDR, BOARD_MCP980X_TWI_INSTANCE, twi_packet::chip, twi_packet::length, MCP980X_CONF_REG, and twi_master_write().

Referenced by mcp980x_disable(), mcp980x_enable(), mcp980x_set_configuration(), mcp980x_set_temperature_hysteresis(), and mcp980x_set_temperature_limit().