搞了好多天了,看了论坛上的相关帖子,发现我的程序在硬件仿真的时候,只进入一次中断,之后就时钟不进入了,数据也没有传输得到,adc溢出,求大神指教啊!!
unsigned int adc_value_buf_one[32];
unsigned int adc_value_buf_two[32];
volatile unsigned char adc_conv_comp_flag=0;
void ADC_Config(void)
{
ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
DMA_InitTypeDef DMA_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable ADCx, DMA and GPIO clocks ****************************************/
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
DMA_DeInit(DMA2_Stream0);
/* DMA2 Stream0 channel0 configuration **************************************/
DMA_InitStructure.DMA_Channel = DMA_Channel_0; //?????÷?¨??
DMA_InitStructure.DMA_PeripheralBaseAddr = ((uint32_t)0x4001224C);//???è???·,adc_dr
DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&adc_value_buf_one;//?????÷???·
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;//????????·??ò
DMA_InitStructure.DMA_BufferSize = 32;//??????????????????
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//???è???????????????????ó?????è????????
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//?????÷???????????????????ó???????÷????????
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_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable; //FIFO????
DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;//FIFO·§??????
DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;//?????÷??·?????
DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;//???è??·?????
DMA_DoubleBufferModeConfig(DMA2_Stream0, (uint32_t)&adc_value_buf_two,DMA_Memory_0);//?????????????? DMA_Memory_0?×??????
DMA_DoubleBufferModeCmd(DMA2_Stream0, ENABLE);
//????????
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
DMA_ITConfig(DMA2_Stream0,DMA_IT_TC,ENABLE);
DMA_Init(DMA2_Stream0, &DMA_InitStructure);//DMA2_Stream0???????÷????
//DMA_Cmd(DMA2_Stream0, ENABLE);
DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0);//?????????÷0?????ê??????±ê????
DMA_ITConfig(DMA2_Stream0, DMA_IT_TC, ENABLE);//DMA2?????÷0?????ê??????????
/* Configure ADC1 Channel 6 7 14 15 pin as analog input ******************************/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* ADC Common Init **********************************************************/
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;//?à??adc????????
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;//adc?±??2·??? 42MHZ
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;//?????à??adc??????????dma
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;//?à??adc??????2?????ù?×???®???????±
ADC_CommonInit(&ADC_CommonInitStructure);
/* ADC1 Init ****************************************************************/
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;//12??·?±???
ADC_InitStructure.ADC_ScanConvMode = ENABLE;//?¨?è????
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 = 4;//???ò?¨??×????ò??×???×???
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC1 regular channel7 configuration ,first convent,Sample Time is 3Cycles**************************************/
ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 1, ADC_SampleTime_144Cycles);
ADC_RegularChannelConfig(ADC1, ADC_Channel_7, 2, ADC_SampleTime_144Cycles);
ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 3, ADC_SampleTime_144Cycles);
ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 4, ADC_SampleTime_144Cycles);
/* Enable DMA request after last transfer (Single-ADC mode) */
ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);
/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
}
void ADC_start(void)
{
/* ??????????????????·????ù???????í????·?ADC×??? */
ADC_SoftwareStartConv(ADC1);
/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
/* Enable DMA channel0 */
DMA_Cmd(DMA2_Stream0, ENABLE);
//DMA_ITConfig(DMA2_Stream0,DMA_IT_TC| DMA_IT_HT,ENABLE);
DMA_ITConfig(DMA2_Stream0,DMA_IT_TC,ENABLE);
}
//DMA?????ê??????????
void DMA2_Stream0_IRQHandler(void)
{
if(DMA_GetITStatus(DMA2_Stream0,DMA_IT_TCIF0) != RESET)
{
DMA_ClearITPendingBit(DMA2_Stream0,DMA_IT_TCIF0);
//USER_LED=~USER_LED;
}
// else
// {
// DMA_ClearFlag(DMA2_Stream0,DMA_FLAG_HTIF0);
// }
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>