本帖最后由 死鹹水魚 于 2017-6-1 09:25 编辑
最近在用STMF030的片子在开发过程中遇到一个奇葩的问题,
打算实现:
ADC1的轮流采集多个通道,数据通过DMA1_CH1搬运到一片内存区,完成一圈后触发DMA传输完成中断,对采集数据进行处理。
前面的功能已经实现,但是在加入了NVIC中断配置后,发现ADC采集数据为0
调试下发现DMA写入目标地址的数据组全部为空,而ADC1->DR里面的数据是有变化的,
并且不为0。DMA内的CPAR1和CMAR1所对应的内存地址没错。NVIC中断也能进入,标志位也正常。
请问下这是什么回事?
以下是ADC、DMA、以及NVIC部分的配置函数。
- void ADC_Config(void)
- {
- /* ADC Configuration Struct */
- ADC_InitTypeDef ADC_InitStruct;
- GPIO_InitTypeDef GPIO_InitStruct;
- DMA_InitTypeDef DMA_InitStruct;
- NVIC_InitTypeDef NVIC_InitStruct;
-
- /* ADC1 Periph clock Enable */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
-
- /* GPIOA Periph clock Enable */
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
-
- /* DMA1 Clock enable */
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1 , ENABLE);
-
- /* ADC RCC CLK */
- RCC_ADCCLKConfig(RCC_ADCCLK_HSI14); /*ADC 14Mhz Clock*/
-
- /* Configuration PA0:6 as AIN */
- GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2/* PA0:TEM2, PA1:TEM1, PA2:C-PV */\
- |GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5/* PA3:C-BAT, PA4:V-BOOST, PA5: V-BAT*/\
- |GPIO_Pin_6/* PA6:V-PV */;
- GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AN;
- GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
-
- GPIO_Init(GPIOA, &GPIO_InitStruct);
-
- /* Enable DMA channel1 IRQ Channel */
- NVIC_InitStruct.NVIC_IRQChannel = DMA1_Channel1_IRQn;
- NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
- NVIC_InitStruct.NVIC_IRQChannelPriority = 1;
-
- //NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1;
- //NVIC_InitStruct.NVIC_IRQChannelSubPriority = 1;
- NVIC_Init(&NVIC_InitStruct);
-
- /* Initialize ADC Struct */
- ADC_StructInit(&ADC_InitStruct);
-
- /* Configuration ADC */
- ADC_InitStruct.ADC_Resolution = ADC_Resolution_12b; /* ADC 12bit */
- ADC_InitStruct.ADC_ContinuousConvMode = ENABLE;/* Continuous Convert Mode */
- //ADC_InitStruct.ADC_ContinuousConvMode = DISABLE;
- ADC_InitStruct.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConv_T1_TRGO;/*ADC_ExternalTrigConvEdge_None;*/
- ADC_InitStruct.ADC_ExternalTrigConv = ADC_ExternalTrigConvEdge_Rising;
- ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right;
- ADC_InitStruct.ADC_ScanDirection = ADC_ScanDirection_Upward;
-
- ADC_Init(ADC1, &ADC_InitStruct);
-
- /* Convert the ADC1 Channel0 and channe6 with 1.5 Cycles as sampling time */
- ADC_ChannelConfig(ADC1, ADC_Channel_0, ADC_SampleTime_1_5Cycles);
- ADC_ChannelConfig(ADC1, ADC_Channel_1, ADC_SampleTime_1_5Cycles);
- ADC_ChannelConfig(ADC1, ADC_Channel_2, ADC_SampleTime_1_5Cycles);
- ADC_ChannelConfig(ADC1, ADC_Channel_3, ADC_SampleTime_1_5Cycles);
- ADC_ChannelConfig(ADC1, ADC_Channel_4, ADC_SampleTime_1_5Cycles);
- ADC_ChannelConfig(ADC1, ADC_Channel_5, ADC_SampleTime_1_5Cycles);
- ADC_ChannelConfig(ADC1, ADC_Channel_6, ADC_SampleTime_1_5Cycles);
-
- /* Convert the ADC1 inner temp sensor with 1.5 Cycles as Sampling time*/
- /* ADCChannel 16 */
- ADC_ChannelConfig(ADC1, ADC_Channel_TempSensor, ADC_SampleTime_1_5Cycles);
-
- /* Convert the ADC1 Vref*//* ADC_Channel 17 */
- ADC_ChannelConfig(ADC1, ADC_Channel_Vrefint, ADC_SampleTime_1_5Cycles);
-
- /* ADC Calibration *//* Get ADC Calibration Data*/
- ADC_Cal_Data = ADC_GetCalibrationFactor(ADC1);
-
- /* ADC DMA request in circular mode */
- ADC_DMARequestModeConfig(ADC1, ADC_DMAMode_Circular);
-
-
- /* Enable ADC_DMA */
- ADC_DMACmd(ADC1, ENABLE);
-
- /* Enable the ADC peripheral */
- ADC_Cmd(ADC1, ENABLE);
- ADC_TempSensorCmd(ENABLE);
- ADC_VrefintCmd(ENABLE);
-
- /* Wait the ADRDY flag */
- while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADRDY));
-
- /* ADC Auto Power off */
- ADC_AutoPowerOffCmd(ADC1, ENABLE);
-
- /* DMA1 Configuration */
- DMA_DeInit(ADC_DMA_CH);
-
- DMA_InitStruct.DMA_PeripheralBaseAddr = (uint32_t)&(ADC1->DR); /* DMA Data Source Addr */
- //DMA_InitStruct.DMA_MemoryBaseAddr = (uint32_t)ConvertDatas; /* DMA Data Distance Addr */
- DMA_InitStruct.DMA_MemoryBaseAddr = (uint32_t)&g_ADCCollectorStruct;
- DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralSRC; /* DMA Data Transform Dir */
- DMA_InitStruct.DMA_BufferSize = 9; /* DMA Data Busser Size */
- DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;
- DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; /* Data Length Half Word 16bit */
- DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
- DMA_InitStruct.DMA_Mode = DMA_Mode_Circular; /* DMA Mode : Circular Mode */
- //DMA_InitStruct.DMA_Mode = DMA_Mode_Normal;
- DMA_InitStruct.DMA_Priority = DMA_Priority_High;
- DMA_InitStruct.DMA_M2M = DMA_M2M_Disable;
- /* DMA Init Configuration */
- DMA_Init(ADC_DMA_CH, &DMA_InitStruct);
-
- DMA_ITConfig(ADC_DMA_CH, DMA_IT_TC, ENABLE);
-
- /* DMA1 Channel1 enable */
- DMA_Cmd(ADC_DMA_CH, ENABLE);
- /* ADC1 regular Software Start Conv */
- ADC_StartOfConversion(ADC1);
- }
复制代码 中断部分函数
- extern void ConvertAVGFitter(void);
- void DMA1_Channel1_IRQHandler(void)
- {
- if(DMA_GetITStatus(DMA1_IT_TE1))
- {
- while(1);
- }
- if(DMA_GetITStatus(DMA1_IT_TC1))
- {
- DMA_ClearFlag(DMA1_FLAG_TC1);
- DMA_ClearITPendingBit(DMA1_IT_TC1);
- ConvertAVGFitter();
- }
- }
复制代码
另,ADC1是利用TIM1的TRGO触发的,请问这有关系吗?
|
感觉030这种低端型的片子看来还是少用库写为妙啊。。