📄 stm8l15x_adc.c
字号:
/* set the External Trigger Edge Sensitivity and the external event
selection */
ADCx->CR2 |= (uint8_t)( (uint8_t)ADC_ExtTRGSensitivity | \
(uint8_t)ADC_ExtEventSelection);
}
/**
* @}
*/
/** @defgroup ADC_Group2 Analog Watchdog configuration functions
* @brief Analog Watchdog configuration functions
*
@verbatim
===============================================================================
Analog Watchdog configuration functions
===============================================================================
This section provides functions allowing to configure the Analog Watchdog
(AWD) feature in the ADC.
A typical configuration Analog Watchdog is done following these steps :
1. the ADC guarded channel is selected using the
ADC_AnalogWatchdogChannelSelect() function.
2. The Analog watchdog lower and higher threshold are configured using the
ADC_AnalogWatchdogThresholdsConfig() function.
Note : Both AWD selection and thresholds can be configured with one unique
function ADC_AnalogWatchdogConfig(), which is kept for firmware
compatibility reason.
@endverbatim
* @{
*/
/**
* @brief Configures the channel to be checked by the Analog watchdog.
* @param ADCx where x can be 1 to select the specified ADC peripheral.
* @param ADC_AnalogWatchdogSelection : Specifies the channel to be checked
* by the Analog watchdog.
* This parameter can be one of the following values:
* @arg ADC_AnalogWatchdogSelection_Channel0: AWD affected to Channel 0
* @arg ADC_AnalogWatchdogSelection_Channel1: AWD affected to Channel 1
* @arg ADC_AnalogWatchdogSelection_Channel2: AWD affected to Channel 2
* @arg ADC_AnalogWatchdogSelection_Channel3: AWD affected to Channel 3
* @arg ADC_AnalogWatchdogSelection_Channel4: AWD affected to Channel 4
* @arg ADC_AnalogWatchdogSelection_Channel5: AWD affected to Channel 5
* @arg ADC_AnalogWatchdogSelection_Channel6: AWD affected to Channel 6
* @arg ADC_AnalogWatchdogSelection_Channel7: AWD affected to Channel 7
* @arg ADC_AnalogWatchdogSelection_Channel8: AWD affected to Channel 8
* @arg ADC_AnalogWatchdogSelection_Channel9: AWD affected to Channel 9
* @arg ADC_AnalogWatchdogSelection_Channel10: AWD affected to Channel 10
* @arg ADC_AnalogWatchdogSelection_Channel11: AWD affected to Channel 11
* @arg ADC_AnalogWatchdogSelection_Channel12: AWD affected to Channel 12
* @arg ADC_AnalogWatchdogSelection_Channel13: AWD affected to Channel 13
* @arg ADC_AnalogWatchdogSelection_Channel14: AWD affected to Channel 14
* @arg ADC_AnalogWatchdogSelection_Channel15: AWD affected to Channel 15
* @arg ADC_AnalogWatchdogSelection_Channel16: AWD affected to Channel 16
* @arg ADC_AnalogWatchdogSelection_Channel17: AWD affected to Channel 17
* @arg ADC_AnalogWatchdogSelection_Channel18: AWD affected to Channel 18
* @arg ADC_AnalogWatchdogSelection_Channel19: AWD affected to Channel 19
* @arg ADC_AnalogWatchdogSelection_Channel20: AWD affected to Channel 20
* @arg ADC_AnalogWatchdogSelection_Channel21: AWD affected to Channel 21
* @arg ADC_AnalogWatchdogSelection_Channel22: AWD affected to Channel 22
* @arg ADC_AnalogWatchdogSelection_Channel23: AWD affected to Channel 23
* @ref ADC_AnalogWatchdogSelection_TypeDef enumeration.
* @retval None
*/
void ADC_AnalogWatchdogChannelSelect(ADC_TypeDef* ADCx,
ADC_AnalogWatchdogSelection_TypeDef ADC_AnalogWatchdogSelection)
{
/* Check the parameters */
assert_param(IS_ADC_ANALOGWATCHDOG_SELECTION(ADC_AnalogWatchdogSelection));
/* Reset the CHSEL bits */
ADCx->CR3 &= ((uint8_t)~ADC_CR3_CHSEL);
/* Select the channel to be checked by the Analog watchdog */
ADCx->CR3 |= (uint8_t)ADC_AnalogWatchdogSelection;
}
/**
* @brief Configures the high and low thresholds of the Analog watchdog.
* @param ADCx where x can be 1 to select the specified ADC peripheral.
* @param HighThreshold: Analog watchdog High threshold value.
* This parameter must be a 12bit value.
* @param LowThreshold: Analog watchdog Low threshold value.
* This parameter must be a 12bit value.
* @retval None
*/
void ADC_AnalogWatchdogThresholdsConfig(ADC_TypeDef* ADCx, uint16_t HighThreshold, uint16_t LowThreshold)
{
/* Check the parameters */
assert_param(IS_ADC_THRESHOLD(HighThreshold));
assert_param(IS_ADC_THRESHOLD(LowThreshold));
/* Set the ADC high threshold */
ADCx->HTRH = (uint8_t)(HighThreshold >> 8);
ADCx->HTRL = (uint8_t)(HighThreshold);
/* Set the ADC low threshold */
ADCx->LTRH = (uint8_t)(LowThreshold >> 8);
ADCx->LTRL = (uint8_t)(LowThreshold);
}
/**
* @brief Configures the Analog watchdog.
* @param ADCx where x can be 1 to select the specified ADC peripheral.
* @param ADC_AnalogWatchdogSelection : Specifies the channel to be checked
* by the Analog watchdog.
* This parameter can be one of the following values:
* @arg ADC_AnalogWatchdogSelection_Channel0: AWD affected to Channel 0
* @arg ADC_AnalogWatchdogSelection_Channel1: AWD affected to Channel 1
* @arg ADC_AnalogWatchdogSelection_Channel2: AWD affected to Channel 2
* @arg ADC_AnalogWatchdogSelection_Channel3: AWD affected to Channel 3
* @arg ADC_AnalogWatchdogSelection_Channel4: AWD affected to Channel 4
* @arg ADC_AnalogWatchdogSelection_Channel5: AWD affected to Channel 5
* @arg ADC_AnalogWatchdogSelection_Channel6: AWD affected to Channel 6
* @arg ADC_AnalogWatchdogSelection_Channel7: AWD affected to Channel 7
* @arg ADC_AnalogWatchdogSelection_Channel8: AWD affected to Channel 8
* @arg ADC_AnalogWatchdogSelection_Channel9: AWD affected to Channel 9
* @arg ADC_AnalogWatchdogSelection_Channel10: AWD affected to Channel 10
* @arg ADC_AnalogWatchdogSelection_Channel11: AWD affected to Channel 11
* @arg ADC_AnalogWatchdogSelection_Channel12: AWD affected to Channel 12
* @arg ADC_AnalogWatchdogSelection_Channel13: AWD affected to Channel 13
* @arg ADC_AnalogWatchdogSelection_Channel14: AWD affected to Channel 14
* @arg ADC_AnalogWatchdogSelection_Channel15: AWD affected to Channel 15
* @arg ADC_AnalogWatchdogSelection_Channel16: AWD affected to Channel 16
* @arg ADC_AnalogWatchdogSelection_Channel17: AWD affected to Channel 17
* @arg ADC_AnalogWatchdogSelection_Channel18: AWD affected to Channel 18
* @arg ADC_AnalogWatchdogSelection_Channel19: AWD affected to Channel 19
* @arg ADC_AnalogWatchdogSelection_Channel20: AWD affected to Channel 20
* @arg ADC_AnalogWatchdogSelection_Channel21: AWD affected to Channel 21
* @arg ADC_AnalogWatchdogSelection_Channel22: AWD affected to Channel 22
* @arg ADC_AnalogWatchdogSelection_Channel23: AWD affected to Channel 23
* @param HighThreshold: Analog watchdog High threshold value.
* This parameter must be a 12bit value.
* @param LowThreshold: Analog watchdog Low threshold value.
* This parameter must be a 12bit value.
* @retval None
*/
void ADC_AnalogWatchdogConfig(ADC_TypeDef* ADCx,
ADC_AnalogWatchdogSelection_TypeDef ADC_AnalogWatchdogSelection,
uint16_t HighThreshold,
uint16_t LowThreshold)
{
/* Check the parameters */
assert_param(IS_ADC_ANALOGWATCHDOG_SELECTION(ADC_AnalogWatchdogSelection));
assert_param(IS_ADC_THRESHOLD(HighThreshold));
assert_param(IS_ADC_THRESHOLD(LowThreshold));
/*Reset the CHSEL bits */
ADCx->CR3 &= ((uint8_t)~ADC_CR3_CHSEL);
/* Select the channel to be checked by the Analog watchdog.*/
ADCx->CR3 |= (uint8_t)ADC_AnalogWatchdogSelection;
/* Set the ADC high threshold */
ADCx->HTRH = (uint8_t)(HighThreshold >> 8);
ADCx->HTRL = (uint8_t)(HighThreshold);
/* Set the ADC low threshold */
ADCx->LTRH = (uint8_t)(LowThreshold >> 8);
ADCx->LTRL = (uint8_t)LowThreshold;
}
/**
* @}
*/
/** @defgroup ADC_Group3 Temperature Sensor & Vrefint (Voltage Reference
* internal) management functions
* @brief Temperature Sensor & Vrefint (Voltage Reference internal)
* management functions
*
@verbatim
===============================================================================
Temperature Sensor & Vrefint (Voltage Reference internal) management functions
===============================================================================
This section provides functions allowing to enable/ disable the internal
connections between the ADC and the Temperature Sensor and the Vrefint source.
A typical configuration to get the Temperature sensor or/and Vrefint channels
voltages is done following these steps :
1. Enable the internal connection of Temperature sensor or/and Vrefint sources
with the ADC channels:
- for the Temperature sensor using ADC_TempSensorCmd() function.
- for the Internal Voltage reference using ADC_VrefintCmd() function.
2. Enable the ADC_Channel_TempSensor and/or ADC_Channel_Vrefint channels
using ADC_ChannelCmd()function.
3. Get the voltage values, using ADC_GetConversionValue().
@endverbatim
* @{
*/
/**
* @brief Enables or disables the Temperature sensor internal reference.
* @param NewState : new state of the Temperature sensor internal reference.
* This parameter can be: ENABLE or DISABLE.
* @retval None
*/
void ADC_TempSensorCmd(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NewState));
if (NewState != DISABLE)
{
/*Enable the Temperature sensor internal reference.*/
ADC1->TRIGR[0] |= (uint8_t)(ADC_TRIGR1_TSON);
}
else
{
/*Disable the Temperature sensor internal reference.*/
ADC1->TRIGR[0] &= (uint8_t)(~ADC_TRIGR1_TSON);
}
}
/**
* @brief Enables or disables the Internal Voltage reference.
* @param NewState : new state of the Internal Voltage reference.
* This parameter can be: ENABLE or DISABLE.
* @retval None
*/
void ADC_VrefintCmd(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NewState));
if (NewState != DISABLE)
{
/* Enable the Internal Voltage reference.*/
ADC1->TRIGR[0] |= (uint8_t)(ADC_TRIGR1_VREFINTON);
}
else
{
/* Disable the Internal Voltage reference.*/
ADC1->TRIGR[0] &= (uint8_t)(~ADC_TRIGR1_VREFINTON);
}
}
/**
* @}
*/
/** @defgroup ADC_Group4 Channels Configuration functions
* @brief Channels Configuration functions
*
@verbatim
===============================================================================
Channels Configuration functions
===============================================================================
This section provides functions allowing to:
- Enable or disable the ADC channel using ADC_ChannelCmd() function,
- Configure the channels sampling times using ADC_SamplingTimeConfig()
function.
Note: there are 2 sampling times configuration values :
- 1st Group value : for channels 0..23
- 2nd Group value : for channels 24..27 (depending on the MCU
package density) and Temperature Sensor and Vrefint channels.
- Configure the channels Schmitt Trigger for each channel using
ADC_SchmittTriggerConfig() function.
- Get the current ADC conversion value.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -