初级会员

- 积分
- 91
- 金钱
- 91
- 注册时间
- 2016-11-24
- 在线时间
- 32 小时
|
5金钱
本帖最后由 Gene 于 2016-12-13 17:14 编辑
在阅读“第十五章 驶入捕获实验”的过程中,有3个疑问,想请教一下大家:
1.初始化函数82行:GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽复用输出
既然是输入捕获,GPIO为什么配置成输出?不是应该配置为输入吗?
2.中断服务函数中147行:“TIM_OC1PolarityConfig(TIM5,TIM_ICPolarity_Rising); //CC1P=0 设置为上升沿捕获”
我查看固件手册以及“stm32f4xx_tim.h”中关于函数的说明,第二个形参“TIM_OCPolarity”只有2个可选值(见下面),
* @param TIM_OCPolarity: specifies the OC1 Polarity
* This parameter can be one of the following values:
* @arg TIM_OCPolarity_High: Output Compare active high
* @arg TIM_OCPolarity_Low: Output Compare active low
但是例程中有TIM_OCPolarity却取值“TIM_ICPolarity_Rising”,那请问关于库函数TIM_OC1PolarityConfig的定义,哪里有更详细的说明?
3.中断服务函数中150~156行:
TIM5CH1_CAPTURE_STA=0; //清空
TIM5CH1_CAPTURE_VAL=0;
TIM5CH1_CAPTURE_STA|=0X40; //标记捕获到了上升沿
TIM_Cmd(TIM5,DISABLE ); //关闭定时器5
TIM_SetCounter(TIM5,0);
TIM_OC1PolarityConfig(TIM5,TIM_ICPolarity_Falling); //CC1P=1 设置为下降沿捕获
TIM_Cmd(TIM5,ENABLE ); //使能定时器5
这里为什么要关闭定时器?
|
最佳答案
查看完整内容[请看2#楼]
1.GPIO的模式是: GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用功能
你说的那行代码在复用模式下应该是不起作用的。不必理睬。
2.在“stm32f4xx_tim.h”中有如下定义 #define TIM_OCPolarity_High ((uint16_t)0x0000)
#define TIM_OCPolarity_Low ((uint16_t)0x0002)
#define TIM_ICPolarity_Rising ((uint16_t)0x0000)
#define TIM_ICPolarity_Fall ...
|