完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
看参考手册比问谁都权威
|
|
|
|
我就是看着手册来写程序的,结果CH3和CH4的值一动不动的,手册上应该是支持的
|
|
|
|
手册上说的一般不会错的,楼主先找个例子测试一下
|
|
|
|
本帖最后由 刚声打火机 于 2015-10-19 09:11 编辑
两路都是可以捕获的哈 我公司产品中有实际应用 给你贴上源码 可以参考一下 #define TIM1_PRESCALER 2 typedef void (*tim1_cc_irq_t)(void); /* 使能TIM1 */ #define START_TIM1() do { RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); TIM_Cmd(TIM1, ENABLE); } while (0); /* 停止TIM1 */ #define STOP_TIM1() do { TIM_Cmd(TIM1, DISABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, DISABLE); } while (0); void bsp_tim1_init(void); void tim1_ch3_set_irq_callback(tim1_cc_irq_t func); void tim1_ch4_set_irq_callback(tim1_cc_irq_t func); static tim1_cc_irq_t __tim1_cc3_irq = NULL; static tim1_cc_irq_t __tim1_cc4_irq = NULL; /* +------------------------------------------+ * * | TIM1初始化 | * * +------------------------------------------+ */ void bsp_tim1_init(void) { TIM_ICInitTypeDef TIM_ICInitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; /* TIM1 clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); /* TIM1 CC CH3 */ bsp_gpio_init(GPIOA, GPIO_Pin_10, GPIO_Mode_AF, GPIO_Speed_50MHz, GPIO_OType_PP, GPIO_PuPd_UP); /* TIM1 CC CH4 */ bsp_gpio_init(GPIOA, GPIO_Pin_11, GPIO_Mode_AF, GPIO_Speed_50MHz, GPIO_OType_PP, GPIO_PuPd_UP); /* Connect TIM pins to AF2 */ GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_2); GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_2); TIM_TimeBaseStructure.TIM_Period = 0xFFFFFFFF; /* 累计 TIM_Period个频率后产生一个更新或者中断 */ TIM_TimeBaseStructure.TIM_Prescaler = TIM1_PRESCALER - 1; // 24M TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; // 采样分频 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; // 向上计数模式 TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); TIM_ICInitStructure.TIM_Channel = TIM_Channel_3; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; TIM_ICInitStructure.TIM_ICFilter = 0x0; TIM_ICInit(TIM1, &TIM_ICInitStructure); TIM_ICInitStructure.TIM_Channel = TIM_Channel_4; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1; TIM_ICInitStructure.TIM_ICFilter = 0x0; TIM_ICInit(TIM1, &TIM_ICInitStructure); TIM_Cmd(TIM1, ENABLE); TIM_ITConfig(TIM1, TIM_IT_CC3, ENABLE); TIM_ITConfig(TIM1, TIM_IT_CC4, ENABLE); nvic_config(TIM1_CC_IRQn, TIM1_CC_PRIOR, ENABLE); } /* +------------------------------------------+ * * | TIM1 CH3 初始化回调函数 | * * +------------------------------------------+ */ void tim1_ch3_set_irq_callback(tim1_cc_irq_t func) { __tim1_cc3_irq = func; } /* +------------------------------------------+ * * | TIM1 CH4 初始化回调函数 | * * +------------------------------------------+ */ void tim1_ch4_set_irq_callback(tim1_cc_irq_t func) { __tim1_cc4_irq = func; } /* +------------------------------------------+ * * | TIM1 CC 中断 | * * +------------------------------------------+ */ void TIM1_CC_IRQHandler(void) { if (TIM_GetITStatus(TIM1, TIM_IT_CC3) == SET) { TIM_ClearITPendingBit(TIM1, TIM_IT_CC3); if (NULL != __tim1_cc3_irq) { (__tim1_cc3_irq)(); } } if (TIM_GetITStatus(TIM1, TIM_IT_CC4) == SET) { TIM_ClearITPendingBit(TIM1, TIM_IT_CC4); if (NULL != __tim1_cc4_irq) { (__tim1_cc4_irq)(); } } } 补充一下: bsp_gpio_init() 这个函数我自己封装过,定义是这样的: /* +------------------------------------------+ * * | 封装了一层GPIO初始化函数 | * * +------------------------------------------+ */ /* GPIO Group Periph Manager*/ typedef struct ggm_s { GPIO_TypeDef *gpio_x; u32 periph; vu32 bit_map; } ggpm_t; static ggpm_t ggpm[MAX_GPIO_GROUP_NUM] = { {GPIOA, RCC_AHBPeriph_GPIOA, 0x0}, {GPIOB, RCC_AHBPeriph_GPIOB, 0x0}, {GPIOC, RCC_AHBPeriph_GPIOC, 0x0}, {GPIOD, RCC_AHBPeriph_GPIOD, 0x0}, {GPIOE, RCC_AHBPeriph_GPIOE, 0x0}, {GPIOF, RCC_AHBPeriph_GPIOF, 0x0}, }; void bsp_gpio_init(GPIO_TypeDef *gpio_x, u32 gpio_pin, GPIOMode_TypeDef mode, GPIOSpeed_TypeDef speed, GPIOOType_TypeDef otype, GPIOPuPd_TypeDef pupd) { GPIO_InitTypeDef gpio_init_struct; int i = 0; for (i = 0; i < (sizeof(ggpm) / sizeof(ggpm_t)); i++) { if (ggpm.gpio_x == gpio_x) { if ( ! (ggpm.bit_map & GPIO_PIN_NUM_MASK) ) { RCC_AHBPeriphClockCmd(ggpm.periph, ENABLE); } ggpm.bit_map |= gpio_pin; gpio_init_struct.GPIO_Pin = gpio_pin; gpio_init_struct.GPIO_Mode = mode; gpio_init_struct.GPIO_Speed = speed; gpio_init_struct.GPIO_OType = otype; gpio_init_struct.GPIO_PuPd = pupd; GPIO_Init(gpio_x, &gpio_init_struct); break; } } } |
|
|
|
你这个代码封装的还是不错的 |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
STM32配合可编程加密芯片SMEC88ST的防抄板加密方案设计
1138 浏览 0 评论
2483 浏览 1 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
2273 浏览 3 评论
4916 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
2419 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-1-3 01:01 , Processed in 0.658455 second(s), Total 45, Slave 40 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号