资源描述:
《STM32定时器触发DMA采集捕获输入值》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、intmain(void){////系统初始化//system_init();//时钟初始化drv_rcc_init(0,0,64,APB1_PRESC_2,APB2_PRESC_1,0x08000000);hal_timer_init(5000);//TIM1配置为编码器模式DMA触发请求为外部其他定时的触发输出//TIM4配置为触发输出用于定时器给一个触发信号到TIM1//输入通道引脚初始化drv_rcc_ahb1_clk_enable(RCC_AHBENR_GPIOEEN);drv_gpio_alternate_fu
2、nction_init(GPIOE,GPIO_PIN_9,GPIO_PUPD_PULL,GPIO_OTYPE_OD,GPIO_SPEED_MID);drv_gpio_alternate_function_init(GPIOE,GPIO_PIN_11,GPIO_PUPD_PULL,GPIO_OTYPE_OD,GPIO_SPEED_MID);drv_gpio_alternate_function_connect(GPIOE,GPIO_PINSOURCE9,GPIO_AF2_TIM1);drv_gpio_alternate_fu
3、nction_connect(GPIOE,GPIO_PINSOURCE11,GPIO_AF2_TIM1);//TIM1初始化drv_rcc_apb2_clk_enable(RCC_APB2ENR_TIM1EN);drv_timer_base_init(TIM1,0,0xFFFF,TIM_EDGE_CNT_MODE_UP);drv_timer_select_input_trigger(TIM1,TIM_TS_ITR3);drv_timer_select_slave_mode(TIM1,TIM_SLAVE_MODE_EQEP_
4、3);//TIM_SLAVE_MODE_TRIGGER//输入通道配置drv_timer_ic1_init(TIM1,TIM_IC_POLARITY_RISING,TIM_IC_PSC_DIV_1,TIM_IC_SELECTION_1,Filter_NO);drv_timer_ic2_init(TIM1,TIM_IC_POLARITY_RISING,TIM_IC_PSC_DIV_1,TIM_IC_SELECTION_1,Filter_NO);drv_timer_ic1_enable(TIM1);drv_timer_ic2_
5、enable(TIM1);//TIM定时器配置TIM1->DIER.bit.TDE=1;//使能触发DMA请求TIM1->DCR.bit.DBL=0;//传输个数TIM1->DCR.bit.DBA=9;//基地址为TIM1->CNT//TIM1DMA初始化DMA1CHANNEL4:TIM1_TRIGdrv_rcc_ahb1_clk_enable(RCC_AHBENR_DMA1EN);drv_dma_stream_deinit(DMA1_Channel4);drv_dma_stream_init(DMA1_Channel4,
6、(UINT32)g_TimerCntBuffer,(UINT32)(&(TIM1->CNT)),5,DMA_CIRC_MODE_ENABLE,DMA_CHANNEL_PRIORITY_VERY_HIGH,DMA_DIR_PERIPH_TO_MEM,DMA_DATA_WIDTH_WORD);drv_dma_stream_enable(DMA1_Channel4);//TIM4初始化drv_rcc_apb1_clk_enable(RCC_APB1ENR_TIM4EN);drv_timer_base_init(TIM4,1000
7、000,5000,TIM_EDGE_CNT_MODE_UP);drv_timer_select_output_trigger(TIM4,TIM_TRGOSource_Update);//根新事件作为触发输出drv_timer_enable(TIM1);drv_timer_enable(TIM4);while(1){//hal_watchdog_feed();}}