2.10 Temperature Sensor Off-chip Device Driver
2.10.1 Introduction
The MCC Melody Temperature Sensor Library creates an API interface to facilitate a temperature sensor's core functionalities. This library provides quick access to temperature readings, value conversions, and power mode selection.
2.10.2 Module Documentation
2.10.2.1 TEMP_SENSOR
Contains the API declarations and related data classes for the Temperature Sensor driver.
2.10.2.1.1 Module description
Contains the API declarations and related data classes for the Temperature Sensor driver.
Data structures
struct TEMP_SENSOR_INTERFACE_t
Structure containing the function pointers to the Temperature Sensor driver APIs.
Enumerations
enum _TEMP_SENSOR_STATUS { TEMP_SENSOR_NO_ERROR = 0U, TEMP_SENSOR_ERROR = 1U, TEMP_SENSOR_COMMUNICATION_ERROR = 2U }
Enumeration of the Temperature Sensor driver status codes.
Functions
TEMP_SENSOR_STATUS_t Temp_Sensor_Initialize (void)
Initializes the temperature sensor.
TEMP_SENSOR_STATUS_t Temp_Sensor_TemperatureRawValueRead (uint16_t *tempRawVal)
Reads the temperature sensor data.
TEMP_SENSOR_STATUS_t Temp_Sensor_TemperatureCelsiusRead (float *tempCelsiusVal)
Reads the temperature sensor value in Celsius.
TEMP_SENSOR_STATUS_t Temp_Sensor_TemperatureFahrenheitRead (float *tempFahrenheitVal)
Reads the temperature sensor value in Fahrenheit.
TEMP_SENSOR_STATUS_t Temp_Sensor_LowPowerEnable (void)
Shifts the temperature sensor operation to Low-Power mode.
TEMP_SENSOR_STATUS_t Temp_Sensor_LowPowerDisable (void)
Returns the temperature sensor power mode to Normal.
float Temp_Sensor_CelsiusToFahrenheit (float tempVal)
Converts the temperature value from Celsius to Fahrenheit.
float Temp_Sensor_FahrenheitToCelsius (float tempVal)
Converts the temperature value from Fahrenheit to Celsius.
2.10.2.1.2 Function Documentation
Temp_Sensor_CelsiusToFahrenheit()
float Temp_Sensor_CelsiusToFahrenheit (float tempVal)
Converts the temperature value from Celsius to Fahrenheit.
|
Converted value in Fahrenheit. |
Temp_Sensor_FahrenheitToCelsius()
float Temp_Sensor_FahrenheitToCelsius (float tempVal)
Converts the temperature value from Fahrenheit to Celsius.
|
Converted value in Celsius. |
Temp_Sensor_Initialize()
TEMP_SENSOR_STATUS_t Temp_Sensor_Initialize (void )
Initializes the temperature sensor.
|
TEMP_SENSOR status code. |
Temp_Sensor_LowPowerDisable()
TEMP_SENSOR_STATUS_t Temp_Sensor_LowPowerDisable (void )
Returns the temperature sensor power mode to Normal.
|
TEMP_SENSOR status code. |
Temp_Sensor_LowPowerEnable()
TEMP_SENSOR_STATUS_t Temp_Sensor_LowPowerEnable (void )
Shifts the temperature sensor operation to Low-Power mode.
|
TEMP_SENSOR status code. |
Temp_Sensor_TemperatureCelsiusRead()
TEMP_SENSOR_STATUS_t Temp_Sensor_TemperatureCelsiusRead (float * tempCelsiusVal)
Reads the temperature sensor value in Celsius.
|
TEMP_SENSOR status code. |
Temp_Sensor_TemperatureFahrenheitRead()
TEMP_SENSOR_STATUS_t Temp_Sensor_TemperatureFahrenheitRead (float * tempFahrenheitVal)
Reads the temperature sensor value in Fahrenheit.
|
TEMP_SENSOR status code. |
Temp_Sensor_TemperatureRawValueRead()
TEMP_SENSOR_STATUS_t Temp_Sensor_TemperatureRawValueRead (uint16_t * tempRawVal)
Reads the temperature sensor data.
|
TEMP_SENSOR status code. |
2.10.2.1.3 Enumeration Type Documentation
_TEMP_SENSOR_STATUS
enum _TEMP_SENSOR_STATUS
Enumeration of the Temperature Sensor driver status codes.
TEMP_SENSOR_NO_ERROR | |
TEMP_SENSOR_ERROR | |
TEMP_SENSOR_COMMUNICATION_ERROR |
2.10.2.2 Temp-sensor-use-cases
2.10.2.2.1 Temp Sensor Use-cases Code Snippet Instructions
-
Add Temperature > Temperature Sensor
-
Select Device "Off-chip: MCP98xx"
-
Select MCP98xx > I2C Host Dependency > TWI0 or TWÌ1 (depends on use case)
-
Select TWI interface > Interrupt driven: Off
-
Add Drivers > UART
-
Select UART > Dependency Selector > USARTx (depends on use case)
-
Select UART > Redirect Printf to UART > on
-
Generate
-
Make and Program Device Main Project
-
Select MCP98xx > I2C Host Dependency > TWI1
-
Select MCP98xx > A0 > VCC
-
Select TWI1 interface > Interrupt driven: Off
-
Select UART > Dependency Selector > USART3
2.10.2.2.2 temp-sensor-use-case-headers
For all the use cases below, include the following headers:
2.10.2.2.3 Read temperature (celcius/fahrenheit)
Reads temperature in degrees celcius and fahrenheit Calls API to get sensor readings, and displays these through the serial terminal.
2.10.2.2.4 Low power mode
Displays low power functionality of the MCP98xx device. Sets the device to sleep mode, wakes the device, takes sensor reading and displays this through the serial terminal and goes back to sleep.
2.10.3 Class Documentation
2.10.3.1 TEMP_SENSOR_INTERFACE_t Struct Reference
Structure containing the function pointers to the Temperature Sensor driver APIs.
2.10.3.1.1 Detailed Description
Structure containing the function pointers to the Temperature Sensor driver APIs.
#include <temp_sensor.h>
Public Attributes
TEMP_SENSOR_STATUS_t(* TempRead )(uint16_t *tempRawVal)
TEMP_SENSOR_STATUS_t(* TempCelsiusRead )(float *tempCelsiusVal)
TEMP_SENSOR_STATUS_t(* TempFahrenheitRead )(float *tempFahrenheitVal)
float(* CelsiusToFahrenheit )(float tempVal)
float(* FahrenheitToCelsius )(float tempVal)
2.10.3.1.2 Member Data Documentation
CelsiusToFahrenheit
float(* TEMP_SENSOR_INTERFACE_t::CelsiusToFahrenheit) (float tempVal)
FahrenheitToCelsius
float(* TEMP_SENSOR_INTERFACE_t::FahrenheitToCelsius) (float tempVal)
Initialize
TEMP_SENSOR_STATUS_t(* TEMP_SENSOR_INTERFACE_t::Initialize) ()
LowPowerDisable
TEMP_SENSOR_STATUS_t(* TEMP_SENSOR_INTERFACE_t::LowPowerDisable) ()
LowPowerEnable
TEMP_SENSOR_STATUS_t(* TEMP_SENSOR_INTERFACE_t::LowPowerEnable) ()
TempCelsiusRead
TEMP_SENSOR_STATUS_t(* TEMP_SENSOR_INTERFACE_t::TempCelsiusRead) (float *tempCelsiusVal)
TempFahrenheitRead
TEMP_SENSOR_STATUS_t(* TEMP_SENSOR_INTERFACE_t::TempFahrenheitRead) (float *tempFahrenheitVal)
TempRead
TEMP_SENSOR_STATUS_t(* TEMP_SENSOR_INTERFACE_t::TempRead) (uint16_t *tempRawVal)
2.10.4 File Documentation
2.10.4.1 source/src/temp_sensor.c File Reference
Contains the API definitions for the Temperature Sensor module.
#include "../../temperature/temp_sensor.h"
2.10.4.1.1 Functions
TEMP_SENSOR_STATUS_t Temp_Sensor_Initialize (void)
Initializes the temperature sensor.
TEMP_SENSOR_STATUS_t Temp_Sensor_TemperatureRawValueRead (uint16_t *tempRawValue)
Reads the temperature sensor data.
TEMP_SENSOR_STATUS_t Temp_Sensor_TemperatureCelsiusRead (float *tempCelsiusVal)
Reads the temperature sensor value in Celsius.
TEMP_SENSOR_STATUS_t Temp_Sensor_TemperatureFahrenheitRead (float *tempFahrenheitVal)
Reads the temperature sensor value in Fahrenheit.
TEMP_SENSOR_STATUS_t Temp_Sensor_LowPowerEnable (void)
Shifts the temperature sensor operation to Low-Power mode.
TEMP_SENSOR_STATUS_t Temp_Sensor_LowPowerDisable (void)
Returns the temperature sensor power mode to Normal.
float Temp_Sensor_CelsiusToFahrenheit (float tempVal)
Converts the temperature value from Celsius to Fahrenheit.
float Temp_Sensor_FahrenheitToCelsius (float tempVal)
Converts the temperature value from Fahrenheit to Celsius.
2.10.4.1.2 Variables
2.10.4.1.3 Detailed Description
Contains the API definitions for the Temperature Sensor module.
Temp_Sensor generated driver source file.
2.10.4.1.4 Variable Documentation
Temp_Sensor
const TEMP_SENSOR_INTERFACE_t Temp_Sensor
Initial value:
={ .Initialize = Temp_Sensor_Initialize, .TempRead = Temp_Sensor_TemperatureRawValueRead, .TempCelsiusRead = Temp_Sensor_TemperatureCelsiusRead, .TempFahrenheitRead = Temp_Sensor_TemperatureFahrenheitRead, .LowPowerEnable = Temp_Sensor_LowPowerEnable, .LowPowerDisable = Temp_Sensor_LowPowerDisable, .CelsiusToFahrenheit = Temp_Sensor_CelsiusToFahrenheit, .FahrenheitToCelsius = Temp_Sensor_FahrenheitToCelsius }
2.10.4.2 source/temp-sensor-lib.dox File Reference
2.10.4.3 source/temp_sensor.h File Reference
#include <stdint.h>
2.10.4.3.1 Data structures
struct TEMP_SENSOR_INTERFACE_t
Structure containing the function pointers to the Temperature Sensor driver APIs.
2.10.4.3.2 Functions
TEMP_SENSOR_STATUS_t Temp_Sensor_Initialize (void)
Initializes the temperature sensor.
TEMP_SENSOR_STATUS_t Temp_Sensor_TemperatureRawValueRead (uint16_t *tempRawVal)
Reads the temperature sensor data.
TEMP_SENSOR_STATUS_t Temp_Sensor_TemperatureCelsiusRead (float *tempCelsiusVal)
Reads the temperature sensor value in Celsius.
TEMP_SENSOR_STATUS_t Temp_Sensor_TemperatureFahrenheitRead (float *tempFahrenheitVal)
Reads the temperature sensor value in Fahrenheit.
TEMP_SENSOR_STATUS_t Temp_Sensor_LowPowerEnable (void)
Shifts the temperature sensor operation to Low-Power mode.
TEMP_SENSOR_STATUS_t Temp_Sensor_LowPowerDisable (void)
Returns the temperature sensor power mode to Normal.
float Temp_Sensor_CelsiusToFahrenheit (float tempVal)
Converts the temperature value from Celsius to Fahrenheit.
float Temp_Sensor_FahrenheitToCelsius (float tempVal)
Converts the temperature value from Fahrenheit to Celsius.
2.10.4.3.3 Typedefs
typedef enum _TEMP_SENSOR_STATUS TEMP_SENSOR_STATUS_t
2.10.4.3.4 Enumerations
enum _TEMP_SENSOR_STATUS { TEMP_SENSOR_NO_ERROR = 0U, TEMP_SENSOR_ERROR = 1U, TEMP_SENSOR_COMMUNICATION_ERROR = 2U }
Enumeration of the Temperature Sensor driver status codes.
2.10.4.3.5 Detailed Description
Temperature Sensor generated driver header file.
2.10.4.3.6 Typedef Documentation
TEMP_SENSOR_STATUS_t
typedef enum _TEMP_SENSOR_STATUS TEMP_SENSOR_STATUS_t