问大神一个问题 我有个的代码 在
STM32103系列中可以使用 波形可以实现 输出 。 到了stm322xx波形不能输出 ,以下是f2xx的代码。(我自己找了测试了这个引脚,通过延迟来实现波形输出,成功了,是不是说明这个引脚没被占用?当然自己也看了。应该是这个引脚没有被占用)。
(1)放在一个platform.c中的代码
- void OUTGPIO_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- OUTGPIO_CLK_INIT(OUTGPIO_CLK, ENABLE);
- GPIO_InitStructure.GPIO_Pin = OUTGPIO_PIN;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //接上拉电阻
- GPIO_Init(OUTGPIO_PORT, &GPIO_InitStructure);
- }
复制代码
我觉得可能是GPIO引脚配置的问题。
- void tiM_Config(uint16_t Channel2Pulse)//, uint16_t Channel3Pulse
- {
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- TIM_OCInitTypeDef TIM_OCInitStructure;
-
- /* TIM4 clock enable */
- TIME4_CLK_INIT(TIME4_CLK, ENABLE);
-
- /* Time base configuration */
- TIM_TimeBaseStructure.TIM_Period = 999; //1KHz
- TIM_TimeBaseStructure.TIM_Prescaler = 0;
- TIM_TimeBaseStructure.TIM_ClockDivision = 0;
- TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
- TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
-
- TIM_PrescalerConfig(TIM4,50, TIM_PSCReloadMode_Immediate);
- /* Channel 2 Configuration in PWM mode */
- TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
- TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
- TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
- TIM_OCInitStructure.TIM_Pulse = Channel2Pulse;
- TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
- TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
- TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
- TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
- TIM_OC2Init(TIM4, &TIM_OCInitStructure);
- TIM_Cmd(TIM4, ENABLE);
- TIM_CtrlPWMOutputs(TIM4, ENABLE);
- }
复制代码
(3)然后我再main.c中直接使用的TIM_Config(400);函数。
希望大神给予指导。
一周热门 更多>