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.

Version: Temperature Sensor Driver Version 1.0.0
Data structures
Functions

2.10.2.1.2 Function Documentation

Temp_Sensor_CelsiusToFahrenheit()

float Temp_Sensor_CelsiusToFahrenheit (float tempVal)

Converts the temperature value from Celsius to Fahrenheit.

Parameters:
float

tempVal - Temperature value to be converted.

Returns:

Converted value in Fahrenheit.

Temp_Sensor_FahrenheitToCelsius()

float Temp_Sensor_FahrenheitToCelsius (float tempVal)

Converts the temperature value from Fahrenheit to Celsius.

Parameters:
float

tempVal - Temperature value to be converted.

Returns:

Converted value in Celsius.

Temp_Sensor_Initialize()

TEMP_SENSOR_STATUS_t Temp_Sensor_Initialize (void )

Initializes the temperature sensor.

Parameters:
None.
Returns:

TEMP_SENSOR status code.

Temp_Sensor_LowPowerDisable()

TEMP_SENSOR_STATUS_t Temp_Sensor_LowPowerDisable (void )

Returns the temperature sensor power mode to Normal.

Parameters:
None.
Returns:

TEMP_SENSOR status code.

Temp_Sensor_LowPowerEnable()

TEMP_SENSOR_STATUS_t Temp_Sensor_LowPowerEnable (void )

Shifts the temperature sensor operation to Low-Power mode.

Parameters:
None.
Returns:

TEMP_SENSOR status code.

Temp_Sensor_TemperatureCelsiusRead()

TEMP_SENSOR_STATUS_t Temp_Sensor_TemperatureCelsiusRead (float * tempCelsiusVal)

Reads the temperature sensor value in Celsius.

Parameters:
float*

tempCelsiusVal - Pointer to a user-defined variable where the temperature in Celsius is to be stored.

Returns:

TEMP_SENSOR status code.

Temp_Sensor_TemperatureFahrenheitRead()

TEMP_SENSOR_STATUS_t Temp_Sensor_TemperatureFahrenheitRead (float * tempFahrenheitVal)

Reads the temperature sensor value in Fahrenheit.

Parameters:
float*

tempFahrenheitVal - Pointer to a user-defined variable where the temperature in Fahrenheit is to be stored.

Returns:

TEMP_SENSOR status code.

Temp_Sensor_TemperatureRawValueRead()

TEMP_SENSOR_STATUS_t Temp_Sensor_TemperatureRawValueRead (uint16_t * tempRawVal)

Reads the temperature sensor data.

Parameters:
uint16_t*

tempRawVal - Pointer to a user-defined variable where the temperature raw value is to be stored.

Returns:

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

The use-case code snippets explains Interface APIs Usage for the I2C MCP98xx off-chip device driver, within an MCC Melody project. The settings below are generic for all the use-cases listed in this document:
  • 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

(Specific settings for the AVR Cellular Mini)
  • 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>

2.10.3.1.2 Member Data Documentation

The documentation for this struct was generated from the following file:

source/

temp_sensor.h

CelsiusToFahrenheit

float(* TEMP_SENSOR_INTERFACE_t::CelsiusToFahrenheit) (float tempVal)

FahrenheitToCelsius

float(* TEMP_SENSOR_INTERFACE_t::FahrenheitToCelsius) (float tempVal)

TempCelsiusRead

TEMP_SENSOR_STATUS_t(* TEMP_SENSOR_INTERFACE_t::TempCelsiusRead) (float *tempCelsiusVal)

TempFahrenheitRead

TEMP_SENSOR_STATUS_t(* TEMP_SENSOR_INTERFACE_t::TempFahrenheitRead) (float *tempFahrenheitVal)

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

2.10.4.1.3 Detailed Description

Contains the API definitions for the Temperature Sensor module.

Temp_Sensor generated driver source file.

Version: Temperature Sensor Driver Version 1.0.0

2.10.4.1.4 Variable Documentation

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

2.10.4.3.2 Functions

2.10.4.3.5 Detailed Description

Temperature Sensor generated driver header file.