DMA不开中断读到的ADC值正常,开启DMA传输完成中断,程序不进DMA中断,程序死在某个地方了
#include "bsp_adc.h"
#include "USART0.h"
#include "iic.h"
volatile uint16_t adc_read_data[2]={0x0000};//DMAÊý¾Ý´æ·Å»º´æ adc_read_data_length
volatile uint16_t adc_data_dispose[adc_channel_number][adc_read_data_length]={0x0000};//ADCÊý¾Ý´¦Àí»º´æ
void ADC_GPIO_Config(void)
{
// ʹÄÜ GPIO ʱÖÓ
rcu_periph_clock_enable(RCU_GPIOA);
// ÅäÖÃ IO
gpio_mode_set(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO_PIN_0|GPIO_PIN_1);//PA0¡¢PA1 Ä£ÄâÊäÈë
}
void ADC_Mode_Config(void)
{
// ¿ªÆôADCʱÖÓ
rcu_periph_clock_enable(RCU_ADC1);
adc_clock_config(ADC_ADCCK_PCLK2_DIV8);//ʱÖÓ8·ÖƵ
adc_deinit();//¸´Î»ADCÅäÖÃ
adc_channel_length_config(ADC1,ADC_REGULAR_CHANNEL,2);//ADCͨµÀÊýÁ¿ÅäÖÃ
adc_regular_channel_config(ADC1,0, ADC_CHANNEL_0, ADC_SAMPLETIME_144);//ͨµÀÅäÖÃ
adc_regular_channel_config(ADC1,1, ADC_CHANNEL_1, ADC_SAMPLETIME_144);//ͨµÀÅäÖÃ
adc_external_trigger_config(ADC1,ADC_REGULAR_CHANNEL,ENABLE);//¹Ø±ÕÍⲿ´¥·¢
adc_data_alignment_config(ADC1,ADC_DATAALIGN_RIGHT);//Êý¾ÝÓÒ¶ÔÆë
adc_resolution_config(ADC1,ADC_RESOLUTION_12B);//12λ·Ö±æÂÊ
adc_dma_mode_enable(ADC1);//ADC0µÄDMAʹÄÜ
adc_dma_request_after_last_enable(ADC1);//
adc_special_function_config(ADC1,ADC_SCAN_MODE, ENABLE);//¶àͨµÀ¿ªÆôɨÃèģʽ
adc_special_function_config(ADC1,ADC_CONTINUOUS_MODE, ENABLE);//Ñ»·Á¬Ðø²É¼¯
adc_enable(ADC1);//ʹÄÜADC0
delay_ms(10);
adc_calibration_enable(ADC1);//ADC0У׼
adc_software_trigger_enable(ADC1, ADC_REGULAR_CHANNEL);//Èí¼þÆô¶¯×ª»»
}
void DMA_init(void){
dma_single_data_parameter_struct dma_init_struct;
/*¿ªÆôDMAʱÖÓ*/
rcu_periph_clock_enable(RCU_DMA1);//ʹÄÜDMA1ʱÖÓ
//DMA ADC½ÓÊÕÅäÖÃ
dma_deinit(DMA1, DMA_CH2);//¸´Î»DMA1ͨµÀ0
dma_init_struct.periph_addr = (uint32_t)(&ADC_RDATA(ADC1));//ÍâÉèµØÖ·
dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE;//ÍâÉèµØÖ·²»±ä
dma_init_struct.memory0_addr = (uint32_t)adc_read_data;//ÄÚ´æµØÖ·
dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE;//ÄÚ´æµØÖ·ÔöÁ¿Ä£Ê½
dma_init_struct.periph_memory_width = DMA_PERIPH_WIDTH_16BIT;//Êý¾Ý¿í¶È16λ
dma_init_struct.circular_mode=DMA_CIRCULAR_MODE_DISABLE;//DMA_CIRCULAR_MODE_ENABLE;//Ñ»·Ä£Ê½
dma_init_struct.direction = DMA_PERIPH_TO_MEMORY;//ÍâÉèµ½ÄÚ´æ
dma_init_struct.number = 2;//adc_read_data_length;//Êý¾Ý³¤¶È
dma_init_struct.priority = DMA_PRIORITY_HIGH;//ÓÅÏȼ¶¸ß
dma_single_data_mode_init(DMA1, DMA_CH2, dma_init_struct);//³õʼ»¯DMA1ͨµÀ0
dma_channel_subperipheral_select(DMA1, DMA_CH2, DMA_SUBPERI1);//DMAͨµÀÍâÉèÑ¡Ôñ
nvic_irq_enable(DMA1_Channel2_IRQn, 0, 1);//DMA1ͨµÀ0ÖжÏÓÅÏȼ¶ÅäÖÃ
dma_interrupt_flag_clear(DMA1,DMA_CH2,DMA_CHXCTL_FTFIE);//Çå³ýDMA1ͨµÀ0´«ÊäÍê³ÉÖжÏ
dma_interrupt_enable(DMA1,DMA_CH2,DMA_CHXCTL_FTFIE);//¿ªÆôDMA1ͨµÀ0´«ÊäÍê³ÉÖжÏ
dma_channel_enable(DMA1, DMA_CH2);//ʹÄÜDMA1ͨµÀ0(¿ªÆô½ÓÊÕ)
// nvic_irq_enable(DMA1_Channel0_IRQn, 1, 1);//DMA1ͨµÀ0ÖжÏÓÅÏȼ¶ÅäÖÃ
//
// dma_interrupt_flag_clear(DMA1,DMA_CH0,DMA_CHXCTL_FTFIE);//Çå³ýDMA1ͨµÀ0´«ÊäÍê³ÉÖжÏ
//
// dma_interrupt_enable(DMA1,DMA_CH0,DMA_CHXCTL_FTFIE);//¿ªÆôDMA1ͨµÀ0´«ÊäÍê³ÉÖжÏ
}
void ADC_Init(void)
{
ADC_GPIO_Config();
DMA_init();
ADC_Mode_Config();
}
void DMA1_Channel2_IRQHandler(void)
{
USART0SendByte(0x44);
if((dma_interrupt_flag_get(DMA1,DMA_CH2,DMA_CHXCTL_FTFIE)==SET)&&(dma_flag_get(DMA1,DMA_CH2,DMA_CHXCTL_FTFIE)==SET))//´«ÊäÍê³ÉÖжÏ
{
// for(adc_i=0;adc_i<adc_read_data_length;adc_i++){//½«µÚÒ»¸öͨµÀ´ÓDMA»º´æ¸´ÖƵ½ADC´¦Àí»º´æ
// adc_data_dispose[0][adc_i]=adc_read_data[adc_i*2];
// }
//
// for(adc_i=0;adc_i<adc_read_data_length;adc_i++){//½«µÚ¶þ¸öͨµÀ´ÓDMA»º´æ¸´ÖƵ½ADC´¦Àí»º´æ
// adc_data_dispose[1][adc_i]=adc_read_data[adc_i*2+1];
// }
//
// USART0SendByte(0xFF);
// USART0SendByte((uint8_t)(adc_data_dispose[0][6]>>8));//²âÊÔ
// USART0SendByte((uint8_t)adc_data_dispose[0][6]);//²âÊÔ
//
// USART0SendByte(0x66);
// USART0SendByte((uint8_t)(adc_data_dispose[1][7]>>8));//²âÊÔ
// USART0SendByte((uint8_t)adc_data_dispose[1][7]);//²âÊÔ
dma_interrupt_flag_clear(DMA1,DMA_CH2,DMA_CHXCTL_FTFIE);//Çå³ý´«ÊäÍê³ÉÖжÏ
}
}
|
|