请教stm32定时器的连续DMA装载模式
展开全部
int main( 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_function_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_function_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_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_enable( TIM1 );
//TIM
定时器配置
TIM1->DIER.bit.TDE = 1;
//
使能触发
DMA
请求
TIM1->DCR.bit.DBL = 0;
//
传输个数
TIM1->DCR.bit.DBA = 9;
//
基地址为
TIM1->CNT
//TIM1 DMA
初始化
DMA1 CHANNEL4 :TIM1_TRIG
drv_rcc_ahb1_clk_enable( RCC_AHBENR_DMA1EN );
drv_dma_stream_deinit( DMA1_Channel4 );
drv_dma_stream_init(
DMA1_Channel4,
(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, 1000000, 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( );
}
}
{
//
//
系统初始化
//
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_function_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_function_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_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_enable( TIM1 );
//TIM
定时器配置
TIM1->DIER.bit.TDE = 1;
//
使能触发
DMA
请求
TIM1->DCR.bit.DBL = 0;
//
传输个数
TIM1->DCR.bit.DBA = 9;
//
基地址为
TIM1->CNT
//TIM1 DMA
初始化
DMA1 CHANNEL4 :TIM1_TRIG
drv_rcc_ahb1_clk_enable( RCC_AHBENR_DMA1EN );
drv_dma_stream_deinit( DMA1_Channel4 );
drv_dma_stream_init(
DMA1_Channel4,
(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, 1000000, 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( );
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询