我感觉是库函数的问题,因为库函数没有要求给他TIM3,参数只有数据
[mw_shl_code=c,true]void TIM_BDTRStructInit(TIM_BDTRInitTypeDef* TIM_BDTRInitStruct)
{
/* Set the default configuration */
TIM_BDTRInitStruct->TIM_OSSRState = TIM_OSSRState_Disable;
TIM_BDTRInitStruct->TIM_OSSIState = TIM_OSSIState_Disable;
TIM_BDTRInitStruct->TIM_LOCKLevel = TIM_LOCKLevel_OFF;
TIM_BDTRInitStruct->TIM_DeadTime = 0x00;
TIM_BDTRInitStruct->TIM_Break = TIM_Break_Disable;
TIM_BDTRInitStruct->TIM_BreakPolarity = TIM_BreakPolarity_Low;
TIM_BDTRInitStruct->TIM_AutomaticOutput = TIM_AutomaticOutput_Disable;
}[/mw_shl_code]
没有要求让我把TIM1给他,那么他如何知道我是要初始化TIM1的呢?其他部分代码应该没有问题,因为使用tim3时可以输出
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
void TIM1_PWM_Init(u32 arr, u32 psc)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE); //TIM1时钟使能
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE); //使能PORTB时钟
GPIO_PinAFConfig(GPIOB,GPIO_PinSource13, GPIO_AF_TIM1);//PB13 复用为TIM1
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13; //GPIOB13
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; //复用功能
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; //速度50MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽复用输出
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //上拉
GPIO_Init(GPIOB, &GPIO_InitStructure); //初始化 B13
TIM_TimeBaseStructure.TIM_Prescaler = psc; //定时器分频
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;//向上计数模式
TIM_TimeBaseStructure.TIM_Period = arr; //自动重装值
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); //初始化定时器1
//初始化 TIM1 Channel WM 模式
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //PWM调制模式1
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;//比较输出使能
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; //输出极性低
TIM_OC1Init(TIM1, &TIM_OCInitStructure); //初始化外设 TIM1 OC1
TIM_OC1PreloadConfig(TIM1,TIM_OCPreload_Enable); //使能预装载寄存器
TIM_ARRPreloadConfig(TIM1,ENABLE); //ARPE使能
TIM_CtrlPWMOutputs(TIM1,ENABLE); //高级定时器 还需要设置一个MOE位以使能主输出 否则不会输出  WM
TIM_Cmd(TIM1,ENABLE); //使能TIM1
}
一周热门 更多>