你好!
我想报告一个错误。
我尝试了 SDADC,但发现了一个错误。
此外,它应该代表“多模式”而不是“多模式”,并且 STM32CubeIDE 1.5.0(我正在使用)在 STM32CubeIDE 项目启动器中缺少校准选项。
解决这个问题。在“SDADC_init()”函数中写入此代码
- // Multi mode for SDADC1 and SDADC3
- if (HAL_SDADC_InjectedMultiModeConfigChannel(&hsdadc1, SDADC_MULTIMODE_SDADC1_SDADC3) != HAL_OK)
- {
- Error_Handler();
- }
例子:
- /**
- * @brief SDADC1 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_SDADC1_Init(void)
- {
- /* USER CODE BEGIN SDADC1_Init 0 */
- /* USER CODE END SDADC1_Init 0 */
- SDADC_ConfParamTypeDef ConfParamStruct = {0};
- /* USER CODE BEGIN SDADC1_Init 1 */
- /* USER CODE END SDADC1_Init 1 */
- /** Configure the SDADC low power mode, fast conversion mode,
- slow clock mode and SDADC1 reference voltage
- */
- hsdadc1.Instance = SDADC1;
- hsdadc1.Init.IdleLowPowerMode = SDADC_LOWPOWER_NONE;
- hsdadc1.Init.FastConversionMode = SDADC_FAST_CONV_DISABLE;
- hsdadc1.Init.SlowClockMode = SDADC_SLOW_CLOCK_DISABLE;
- hsdadc1.Init.ReferenceVoltage = SDADC_VREF_VDDA;
- hsdadc1.InjectedTrigger = SDADC_SOFTWARE_TRIGGER;
- if (HAL_SDADC_Init(&hsdadc1) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure the Injected Mode
- */
- if (HAL_SDADC_SelectInjectedDelay(&hsdadc1, SDADC_INJECTED_DELAY) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_SDADC_SelectInjectedTrigger(&hsdadc1, SDADC_SOFTWARE_TRIGGER) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_SDADC_InjectedConfigChannel(&hsdadc1, SDADC_CHANNEL_4|SDADC_CHANNEL_8
- |SDADC_CHANNEL_6, SDADC_CONTINUOUS_CONV_ON) != HAL_OK)
- {
- Error_Handler();
- }
- /** Set parameters for SDADC configuration 0 Register
- */
- ConfParamStruct.InputMode = SDADC_INPUT_MODE_SE_ZERO_REFERENCE;
- ConfParamStruct.Gain = SDADC_GAIN_1;
- ConfParamStruct.CommonMode = SDADC_COMMON_MODE_VSSA;
- ConfParamStruct.Offset = 0;
- if (HAL_SDADC_PrepareChannelConfig(&hsdadc1, SDADC_CONF_INDEX_0, &ConfParamStruct) != HAL_OK)
- {
- Error_Handler();
- }
- /** Set parameters for SDADC configuration 1 Register
- */
- ConfParamStruct.InputMode = SDADC_INPUT_MODE_DIFF;
- if (HAL_SDADC_PrepareChannelConfig(&hsdadc1, SDADC_CONF_INDEX_1, &ConfParamStruct) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure the Injected Channel
- */
- if (HAL_SDADC_AssociateChannelConfig(&hsdadc1, SDADC_CHANNEL_4, SDADC_CONF_INDEX_0) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure the Injected Channel
- */
- if (HAL_SDADC_AssociateChannelConfig(&hsdadc1, SDADC_CHANNEL_8, SDADC_CONF_INDEX_1) != HAL_OK)
- {
- Error_Handler();
- }
- /** Configure the Injected Channel
- */
- if (HAL_SDADC_AssociateChannelConfig(&hsdadc1, SDADC_CHANNEL_6, SDADC_CONF_INDEX_1) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN SDADC1_Init 2 */
- // Multi mode for SDADC1 and SDADC3
- if (HAL_SDADC_InjectedMultiModeConfigChannel(&hsdadc1, SDADC_MULTIMODE_SDADC1_SDADC3) != HAL_OK)
- {
- Error_Handler();
- }
- // Calibration
- if (HAL_SDADC_CalibrationStart(&hsdadc1, SDADC_CALIBRATION_SEQ_1) != HAL_OK) {
- Error_Handler();
- }
- // Pool for the end of calibration
- if (HAL_SDADC_PollForCalibEvent(&hsdadc1, HAL_MAX_DELAY) != HAL_OK) {
- Error_Handler();
- }
- // Start interrupt mode
- if (HAL_SDADC_InjectedStart_IT(&hsdadc1) != HAL_OK) {
- Error_Handler();
- }
- /* USER CODE END SDADC1_Init 2 */
- }
也用于为 SDADC(在本例中为 SDADC1 和 SDADC3)使用多个中断。请使用此代码作为 NVIC 中断的回调函数。这里我有 3 个来自 SDADC1 的输入和 2 个来自 SDADC3 的输入。
- // When we got a measurement
- uint32_t CHANNEL = 4;
- uint16_t SD_ADC[6] = {0};
- void HAL_SDADC_InjectedConvCpltCallback(SDADC_HandleTypeDef *hsdadc){
- // CHANNEL will be 4, 6, 8 but randomly
- // SD_ADC for SDADC1 = [SDADC1_IN4, 0, SDADC1_IN6, SDADC3_IN6, SDADC1_IN8, SDADC3_IN8];
- if(hsdadc->Instance == SDADC1){
- SD_ADC[CHANNEL - 4] = HAL_SDADC_InjectedGetValue(hsdadc, &CHANNEL);
- }else if(hsdadc->Instance == SDADC3){
- SD_ADC[CHANNEL - 4 + 1] = HAL_SDADC_InjectedGetValue(hsdadc, &CHANNEL);
- }
- }
漏洞截图:
0
|
|
|
|