Sensor Data Collector#
Introduction#
The Sensor Data Collector (SDC) is a low-power peripheral that internally uses ADC, enabling the conversion of analog signals (continuous voltage levels) into digital data (discrete binary values). This conversion allows microcontrollers to interface with analog sensors, such as temperature sensors, light sensors, or joysticks, effectively translating real-world analog signals into data that can be processed by digital systems.
Features supported by the Watchdog Timer
Low power operation: SDC works in PS1 mode.
Multiple channels: SDC supports upto 4 channels.
Sampling Interval: The SDC can be configured to sample data at different intervals from 1 to 1024 units of seconds or milli seconds.
Sampling threshold: The SDC can be configured with a sampling threshold ranging from 1 to 16. device wakeups after reaching the threshold.
Single Ended and Differential Mode: SDC supports both single-ended and differential modes of operation.
Configuration#
Configuring the SDC involves several key steps to ensure accurate and efficient operation. These steps vary based on the specific hardware and application requirements. Below are some essential configuration tasks:
SDC Common Configurations: Define number of samples, sampling interval (1-1024), sampling threshold (1-16), clock division factor, and millisecond or second selection in the
sl_si91x_sdc_config_t
structure. After configuring this structure, callsl_si91x_sdc_driver_config()
to set the SDC parameters.Channel-Specific Settings: Define transfer count, buffer in the
sl_si91x_sdc_channel_info_t
structure, Auto buffer reset insl_si91x_sdc_channel_misc_config_t
, Input type and input pins insl_si91x_sdc_adc_config_t
. After configuring this structure, callsl_sdc_driver_channel_config()
to set the channel parameters.
For more detailed configuration information, see the specific peripheral example README documents.
Usage#
After defining the ADC configuration structures, use the following functions to initialize and control the ADC module:
Initialize SDC: sl_si91x_sdc_driver_init
Set SDC Configuration: sl_si91x_sdc_driver_config
Set Channel Configuration: sl_si91x_sdc_driver_channel_config
Register Callback: sl_si91x_sdc_driver_register_callback
Start Reading Data: sl_si91x_sdc_driver_read_data_start
Stop Reading Data: sl_si91x_sdc_driver_stop
Store Data: sl_si91x_sdc_driver_store_data
Read Data: sl_si91x_sdc_driver_read_data
Modules#
sl_si91x_sdc_channel_misc_config_t
Enumerations#
Enumeration for SDC Events.
Typedefs#
Callback function type for Sensor Data Controller (SDC) events.
Functions#
Initialize the SDC driver.
Deinitialize the SDC driver.
Configure the SDC driver with channel and pin configuration.
Configures an SDC channel with the specified settings.
Register a callback for SDC events.
Unregister the SDC callback.
Start reading data from SDC.
Stop the SDC driver.
Store the data from SDC FIFO registers.
Reads data from the SDC driver for the specified channel.
Macros#
Mask for transfer complete.
Position for transfer complete.
Channel 1 transfer complete flag.
Channel 2 transfer complete flag.
Channel 3 transfer complete flag.
Channel 4 transfer complete flag.
Mask for buffer auto reset.
Position for buffer auto reset.
Channel 1 buffer auto reset enable flag.
Channel 2 buffer auto reset enable flag.
Channel 3 buffer auto reset enable flag.
Channel 4 buffer auto reset enable flag.
Mask for differential mode.
Position for differential mode.
Channel 1 differential mode flag.
Channel 2 differential mode flag.
Channel 3 differential mode flag.
Channel 4 differential mode flag.
Status code indicating that buffer has been reset after successfully reading the data.
Status code indicating buffer is full.
Single-ended Mode.
Differential Mode.
Maximum value of the SDC in single-ended mode.
Minimum value of the SDC.
Mid value of the SDC.
Maximum FIFO threshold per channel when only using one channel.
Maximum FIFO threshold per channel for SDC with two channels.
Maximum FIFO threshold per channel for SDC with four channels.
Enumeration Documentation#
sl_sdc_event_t#
sl_sdc_event_t
Enumeration for SDC Events.
Enumerator | |
---|---|
SDC_EVENT_SAMPLE_COMPLETE | Sample complete event. |
SDC_EVENT_ERROR | Error event. |
SDC_EVENT_DATA_READY | SDC data ready. |
SDC_EVENT_BUFFER_FULL | Buffer is full. |
SDC_EVENT_BUFFER_RESET | Buffer reset. |
Typedef Documentation#
sl_sdc_callback_t#
typedef void(* sl_sdc_callback_t) (uint8_t channel, sl_sdc_event_t event) )(uint8_t channel, sl_sdc_event_t event)
Callback function type for Sensor Data Controller (SDC) events.
Type | Direction | Argument Name | Description |
---|---|---|---|
[in] | channel | The SDC channel on which the event occurred | |
[in] | event | The type of event that occurred |
This typedef defines a function pointer for SDC event callbacks. The callback function is invoked when SDC events occur.
Note
The application must register this callback to receive notifications about SDC events
Function Documentation#
sl_si91x_sdc_driver_init#
sl_status_t sl_si91x_sdc_driver_init (float vref)
Initialize the SDC driver.
Type | Direction | Argument Name | Description |
---|---|---|---|
float | [in] | vref | Reference voltage for SDC. |
This function initializes the SDC driver by performing the following steps:
Initializes the RTC block.
Starts the RTC.
Initializes the SDC peripheral.
Gets the chip voltage and update input voltage if required.
Calibrates the ADC.
Calculates the offset and gain values and stores them.
Configures the SDC LDO voltage based on the reference voltage.
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Successfully initialized the SDC.
SL_STATUS_INVALID_PARAMETER - Parameters are invalid.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_sdc_driver_deinit#
sl_status_t sl_si91x_sdc_driver_deinit (void )
Deinitialize the SDC driver.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
This function performs the following steps:
Stops the RTC to ensure no further operations are performed on it.
Disables the SDC NVIC interrupt to prevent further interrupts.
Deinitializes the SDC peripheral.
Disables the SDC LDO to save power.
Resets the global variable sdc_channel_info to zero.
Resets the global variable sdc_calibration_data to zero.
Pre-conditions:
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Successfully deinitialized the SDC.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_sdc_driver_config#
sl_status_t sl_si91x_sdc_driver_config (sl_si91x_sdc_config_t * sl_sdc_config)
Configure the SDC driver with channel and pin configuration.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_si91x_sdc_config_t * | [in] | sl_sdc_config | Pointer to SDC configuration structure. |
This function performs the following steps:
Checks if the provided configuration pointer is NULL and returns an error if it is.
Decrements the sample threshold and trigger event select values in the configuration to match the expected values in the SDC register.
Configures the SDC with the provided configuration using the
sl_si91x_sdc_config
function.Returns the status of the configuration operation.
Pre-conditions:
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Successfully configured the SDC.
SL_STATUS_INVALID_PARAMETER - Parameters are invalid.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_sdc_driver_channel_config#
sl_status_t sl_si91x_sdc_driver_channel_config (sl_si91x_sdc_adc_config_t * pin_config, sl_si91x_sdc_channel_info_t * sdc_channel_config, sl_si91x_sdc_channel_misc_config_t * misc_config)
Configures an SDC channel with the specified settings.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_si91x_sdc_adc_config_t * | [in] | pin_config | Pointer to a structure containing the ADC pin configuration parameters. |
sl_si91x_sdc_channel_info_t * | [in] | sdc_channel_config | Pointer to a structure containing the SDC channel configuration parameters. |
sl_si91x_sdc_channel_misc_config_t * | [in] | misc_config | Pointer to a structure containing misc config of SDC channel |
This function performs the following steps:
Checks if the provided pin configuration and channel configuration pointers are NULL and returns an error if they are.
Configures the SDC ADC pins using the
sl_si91x_sdc_adc_pin_config
function with the provided pin configuration and the number of channels.Iterates through each channel and initializes the channel information structure with the provided settings:
Sets the sample length for each channel.
Sets the receive buffer for each channel.
Sets the differential mode and auto buffer reset bits in the channel info bit field.
Returns the status of the configuration operation.
Pre-conditions:
Note
pin_config structure is auto-generated when instance is created in the application user can directly use that structure.
Returns
SL_STATUS_OK on success.
SL_STATUS_FAIL on failure.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_sdc_driver_register_callback#
sl_status_t sl_si91x_sdc_driver_register_callback (sl_sdc_callback_t callback_event)
Register a callback for SDC events.
Type | Direction | Argument Name | Description |
---|---|---|---|
sl_sdc_callback_t | [in] | callback_event | Callback function to register. |
This API registers a user-provided callback function that is invoked when an SDC event occurs.
Pre-conditions:
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Successfully registered the callback.
SL_STATUS_BUSY - Callback already registered.
SL_STATUS_NULL_POINTER - The parameter is a null pointer.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_sdc_driver_unregister_callback#
sl_status_t sl_si91x_sdc_driver_unregister_callback (void )
Unregister the SDC callback.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
This API unregisters the callback function registered for SDC events.
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Successfully unregistered the callback.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_sdc_driver_read_data_start#
sl_status_t sl_si91x_sdc_driver_read_data_start (void )
Start reading data from SDC.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
This API starts the SDC data acquisition process.
It prepares the SDC to read data and provides a buffer to store the received data.
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Successfully started data read.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_sdc_driver_stop#
sl_status_t sl_si91x_sdc_driver_stop (void )
Stop the SDC driver.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
This API stops the SDC data acquisition process.
It disables the SDC interrupt and stops the SDC sampling process.
Pre-conditions:
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Successfully stopped the SDC.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_sdc_driver_store_data#
sl_status_t sl_si91x_sdc_driver_store_data (void )
Store the data from SDC FIFO registers.
Type | Direction | Argument Name | Description |
---|---|---|---|
void | N/A |
This API performs the following steps:
Reads the data from the SDC FIFO.
channel_id is decremented by 1 to match the zero-based index.
Checks if the channel is in differential mode and processes the data accordingly.
Stores the processed data in the channel's receive buffer.
Increments the transfer count for the channel.
Checks if the transfer count has reached the sample length for the channel. If it has, it calls the callback function with the SDC_EVENT_SAMPLE_COMPLETE event for that channel.
If the channel is set to auto buffer reset, it resets the transfer count for the channel and clears the transfer complete bit in the channel info bit field.
Pre-conditions:
Note
1. This API should be called only after the SDC is started.
If auto buffer reset is enabled, the write pointer wraps around to the start of the buffer when it reaches the end, allowing new data to overwrite the oldest data.
Returns
sl_status_t Status code indicating the result:
SL_STATUS_OK - Successfully reads the SDC data.
For more information on status codes, see SL STATUS DOCUMENTATION.
sl_si91x_sdc_driver_read_data#
sl_status_t sl_si91x_sdc_driver_read_data (uint32_t channel, int16_t * buffer, uint8_t length)
Reads data from the SDC driver for the specified channel.
Type | Direction | Argument Name | Description |
---|---|---|---|
uint32_t | [in] | channel | The SDC channel number to read data from. |
int16_t * | [out] | buffer | Pointer to the buffer where the read data will be stored. |
uint8_t | [in] | length | The number of samples to read from the SDC channel. |
This function reads data of specified length from the given SDC channel and stores it in the provided buffer.
Pre-conditions:
Returns
SL_STATUS_OK if the data was read successfully.
SL_INVALID_PARAMETER if the provided parameters are invalid (e.g., channel number out of range, buffer is NULL, or length > threshold). For more information on status codes, see SL STATUS DOCUMENTATION.