完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
int main(void)
{ /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_DMA_Init(); MX_ADC1_Init(); MX_TIM1_Init(); MX_TIM6_Init(); MX_USART1_UART_Init(); /* USER CODE BEGIN 2 */ HAL_ADCEx_Calibration_Start( hadc1);//ADC自校验 HAL_ADC_Start_DMA( hadc1,(uint32_t *)ADC_ConvertedData,ADC_SAMPLE);//启动AD转换并使能DMA传输和中断 HAL_TIM_Base_Start_IT( htim1); //初始化定时器中断 HAL_TIM_Base_Start_IT( htim6); //初始化定时器中断 HAL_TIMEx_PWMN_Start( htim1,TIM_CHANNEL_1); HAL_TIM_PWM_Start( htim1,TIM_CHANNEL_1); //__HAL_TIM_CLEAR_FLAG( htim6,TIM_FLAG_UPDATE); //这是关断定时器语句 /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ HAL_GPIO_TogglePin(K_OUT_GPIO_Port, K_OUT_Pin); HAL_GPIO_TogglePin(FAN_GPIO_Port, FAN_Pin); HAL_GPIO_TogglePin(K_IN_GPIO_Port, K_IN_Pin); HAL_GPIO_TogglePin(GPIOB,LED_LV_Pin); HAL_Delay(500); ADC_ConvertedData[3]; //htim1.Instance->sTimerxRegs[0].PERxR = 50000;//通过修改重装载值PER,从而修改PWM的频率 htim1 //htim1.Instance->sTimerxRegs[0].CMP1xR = 11504;//通过修改比较值CMP,从而修改占空比 } /* USER CODE END 3 */ } /** * @brief System Clock Configuration * @retval None */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; /** Configure the main internal regulator output voltage */ HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1); /** Initializes the CPU, AHB and APB busses clocks */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSIDiv = RCC_HSI_DIV1; RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1; RCC_OscInitStruct.PLL.PLLN = 16; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2; RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV4; if (HAL_RCC_OscConfig( RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB busses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig( RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) { Error_Handler(); } /** Initializes the peripherals clocks */ PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_ADC |RCC_PERIPHCLK_TIM1; PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1; PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK; PeriphClkInit.Tim1ClockSelection = RCC_TIM1CLKSOURCE_PLL; if (HAL_RCCEx_PeriphCLKConfig( PeriphClkInit) != HAL_OK) { Error_Handler(); } } /* USER CODE BEGIN 4 */ /* void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { // Prevent unused argument(s) compilation warning UNUSED(htim); HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_4); //只有定时器有中断,就翻转一次引脚电平 } */ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) { static unsigned char ledState = 0; if (htim == ( htim6)) { if (ledState == 0) HAL_GPIO_WritePin(GPIOB,GPIO_PIN_4,GPIO_PIN_RESET); else HAL_GPIO_WritePin(GPIOB,GPIO_PIN_4,GPIO_PIN_SET); ledState = !ledState; } } /* USER CODE END 4 */ |
|
相关推荐
1个回答
|
|
HAL_TIM_PeriodElapsedCallback 这个函数写只能写一次,在函数内判断是哪个定时器的中断。
你 HAL_TIM_PeriodElapsedCallback 写两次是不行的,第二次的不会被编译。 |
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1658 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1571 浏览 1 评论
998 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
695 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1617 浏览 2 评论
1877浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
663浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
529浏览 3评论
547浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
517浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-29 10:28 , Processed in 0.968168 second(s), Total 79, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号