RV32 SoC DS UG
High-Perf RV32 SoC DS UG
RV64 SoC DS UG API and Examples
Embedded IDE UG
Loading...
Searching...
No Matches
I2C Temperature Sensor Demo

This demo (temperatureSensorDemo directory) shows how to communicate with the on-board EMC1413 temperature module on Ti375C529. The demo prints out the temperature of the device every few seconds and alerts user if the temperature exceeds the high-temperature limit. Also, you can enable an extended range of temperature measurements to measure the temperature from -64°C to +191°C. Additonally, you can configure the high or low-temperature limit.

For more detail of the driver, refer to Temperature Sensor Driver

Newlib

By default, newlib-nano is used for this demo.

See also
User Debug Configuration - To learn more about User Debug Configuration.

User Configuration

The following parameters allow the user to configure the temperature sensor behavior in userDef.h:

Extended Range

Macro Default Description
EXTENDED_RANGE_ENABLED 0 0 = Standard range (0°C to +127°C)
1 = Extended range (-64°C to +191°C)

Temperature Limit Configuration

Macro Default Description
HIGH_TEMPERATURE_LIMIT_VALUE_INT 85 High temperature limit for internal sensor (EMC1413 itself)
LOW_TEMPERATURE_LIMIT_VALUE_INT 0 Low temperature limit for internal sensor (EMC1413 itself)
HIGH_TEMPERATURE_LIMIT_VALUE_EXT1 85 High temperature limit for external sensor 1
LOW_TEMPERATURE_LIMIT_VALUE_EXT1 0 Low temperature limit for external sensor 1
HIGH_TEMPERATURE_LIMIT_VALUE_EXT2 85 High temperature limit for external sensor 2
LOW_TEMPERATURE_LIMIT_VALUE_EXT2 0 Low temperature limit for external sensor 2

User Debug Configuration

The active debug mode is configured in userDef.h.

By default, this demo enables logging for main.c, system, and interrupt request modules based on DEBUG_Const, with ACTIVE_MIN_LVL set to DBG_LVL_ALL.

Debug Mode

Macro Default Description
DEBUG_MODE 1 0 = Asserts OFF, logs removed
1 = Asserts ON, logs filtered

Active Debug Module

Set ACTIVE_DEBUG_MOD to one or more of the following (combine with |):

Please refer to DEBUG_Const for more detail on Debug Modules.

Active Minimum Log Level

Set ACTIVE_MIN_LVL to filter the minimum log severity shown:

Value Level Description
DBG_LVL_ALL 0 Show Info, Warn, and Error
DBG_LVL_WARN 1 Show Warn and Error only
DBG_LVL_ERR 2 Show Error only
DBG_LVL_NONE 3 Silence all logs

Below are the userDef.h:

/* -------------------------------------------------------------------------*/
/* USER CONFIGURATION
/* -------------------------------------------------------------------------*/
#define EXTENDED_RANGE_ENABLED 0
#define HIGH_TEMPERATURE_LIMIT_VALUE_INT 85
#define LOW_TEMPERATURE_LIMIT_VALUE_INT 0
#define HIGH_TEMPERATURE_LIMIT_VALUE_EXT1 85
#define LOW_TEMPERATURE_LIMIT_VALUE_EXT1 0
#define HIGH_TEMPERATURE_LIMIT_VALUE_EXT2 85
#define LOW_TEMPERATURE_LIMIT_VALUE_EXT2 0
/* -----------------------------------------------------------------------------*/
/* USER DEBUG CONFIGURATION
/* -----------------------------------------------------------------------------*/
// --- DEBUG_MODE ---
// 0 = Asserts OFF, Logs removed
// 1 = Asserts ON, Logs filtered
#define DEBUG_MODE 1
// --- ACTIVE_DEBUG_MOD --- This is the list of available module to debug
// DBG_MOD_SYS // Enable Log for RISCV Extension
// DBG_MOD_IRQ // Enable Log for IRQ, mtrap
// DBG_MOD_FAULT // Enable Log for System Fault
// DBG_MOD_UART // Enable Log for UART Driver
// DBG_MOD_I2C // Enable Log for I2C Driver
// DBG_MOD_SPI // Enable Log for SPI Driver
// DBG_MOD_SPI_FLASH // Enable Log for SPI FLASH Driver
// DBG_MOD_RTC // Enable Log for RTC Driver
// DBG_MOD_CAM // Enable Log for CAM Driver
// DBG_MOD_SENSOR // Enable Log for Sensor (temp sensor)
// DBG_MOD_MAIN // Enable Log for main.c
// DBG_MOD_ALL // Enable all Logs
#define ACTIVE_DEBUG_MOD DBG_MOD_MAIN | DBG_MOD_SYS | DBG_MOD_IRQ
// --- ACTIVE_MIN_LVL ---
// DBG_LVL_ALL 0 // Show Info, Warn, Error
// DBG_LVL_WARN 1 // Show Warn, Error
// DBG_LVL_ERR 2 // Show Error only
// DBG_LVL_NONE 3 // Silence
#define ACTIVE_MIN_LVL DBG_LVL_ALL

Switching Temperature Sensor Driver

In userDef.h, the available Temperature Sensor driver are defined as follows:

/* -----------------------------------------------------------------------------*/
/* SENSOR Selection
/* -----------------------------------------------------------------------------*/
// --- TEMP_SENSOR Selection ---
#define SENSOR_TYPE_EMC1413 1
#define SENSOR_TYPE_CUSTOM 2 // User's Sensor
/* --- Add custom driver here or main.c -- */
// #include "sensor/device/custom.h"
// #define TEMP_SENSOR_CTRL TEMP_CUSTOM_ADDR
// #define TEMP_SENSOR_DRIVER custom_driver
// User Selects Here:
#define ACTIVE_TEMP_SENSOR_TYPE SENSOR_TYPE_EMC1413

To switch the Temperature Sensor driver, modify ACTIVE_TEMP_SENSOR_TYPE to the desired type.

Each selection automatically maps to the corresponding TEMP_SENSOR_CTRL(I2C address) and TEMP_SENSOR_DRIVER(Driver implementation).

ACTIVE_RTC_TYPE Driver Description
SENSOR_TYPE_EMC1413 EMC1413 Default on-board (Ti375C529)
SENSOR_TYPE_CUSTOM User-defined Custom

Integrating a Custom Temperature Sensor Driver

To integrate a custom Temperature Sensor driver into the framework, follow these steps:

Step 1 — Align custom driver to the Temperature Sensor framework

Ensure custom driver implements the temp_sensor_api_t interface for seamless integration.

Step 2 — Register custom driver in userDef.h

Uncomment and update the custom driver section:

#include "sensor/device/custom.h"
#define TEMP_SENSOR_CTRL TEMP_CUSTOM_ADDR
#define TEMP_SENSOR_DRIVER custom_driver

Step 3 — Select the custom driver

#define ACTIVE_TEMP_SENSOR_TYPE custom_driver

Execution Sequence:

The following shows the expected execution sequence:

Welcome to Temperature Demo!
INFO: The default Temperature Sensor driver is set to EMC1413 (Built-in Ti375C529_devkit),
User may change the supported driver via userDef.h
********************START OF CONFIGURATION***********************
Set High Temperature limit in internal EMC1413 sensor: 85.000000°C
Set High Temperature limit on temperature sensor 1 : 85.000000°C
Set High Temperature limit on temperature sensor 2 : 85.000000°C
Set Low Temperature limit in internal EMC1413 sensor : 0.000000°C
Set Low Temperature limit on temperature sensor 1 : 0.000000°C
Set Low Temperature limit on temperature sensor 2 : 0.000000°C
Range of the temperature measurement: Default Range (0°C to +127°C)
********************END OF CONFIGURATION***********************
OK: Done Configure!!!
Internal: 0.000°C External D1: 0.000°C External D2: 0.000°C
Internal: 32.875°C External D1: 34.375°C External D2: 34.375°C
Internal: 32.750°C External D1: 34.375°C External D2: 34.375°C
Internal: 32.875°C External D1: 34.250°C External D2: 34.250°C