问答

汇集网友智慧,解决技术难题

21ic问答首页 - TAG - 定时器触发
  • 关于GD32H757 ADC定时器触发+DMA 配置后DMA的数据不更新 sos

    void ADC_rcu_config(void) { /* enable GPIO clock */ rcu_periph_clock_enable(RCU_GPIOA); /* enable ADC clock */ rcu_periph_clock_enable(RCU_ADC0); /* enable DMA clock */ rcu_periph_clock_enable(RCU_DMA0); rcu_periph_clock_enable(RCU_DMAMUX); /* enable trigsel clock */ rcu_periph_clock_enable(RCU_TRIGSEL); /* enable timer1 clock */ rcu_periph_clock_enable(RCU_TIMER1); rcu_timer_clock_prescaler_config(RCU_TIMER_PSC_MUL4); } /*! \brief configure the GPIO peripheral \param[in] none \param[out] none \retval none */ void ADC_GPIO_Config(void) { /* config the GPIO as analog mode */ /* */ gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, AirPress_PIN | IExpValve_PIN); } /*! \brief configure the TIMER peripheral \param[in] none \param[out] none \retval none */ void timer_config(void) { timer_oc_parameter_struct timer_ocintpara; timer_parameter_struct timer_initpara; /* enable trigsel clock */ rcu_periph_clock_enable(RCU_TRIGSEL); /* enable timer1 clock */ rcu_periph_clock_enable(RCU_TIMER1); rcu_timer_clock_prescaler_config(RCU_TIMER_PSC_MUL4); /* TIMER1 configuration */ timer_initpara.prescaler = 300-1; timer_initpara.alignedmode = TIMER_COUNTER_EDGE; timer_initpara.counterdirection = TIMER_COUNTER_UP; timer_initpara.period = 500-1; timer_initpara.clockdivision = TIMER_CKDIV_DIV1; timer_initpara.repetitioncounter = 0; timer_init(TIMER1, &timer_initpara); /* CH0 configuration in PWM mode1 */ timer_ocintpara.ocpolarity = TIMER_OC_POLARITY_HIGH; timer_ocintpara.outputstate = TIMER_CCX_ENABLE; timer_channel_output_config(TIMER1, TIMER_CH_1, &timer_ocintpara); timer_channel_output_pulse_value_config(TIMER1, TIMER_CH_1, 100); timer_channel_output_mode_config(TIMER1, TIMER_CH_1, TIMER_OC_MODE_PWM1); timer_channel_output_shadow_config(TIMER1, TIMER_CH_1, TIMER_OC_SHADOW_DISABLE); } /*! \brief configure the DMA peripheral \param[in] none \param[out] none \retval none */ void ADC_DMA_Config(void) { /* ADC_DMA_channel configuration */ dma_single_data_parameter_struct dma_single_data_parameter; /* ADC DMA_channel configuration */ dma_deinit(DMA0, DMA_CH0); /* initialize DMA single data mode */ dma_single_data_parameter.request = DMA_REQUEST_ADC0; dma_single_data_parameter.periph_addr = (uint32_t)(&ADC_RDATA(ADC0)); dma_single_data_parameter.periph_inc = DMA_PERIPH_INCREASE_DISABLE; dma_single_data_parameter.memory0_addr = (uint32_t)(&adc_value); dma_single_data_parameter.memory_inc = DMA_MEMORY_INCREASE_ENABLE; dma_single_data_parameter.periph_memory_width = DMA_PERIPH_WIDTH_32BIT; dma_single_data_parameter.direction = DMA_PERIPH_TO_MEMORY; dma_single_data_parameter.number = 2; dma_single_data_parameter.priority = DMA_PRIORITY_HIGH; dma_single_data_mode_init(DMA0, DMA_CH0, &dma_single_data_parameter); /* enable DMA circulation mode 循环模式*/ dma_circulation_enable(DMA0, DMA_CH0); /* enable DMA channel */ dma_channel_enable(DMA0, DMA_CH0); } /*! \brief configure the ADC peripheral \param[in] none \param[out] none \retval none */ void ADC_Config(void) { /* reset ADC */ adc_deinit(ADC0); /* ADC clock config */ adc_clock_config(ADC0, ADC_CLK_SYNC_HCLK_DIV6); /* ADC contineous function enable */ adc_special_function_config(ADC0, ADC_CONTINUOUS_MODE, DISABLE); /* ADC scan mode enable */ adc_special_function_config(ADC0, ADC_SCAN_MODE, ENABLE); /* ADC resolution config */ adc_resolution_config(ADC0, ADC_RESOLUTION_14B); /* ADC data alignment config */ adc_data_alignment_config(ADC0, ADC_DATAALIGN_RIGHT); /* ADC channel length config */ adc_channel_length_config(ADC0, ADC_REGULAR_CHANNEL, 2); /* ADC regular channel config */ adc_regular_channel_config(ADC0, 0, ADC_CHANNEL_15, 240); adc_regular_channel_config(ADC0, 1, ADC_CHANNEL_14, 240); /* ADC trigger config */ adc_external_trigger_config(ADC0, ADC_REGULAR_CHANNEL, EXTERNAL_TRIGGER_RISING); /* clear the ADC flag */ adc_interrupt_flag_clear(ADC0, ADC_INT_FLAG_EOC); adc_interrupt_flag_clear(ADC0, ADC_INT_FLAG_EOIC); /* ADC DMA function enable */ adc_dma_request_after_last_enable(ADC0); adc_dma_mode_enable(ADC0); /* enable ADC interface */ adc_enable(ADC0); /* wait for ADC stability */ LCD_delay_ms(1); /* ADC calibration mode config */ adc_calibration_mode_config(ADC0, ADC_CALIBRATION_OFFSET_MISMATCH); /* ADC calibration number config */ adc_calibration_number(ADC0, ADC_CALIBRATION_NUM1); /* ADC calibration and reset calibration */ adc_calibration_enable(ADC0); } /*! \brief configure the TRIGSEL peripheral \param[in] none \param[out] none \retval none */ void trigsel_config(void) { trigsel_init(TRIGSEL_OUTPUT_ADC0_INSTRG, TRIGSEL_INPUT_TIMER1_CH1); } /** \brief configure the nested vectored interrupt controller \param[in] none \param[out] none \retval none */ void nvic_config(void) { nvic_irq_enable(ADC0_1_IRQn, 10, 0); } void BSP_ADC_Init(void) { ADC_rcu_config(); ADC_GPIO_Config(); timer_config(); trigsel_config(); // nvic_config(); ADC_DMA_Config(); ADC_Config(); timer_enable(TIMER1); } 配置完后 ,数组里没有数据 ,当时测试时也打开过中断,但中断没有触发,请坛友帮忙看看

    TI ADC 定时器触发 GD32H7 DMA 更新

    1022浏览量 0回复量 关注量