STM32F407 ADC DMA模式,数据printf没传送过来,怎么回事

2019-07-21 01:59发布

#define ADC3_DR_Addr   ((uint32_t)0x4001224C)
__IO uint16_t ADCoverVaule;


void GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* ??GPIOCGPIOFGPIOG??*/
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOG | RCC_AHB1Periph_GPIOF, ENABLE);
GPIO_StructInit(&GPIO_InitStructure);

/*??????????*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOF, &GPIO_InitStructure);
            
}

/*************************************************
                        
*************************************************/
void ADC_Config(void)
{
ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC3, ENABLE); 
ADC_DeInit();
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;          
ADC_InitStructure.ADC_ScanConvMode = DISABLE;   
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;  
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; 
ADC_InitStructure.ADC_NbrOfConversion = 1;    
ADC_Init(ADC3, &ADC_InitStructure);      

ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;   
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div4; 
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; 
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
ADC_CommonInit(&ADC_CommonInitStructure);

ADC_RegularChannelConfig(ADC3, ADC_Channel_5, 1, ADC_SampleTime_15Cycles); 
//ADC_ITConfig(ADC3, ADC_IT_EOC, ENABLE); //
ADC_Cmd(ADC3, ENABLE);  

/*********************ADC?????***************************/
//ADC_AnalogWatchdogCmd(ADC3, ADC_AnalogWatchdog_SingleRegEnable);
//ADC_AnalogWatchdogThresholdsConfig(ADC3, 0x0E8B, 0x0555);  
//ADC_AnalogWatchdogSingleChannelConfig(ADC3, ADC_Channel_5);
ADC_ITConfig(ADC3, ADC_IT_AWD, ENABLE);

ADC_DMACmd(ADC3, ENABLE);   //??ADC3?DMA  
ADC_DMARequestAfterLastTransferCmd(ADC3, ENABLE); //?????????????DMA????,?????DMA
}


void NVIC_Config()
{
/* USART6???? */
NVIC_InitTypeDef NVIC_InitStructure;
//NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);        //???????? 1
//NVIC_InitStructure.NVIC_IRQChannel = USART6_IRQn;       //?????USART6_IRQn
//NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //?????? 0
//NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;    //?????? 0
//NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;     //??????
//NVIC_Init(&NVIC_InitStructure);

/* DMA */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);        
NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream0_IRQn;   
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; 
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;    
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;    
NVIC_Init(&NVIC_InitStructure);

/* ADC*/
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);        
NVIC_InitStructure.NVIC_IRQChannel = ADC_IRQn;           
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; 
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;   
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;    
NVIC_Init(&NVIC_InitStructure);
}


void DMA_Config(void)
{
DMA_InitTypeDef DMA_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);

DMA_DeInit(DMA2_Stream0);
DMA_StructInit( &DMA_InitStructure);
DMA_InitStructure.DMA_Channel = DMA_Channel_2;          
DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC3_DR_Addr; 
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADCoverVaule;  
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;    

DMA_InitStructure.DMA_BufferSize = 1;                      
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; 
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;  

DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; 

DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;  
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;       
DMA_InitStructure.DMA_Priority = DMA_Priority_High; 

DMA_Init(DMA2_Stream0, &DMA_InitStructure);
DMA_Cmd(DMA2_Stream0, ENABLE);     

DMA_ITConfig(DMA2_Stream6, DMA_IT_TC, ENABLE);
DMA_ITConfig(DMA2_Stream0, DMA_IT_TC, ENABLE);
}

void DMA2_Stream0_IRQHandler(void)
{
 if(DMA_GetITStatus(DMA2_Stream0, DMA_IT_TCIF0) != RESET)
 {
  DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0);
 }
}


void ADC_IRQHandler(void)
{
  if (ADC_GetITStatus(ADC3, ADC_IT_AWD) == SET)
 {
  ADC_ClearITPendingBit(ADC3, ADC_IT_AWD);
  ADC_Cmd(ADC3, DISABLE);
  printf("Input is out of threrd!!");
 }
}


main(void) 
{
u8 rval=0; 
int i;
  _btn_obj* rbtn; //·???°???????
__IO uint16_t ADCoverVaule;

  LCD_Clear(BLACK);
LCD_DrawGrid();                          //??±??°??????
LCD_DrawGrid2();
LCD_DrawGrid3();
POINT_COLOR=YEL;   
// Display_Frame();                          //??????±??°??
LCD_Display_text();
                   //?è??×???????
BACK_COLOR=BLACK;                         //?è??±??°??
BEEP=1;
delay_ms(100);
BEEP=0; 


GPIO_Config();
ADC_Config();
DMA_Config();
NVIC_Config();
ADC_SoftwareStartConv(ADC3);    

while(rval==0)
{  

  printf("ADCoverVaule=%04X VolVaule=%d mV ", ADCoverVaule, ADCoverVaule*3300/4096);  //这里打印出来的值不变,

}
// return 0;

}


友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。