前天STM32L052采样AD双通道切换问题,解决。 void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* AdcHandle) { /* Get the converted value of regular channel */ uwADCxConvertedValue = HAL_ADC_GetValue(AdcHandle); HAL_ADC_Stop_IT(&hadc); if(CH_dp==0) { CH_dp=1; ADC1->CHSELR = ADC_CHANNEL_2; } else { CH_dp=0; ADC1->CHSELR = ADC_CHANNEL_7; } HAL_ADC_Start_IT(&hadc); UART_Transmit_IT(&huart1, (uint8_t*)uwADCxConvertedValue, 4); } 但我发现把AD中断中的发送命令屏蔽掉就进不了AD中断 我程序,只用到AD、串口、TIM21中断,不可能出现死循环。 |
STM32L011D4芯片用SWD无法下载程序
求助:STM32L0系列标准库哪里下?
STM32L051低温时LPUART串口波特率异常
STM32L051单片机ADC如何彻底关闭?
STM32L051C8进入低功耗模式电流偏大
STM32L052C8T6通过I2C模拟读16位数
STM32L0的VLCD外接5V会有问题吗
求助!!使用STM32L073 IO口模拟IIC接口读写AT24CM01 程序不停...
STM32L072RB写Bank2 EEPROM不响应中断
STM32L031无法进入boot
void MX_ADC_Init(void)
{
ADC_ChannelConfTypeDef sConfig;
hadc.Instance = ADC1;
hadc.Init.OversamplingMode = ENABLE;
hadc.Init.Oversample.Ratio = ADC_OVERSAMPLING_RATIO_128;
hadc.Init.Oversample.RightBitShift = ADC_RIGHTBITSHIFT_3;
hadc.Init.Oversample.TriggeredMode = ADC_TRIGGEREDMODE_SINGLE_TRIGGER;
hadc.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV1;
hadc.Init.Resolution = ADC_RESOLUTION12b;
hadc.Init.SamplingTime = ADC_SAMPLETIME_7CYCLES_5;
hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc.Init.ContinuousConvMode = ENABLE;
hadc.Init.DiscontinuousConvMode = DISABLE;
hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIG_EDGE_NONE;
hadc.Init.DMAContinuousRequests = DISABLE;
hadc.Init.EOCSelection = EOC_SINGLE_CONV;
hadc.Init.Overrun = OVR_DATA_PRESERVED;
hadc.Init.LowPowerAutoWait = DISABLE;
hadc.Init.LowPowerFrequencyMode = ENABLE;
hadc.Init.LowPowerAutoPowerOff = DISABLE;
HAL_ADC_Init(&hadc);
/* USER CODE BEGIN 7 */
if (HAL_ADCEx_Calibration_Start(&hadc, ADC_SINGLE_ENDED) != HAL_OK)
{
Error_Handler();
}
/* USER CODE END 7 */
/**Configure for the selected ADC regular channel to be converted.
*/
sConfig.Channel = ADC_CHANNEL_7;
sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
HAL_ADC_ConfigChannel(&hadc, &sConfig);
}
原因不使用volatile修饰