我是新手,就是想在PB10口输出pwm波,PB1和PB11输出高电平,下面是配置程序,怎么调都不行。我网上查,感觉是AFIO配置问题,可是怎么配置呢,我也不知道到底该怎么开时钟,谢谢大家了,希望指教一下。
#include "pwm_output.h" static void TIM2_GPIO_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOA,ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOB, &GPIO_InitStructure); } static void TIM2_Mode_Config(void){ TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; u16CCR3_Val = 1000; TIM_TimeBaseStructure.TIM_Period = 1999; TIM_TimeBaseStructure.TIM_Prescaler = 6; TIM_TimeBaseStructure.TIM_ClockDivision = 0x0 ; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse= CCR3_Val; TIM_OC3Init(TIM2,&TIM_OCInitStructure); TIM_OC3PreloadConfig(TIM2,TIM_OCPreload_Enable); TIM_ARRPreloadConfig(TIM2,ENABLE); TIM_Cmd(TIM2, ENABLE); } void TIM2_PWM_Init(void){ TIM2_GPIO_Config(); TIM2_Mode_Config(); }
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
大神,我想问的就是怎么AFIO初始化和重映射,这两句函数怎么写? 我网上找的库函数后添加AFIO和重映射之后,依然不管用。
一周热门 更多>