本帖最后由 abs0213 于 2020-3-4 22:33 编辑
stm32L051退出stop模式后,ADC采集的数据刚开始正常,等过了几分钟后,数据一直不会变化
//这是进入stop模式前的外设配置
void system_config_before_stop(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* Enable Ultra low power mode */
HAL_PWREx_EnableUltraLowPower();
/* Enable the fast wake up from Ultra low power mode */
HAL_PWREx_EnableFastWakeUp();
/* Select HSI as system clock source after Wake Up from Stop mode */
__HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_HSI);
//PB2.3.4
GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
//pc15
GPIO_InitStruct.Pin = GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
//PH0.1
GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
//关灯
//HAL_GPIO_WritePin(GPIOB, GPIO_PIN_12, GPIO_PIN_RESET);
// HAL_ADC_Stop_DMA(&hadc);
//关闭时钟
__HAL_RCC_ADC1_CLK_DISABLE();
__HAL_RCC_DMA1_CLK_DISABLE();
HAL_UART_MspDeInit(&huart1);
HAL_UART_MspDeInit(&hlpuart1);
__HAL_RCC_USART1_CLK_DISABLE();
__HAL_RCC_LPUART1_CLK_DISABLE();
__HAL_RCC_GPIOA_CLK_DISABLE();
__HAL_RCC_GPIOB_CLK_DISABLE();
__HAL_RCC_GPIOC_CLK_DISABLE();
__HAL_RCC_GPIOH_CLK_DISABLE();
HAL_TIM_Base_MspDeInit(&htim2);
__HAL_RCC_TIM2_CLK_DISABLE();
}
//这是退出stop模式的配置
void clock_config_after_stop(void)
{
/* Enable Power Control clock */
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_ADC1_CLK_ENABLE();
__HAL_RCC_DMA1_CLK_ENABLE();
HAL_UART_MspInit(&huart1);
HAL_UART_MspInit(&hlpuart1);
__HAL_RCC_LPUART1_CLK_ENABLE();
__HAL_RCC_USART1_CLK_ENABLE();
HAL_TIM_Base_MspInit(&htim2);
__HAL_RCC_TIM2_CLK_ENABLE();
/* The voltage scaling allows optimizing the power consumption when the device is
clocked below the maximum system frequency, to update the voltage scaling value
regarding system frequency refer to product datasheet. */
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
SystemClock_Config();
HAL_ADCEx_EnableVREFINT();
HAL_ADC_Init(&hadc);
HAL_DMA_Init(&hdma_adc);
MX_DMA_Init();
MX_ADC_Init();
HAL_UART_Receive_IT(&hlpuart1,(uint8_t *)&lpuart1.receive_temp,1);//接收LPUART的数�????
HAL_TIM_Base_Start_IT(&htim2);//�????启定时器2
}
|