器件:GD32F303CC 48pin
用Timer0_CH0输出PWM,触发ADC0。ADC0转换的数据用DMA传输。
在中断处理函数中让一个变量自加。debug,发现这个变量的值没有变化。应该没有进入中断函数去执行。请帮忙看看哪里有问题。
rcu_periph_clock_enable(RCU_GPIOA);
rcu_periph_clock_enable(RCU_AF);
rcu_periph_clock_enable(RCU_DMA0);
rcu_periph_clock_enable(RCU_ADC0);
rcu_adc_clock_config(RCU_CKADC_CKAPB2_DIV4);
rcu_periph_clock_enable(RCU_TIMER0);
gpio_init(GPIOA, GPIO_MODE_AIN, GPIO_OSPEED_MAX, GPIO_PIN_2);
nvic_priority_group_set(NVIC_PRIGROUP_PRE2_SUB2);
nvic_irq_enable(DMA0_Channel0_IRQn, 0, 0);
dma_parameter_struct dma_data_parameter;
dma_deinit(DMA0, DMA_CH0);//
// initialize DMA single data mode //
dma_data_parameter.periph_addr = (uint32_t)(&ADC_RDATA(ADC0));
dma_data_parameter.periph_inc = DMA_PERIPH_INCREASE_DISABLE;
dma_data_parameter.memory_addr = (uint32_t)(&adc_buf);
dma_data_parameter.memory_inc = DMA_MEMORY_INCREASE_ENABLE;
dma_data_parameter.periph_width = DMA_PERIPHERAL_WIDTH_8BIT;
dma_data_parameter.memory_width = DMA_MEMORY_WIDTH_8BIT;
dma_data_parameter.direction = DMA_PERIPHERAL_TO_MEMORY;
dma_data_parameter.number = 1024;
dma_data_parameter.priority = DMA_PRIORITY_HIGH;
dma_init(DMA0, DMA_CH0, &dma_data_parameter);
dma_interrupt_enable(DMA0, DMA_CH0, DMA_INT_FTF);//channel full transfer finish interrupt
dma_channel_enable(DMA0, DMA_CH0);
//ADC0 单次,非扫描,独立
adc_special_function_config(ADC0, ADC_SCAN_MODE, DISABLE);
adc_discontinuous_mode_config(ADC0, ADC_CHANNEL_DISCON_DISABLE, 1);
adc_regular_channel_config(ADC0, 0, ADC_CHANNEL_2, ADC_SAMPLETIME_1POINT5);
adc_external_trigger_config(ADC0, ADC_REGULAR_CHANNEL, ENABLE);
// ADC trigger source - Timer0_CH0
adc_external_trigger_source_config(ADC0, ADC_REGULAR_CHANNEL, ADC0_1_EXTTRIG_REGULAR_T0_CH0);
adc_data_alignment_config(ADC0,ADC_DATAALIGN_RIGHT);
adc_mode_config(ADC_MODE_FREE);
adc_channel_length_config(ADC0,ADC_REGULAR_CHANNEL,1);
adc_resolution_config(ADC0, ADC_RESOLUTION_8B);
adc_enable(ADC0);
delay_1ms(1);
adc_calibration_enable(ADC0);
adc_dma_mode_enable(ADC0);
void DMA0_Channel0_IRQHandler(void)
{
var++;
} |