RA Flexible Software Package Documentation  Release v5.7.0

 
RRH47000 NDIR CO2 Sensor Module (rm_rrh47000)

Functions

fsp_err_t RM_RRH47000_Open (rm_air_sensor_ctrl_t *const p_api_ctrl, rm_air_sensor_cfg_t const *const p_cfg)
 Opens and configures the RRH47000 sensor module. Implements rm_air_sensor_api_t::open. More...
 
fsp_err_t RM_RRH47000_Close (rm_air_sensor_ctrl_t *const p_api_ctrl)
 This function should be called when close the sensor module. Implements rm_air_sensor_api_t::close. More...
 
fsp_err_t RM_RRH47000_Read (rm_air_sensor_ctrl_t *const p_api_ctrl, rm_air_sensor_raw_data_t *const p_raw_data)
 This function should be called to get measurement results after measurement finishes. Implements rm_air_sensor_api_t::read. More...
 
fsp_err_t RM_RRH47000_DataCalculate (rm_air_sensor_ctrl_t *const p_api_ctrl, const rm_air_sensor_raw_data_t *const p_raw_data, rm_air_sensor_data_t *const p_rrh47000_data)
 This function should be called when calculating gas data from measurement results. Implements rm_air_sensor_api_t::dataCalculate. More...
 
fsp_err_t RM_RRH47000_FirmwareVersionGet (rm_air_sensor_ctrl_t *const p_api_ctrl, rm_air_sensor_version_t *const p_version)
 This function should be called to get firmware version. Firmware version will be set "ascii_code" of p_version. Implements rm_air_sensor_api_t::firmwareVersionGet. More...
 
fsp_err_t RM_RRH47000_StatusCheck (rm_air_sensor_ctrl_t *const p_api_ctrl)
 StatusCheck API is unsupported. Implements rm_air_sensor_api_t::statusCheck. More...
 
fsp_err_t RM_RRH47000_AlgorithmVersionGet (rm_air_sensor_ctrl_t *const p_api_ctrl, rm_air_sensor_version_t *const p_version)
 AlgorithmVersionGet API is unsupported. Implements rm_air_sensor_api_t::statusCheck. More...
 

Detailed Description

Middleware to implement the RRH47000 sensor module interface. This module implements the SENSOR Middleware Interface.

Overview

This module provides an API for configuring and controlling the RRH47000 sensor module.

I2C communication with the RRH47000 sensor module is realized by connecting with the rm_comms_i2c module.

Features

The RRH47000 sensor interface implementation has the following key features:

Configuration

Build Time Configurations for rm_rrh47000

The following build time configurations are defined in fsp_cfg/rm_rrh47000_cfg.h:

ConfigurationOptionsDefaultDescription
Parameter Checking
  • Default (BSP)
  • Enabled
  • Disabled
Default (BSP) If selected code for parameter checking is included in the build.

Configurations for Sensor > RRH47000 NDIR CO2 Sensor Module (rm_rrh47000)

This module can be added to the Stacks tab via New Stack > Sensor > RRH47000 NDIR CO2 Sensor Module (rm_rrh47000).

ConfigurationOptionsDefaultDescription
NameName must be a valid C symbolg_rrh47000_sensor0 Module name.
Automatic Baseline Correction (ABC)
  • Enable all
  • Enable only ABC
  • Enable only fast ABC
  • Disable all
Enable all Set Automatic Baseline Correction (ABC).
Correction cycle period [days]Value must be 1 or more7 Set correction cycle period. Min = 1 and Max = 30.
CO2 baseline value [ppm]Value must be 400 or more400 Set CO2 baseline value. Min = 400 and Max = 1500.
Comms I2C CallbackName must be a valid C symbolrrh47000_comms_i2c_callback A user COMMS I2C callback function can be provided.

Pin Configuration

This module use SDA and SCL pins of I2C Master, SCI I2C and IICA Master.

Usage Notes

RRH47000 datasheet is here.
The RRH47000 sensor module uses nondispersive infrared (NDIR) technology to accurately measure CO2 in a compact package size while ensuring competitive pricing. An integrated relative humidity and temperature sensor enables calibration and compensation of the NDIR sensor for precise operation in different environments. Sensors for carbon dioxide (CO2, not estimated), humidity (RH), and temperature (T), are combined in a single package.
If an RTOS is used, blocking and bus lock is available.

Notifications

Limitations

Bus Initialization

The RRH47000 interface expects a bus instance to be opened before opening any RRH47000 device. The interface will handle switching between devices on the bus but will not open or close the bus instance. The user should open the bus with the appropriate I2C Master Interface open call.

Initialization

Initialize with RM_RRH47000_Open().

From measurement start to data acquisition

An endless loop continuously checks the status of the RRH47000 sensor module and reads its data. The measurement results are subsequently processed, and the air quality values are calculated.

  1. Call RM_RRH47000_Read() and read the measurement data.
  2. Wait until RM_AIR_SENSOR_EVENT_SUCCESS is received.
  3. Call RM_RRH47000_DataCalculate().

Examples

Basic Example

These are basic examples of minimal use of RRH47000 sensor implementation in an application.

void rm_rrh47000_basic_example (void)
{
fsp_err_t err = FSP_SUCCESS;
rm_air_sensor_data_t rrh47000_data;
bool calculated = false;
/* Open the I2C bus if it is not already open. */
rm_comms_i2c_bus_extended_cfg_t * p_extend =
(rm_comms_i2c_bus_extended_cfg_t *) g_rrh47000_cfg.p_comms_instance->p_cfg->p_extend;
i2c_master_instance_t * p_driver_instance = (i2c_master_instance_t *) p_extend->p_driver_instance;
p_driver_instance->p_api->open(p_driver_instance->p_ctrl, p_driver_instance->p_cfg);
#if BSP_CFG_RTOS
/* Create a semaphore for blocking if a semaphore is not NULL */
if (NULL != p_extend->p_blocking_semaphore)
{
#if BSP_CFG_RTOS == 1 // AzureOS
tx_semaphore_create(p_extend->p_blocking_semaphore->p_semaphore_handle,
p_extend->p_blocking_semaphore->p_semaphore_name,
(ULONG) 0);
#elif BSP_CFG_RTOS == 2 // FreeRTOS
*(p_extend->p_blocking_semaphore->p_semaphore_handle) =
xSemaphoreCreateCountingStatic((UBaseType_t) 1,
(UBaseType_t) 0,
p_extend->p_blocking_semaphore->p_semaphore_memory);
#endif
}
/* Create a recursive mutex for bus lock if a recursive mutex is not NULL */
if (NULL != p_extend->p_bus_recursive_mutex)
{
#if BSP_CFG_RTOS == 1 // AzureOS
tx_mutex_create(p_extend->p_bus_recursive_mutex->p_mutex_handle,
p_extend->p_bus_recursive_mutex->p_mutex_name,
TX_INHERIT);
#elif BSP_CFG_RTOS == 2 // FreeRTOS
*(p_extend->p_bus_recursive_mutex->p_mutex_handle) =
xSemaphoreCreateRecursiveMutexStatic(p_extend->p_bus_recursive_mutex->p_mutex_memory);
#endif
}
#endif
/* Delay 3 seconds after power-on */
err = RM_RRH47000_Open(&g_rrh47000_ctrl, &g_rrh47000_cfg);
/* Handle any errors. This function should be defined by the user. */
handle_error(err);
while (1)
{
do
{
g_rrh47000_i2c_callback_flag = 0;
/* Read measurement results from RRH47000 */
RM_RRH47000_Read(&g_rrh47000_ctrl, &raw_data);
while (0 == g_rrh47000_i2c_callback_flag)
{
/* Wait callback */
}
/* Calculate CO2, Humidity and Temperatuere values from measurement results */
err = RM_RRH47000_DataCalculate(&g_rrh47000_ctrl, &raw_data, &rrh47000_data);
if (FSP_SUCCESS == err)
{
/* valid data */
calculated = 1;
}
else if (FSP_ERR_SENSOR_INVALID_DATA == err)
{
/* invalid data. checksum error occurs. */
calculated = 0;
}
else
{
handle_error(err);
}
} while (0 == calculated);
/* Wait 1 seconds. */
}
}

Data Structures

struct  rm_rrh47000_init_process_params_t
 
struct  rm_rrh47000_instance_ctrl_t
 

Enumerations

enum  rm_rrh47000_abc_t
 

Data Structure Documentation

◆ rm_rrh47000_init_process_params_t

struct rm_rrh47000_init_process_params_t

RRH47000 initialization process block

Data Fields
volatile bool communication_finished Communication flag for blocking.
volatile rm_air_sensor_event_t event Callback event.

◆ rm_rrh47000_instance_ctrl_t

struct rm_rrh47000_instance_ctrl_t

RRH47000 control block

Data Fields

uint32_t open
 Open flag.
 
uint8_t write_buf [7]
 Write buffer for I2C communications.
 
uint8_t read_buf [13]
 Read buffer for I2C communications.
 
uint8_t * p_read_data
 Pointer to read data. This is used for checksum in callback.
 
uint8_t read_bytes
 Read bytes. This is used for checksum in callback.
 
rm_air_sensor_version_tp_version
 Pointer to firmware version.
 
volatile rm_air_sensor_event_t event
 Callback event.
 
rm_rrh47000_init_process_params_t init_process_params
 For the initialization process.
 
rm_air_sensor_cfg_t const * p_cfg
 Pointer of configuration block.
 
rm_comms_instance_t const * p_comms_i2c_instance
 Pointer of I2C Communications Middleware instance structure.
 
void const * p_context
 Pointer to the user-provided context.
 
void(* p_comms_callback )(rm_air_sensor_callback_args_t *p_args)
 I2C Communications callback.
 

Enumeration Type Documentation

◆ rm_rrh47000_abc_t

RRH47000 Automatic Baseline Correction (ABC) setting.

Enumerator
RM_RRH47000_ABC_ENABLE_ALL 

Enable all.

RM_RRH47000_ABC_ENABLE_ONLY_ABC 

Enable only ABC (automatic baseline correction)

RM_RRH47000_ABC_ENABLE_ONLY_FAST_ABC 

Enable only fast ABC (fast automatic baseline correction)

RM_RRH47000_ABC_DISABLE_ALL 

Disable all.

Function Documentation

◆ RM_RRH47000_Open()

fsp_err_t RM_RRH47000_Open ( rm_air_sensor_ctrl_t *const  p_api_ctrl,
rm_air_sensor_cfg_t const *const  p_cfg 
)

Opens and configures the RRH47000 sensor module. Implements rm_air_sensor_api_t::open.

Return values
FSP_SUCCESSRRH47000 successfully configured.
FSP_ERR_ASSERTIONNull pointer, or one or more configuration options is invalid.
FSP_ERR_ALREADY_OPENModule is already open. This module can only be opened once.
FSP_ERR_INVALID_DATAChecksum error occurs.

◆ RM_RRH47000_Close()

fsp_err_t RM_RRH47000_Close ( rm_air_sensor_ctrl_t *const  p_api_ctrl)

This function should be called when close the sensor module. Implements rm_air_sensor_api_t::close.

Return values
FSP_SUCCESSSuccessfully closed.
FSP_ERR_ASSERTIONNull pointer passed as a parameter.
FSP_ERR_NOT_OPENModule is not open.

◆ RM_RRH47000_Read()

fsp_err_t RM_RRH47000_Read ( rm_air_sensor_ctrl_t *const  p_api_ctrl,
rm_air_sensor_raw_data_t *const  p_raw_data 
)

This function should be called to get measurement results after measurement finishes. Implements rm_air_sensor_api_t::read.

Return values
FSP_SUCCESSSuccessfully results are read.
FSP_ERR_ASSERTIONNull pointer passed as a parameter.
FSP_ERR_NOT_OPENModule is not opened configured.
FSP_ERR_TIMEOUTCommunication is timeout.
FSP_ERR_ABORTEDCommunication is aborted.

◆ RM_RRH47000_DataCalculate()

fsp_err_t RM_RRH47000_DataCalculate ( rm_air_sensor_ctrl_t *const  p_api_ctrl,
const rm_air_sensor_raw_data_t *const  p_raw_data,
rm_air_sensor_data_t *const  p_rrh47000_data 
)

This function should be called when calculating gas data from measurement results. Implements rm_air_sensor_api_t::dataCalculate.

Return values
FSP_SUCCESSSuccessfully gas data is calculated.
FSP_ERR_ASSERTIONNull pointer passed as a parameter.
FSP_ERR_NOT_OPENModule is not opened configured.
FSP_ERR_SENSOR_INVALID_DATAChecksum error occurs.

◆ RM_RRH47000_FirmwareVersionGet()

fsp_err_t RM_RRH47000_FirmwareVersionGet ( rm_air_sensor_ctrl_t *const  p_api_ctrl,
rm_air_sensor_version_t *const  p_version 
)

This function should be called to get firmware version. Firmware version will be set "ascii_code" of p_version. Implements rm_air_sensor_api_t::firmwareVersionGet.

Return values
FSP_SUCCESSSuccessfully results are read.
FSP_ERR_ASSERTIONNull pointer passed as a parameter.
FSP_ERR_NOT_OPENModule is not opened configured.
FSP_ERR_INVALID_POINTERPointer is NULL.
FSP_ERR_TIMEOUTCommunication is timeout.
FSP_ERR_ABORTEDCommunication is aborted.

◆ RM_RRH47000_StatusCheck()

fsp_err_t RM_RRH47000_StatusCheck ( rm_air_sensor_ctrl_t *const  p_api_ctrl)

StatusCheck API is unsupported. Implements rm_air_sensor_api_t::statusCheck.

Return values
FSP_ERR_UNSUPPORTEDUnsupported.

◆ RM_RRH47000_AlgorithmVersionGet()

fsp_err_t RM_RRH47000_AlgorithmVersionGet ( rm_air_sensor_ctrl_t *const  p_api_ctrl,
rm_air_sensor_version_t *const  p_version 
)

AlgorithmVersionGet API is unsupported. Implements rm_air_sensor_api_t::statusCheck.

Return values
FSP_ERR_UNSUPPORTEDUnsupported.