ADC Hardware Abstraction Layer API Reference.
More...
API for configuring and manipulating ADC HAL module.
◆ hal_adc_configure_default()
Configures ADC configuration structure to default initialization values. Take into consideration that this is just structure variable initial values setting. Values need to be redefined by user.
- Parameters
-
[in,out] | config | ADC HAL layer configuration settings. See hal_adc_config_t structure definition for detailed explanation. |
Default values:
Function | Default value |
Input pin | HAL_PIN_NC (invalid pin) |
Resolution | 12 bit |
Vref input | External voltage reference source |
Vref value | -1 (invalid reference voltage value) |
- Returns
- Nothing.
Example
◆ hal_adc_open()
err_t hal_adc_open |
( |
handle_t * |
handle, |
|
|
bool |
hal_obj_open_state |
|
) |
| |
Function allocates memory needed for ADC HAL and pin for specified object.
- Parameters
-
[in,out] | handle | ADC handle. |
[in] | hal_obj_open_state | ADC state, is it open or not. |
- Returns
- The function can return one of the values defined by hal_adc_err_t, which is size dependant on the architecture.
Example
adc_configure_default(&hal_adc_cfg);
hal_adc_cfg.
pin. = MIKROBUS_1_AN;
◆ hal_adc_set_resolution()
Initializes ADC HAL on the hardware level and sets sample resolution to specified config->resolution
value.
- Parameters
-
[in] | handle | ADC handle. |
[in] | config | ADC HAL configuration structure. See hal_adc_config_t structure definition for detailed explanation. |
- Returns
- The function can return one of the values defined by hal_adc_err_t, which is size dependant on the architecture.
- Precondition
- Make sure that adequate memory has been allocated beforehand. See hal_adc_open definition for detailed explanation.
- Warning
- If desired resolution can not be achieved, error will be returned. Make sure to poll the return value in your code.
Example
◆ hal_adc_set_vref_input()
Initializes ADC HAL on the hardware level and sets sample reference voltage source to specified config->vref_input
value.
- Parameters
-
[in] | handle | ADC handle. |
[in] | config | ADC HAL configuration structure. See hal_adc_config_t structure definition for detailed explanation. |
- Returns
- The function can return one of the values defined by hal_adc_err_t, which is size dependant on the architecture.
- Precondition
- Make sure that adequate memory has been allocated beforehand. See hal_adc_open definition for detailed explanation.
- Warning
- If desired reference voltage source can not be achieved, error will be returned. Make sure to poll the return value in your code.
Example
◆ hal_adc_set_vref_value()
Sets sample reference voltage value to specified config->vref_value
value used later for calculating voltage.
- Parameters
-
[in] | handle | ADC handle. |
[in] | config | ADC HAL configuration structure. See hal_adc_config_t structure definition for detailed explanation. |
- Returns
- Nothing.
- Precondition
- Make sure that adequate memory has been allocated beforehand. See hal_adc_open definition for detailed explanation.
- Warning
- If desired reference voltage value is not set, calculated voltage value on AN pin will be wrong.
Example
◆ hal_adc_read()
err_t hal_adc_read |
( |
handle_t * |
handle, |
|
|
uint16_t * |
readDatabuf |
|
) |
| |
- Parameters
-
[in] | handle | ADC handle. |
[out] | readDatabuf | Data buffer to place read data in. |
- Returns
- The function can return one of the values defined by hal_adc_err_t, which is size dependant on the architecture.
- Precondition
- Make sure that adequate memory has been allocated beforehand. See hal_adc_open definition for detailed explanation.
Example
◆ hal_adc_read_voltage()
err_t hal_adc_read_voltage |
( |
handle_t * |
handle, |
|
|
float * |
readDatabuf |
|
) |
| |
- Parameters
-
[in] | handle | ADC handle. |
[out] | readDatabuf | Data buffer to place read data in. |
- Returns
- The function can return one of the values defined by hal_adc_err_t, which is size dependant on the architecture.
- Precondition
- Make sure that adequate memory has been allocated beforehand. See hal_adc_open definition for detailed explanation.
Example
◆ hal_adc_close()
err_t hal_adc_close |
( |
handle_t * |
handle | ) |
|
Closes ADC HAL layer object, clears all buffers used by object and clears config.
- Parameters
-
[in,out] | handle | ADC handle. |
- Returns
- Nothing.
Example