不用定时器触发,可以循坏采集数据,但加个定时器就不行了。底下为相关代码,求高手解答。
另外发现303和103在库函数上改动不少,好多地方都要重写。
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f30x.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f30x.c file
*/
/* Configure the ADC clock */
RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div2);
/* Enable ADC1 clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12, ENABLE);
/* Setup SysTick Timer for 1 µsec interrupts */
if (SysTick_Config(SystemCoreClock / 1000000))
{
/* Capture error */
while (1)
{}
}
/* ADC Channel configuration */
/* GPIOC Periph clock enable */
DMA_Config();
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
/* Configure ADC Channel7 as analog input */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOC, &GPIO_InitStructure);
ADC_StructInit(&ADC_InitStructure);
/* Calibration procedure */
ADC_VoltageRegulatorCmd(ADC1, ENABLE);
/* Insert delay equal to 10 µs */
Delay(10);
ADC_SelectCalibrationMode(ADC1, ADC_CalibrationMode_Single);
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1) != RESET );
calibration_value = ADC_GetCalibrationValue(ADC1);
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_CommonInitStructure.ADC_Clock = ADC_Clock_AsynClkMode;
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_1;//ADC_DMAAccessMode_Disabled;
ADC_CommonInitStructure.ADC_DMAMode = ADC_DMAMode_Circular;//ADC_DMAMode_OneShot;
ADC_CommonInitStructure.ADC_TwoSamplingDelay = 0;
ADC_CommonInit(ADC1, &ADC_CommonInitStructure);
ADC_InitStructure.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Disable;
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_2;// ¶ÔÓ¦TIM1CC3 ADC_ExternalTrigConvEvent_0;
// ADC_InitStructure.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_RisingEdge;//ADC_ExternalTrigEventEdge_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_OverrunMode = ADC_OverrunMode_Disable;
ADC_InitStructure.ADC_AutoInjMode = ADC_AutoInjec_Disable;
ADC_InitStructure.ADC_NbrOfRegChannel = 1;
ADC_Init(ADC1, &ADC_InitStructure);
/* ADC1 regular channel7 configuration */
ADC_RegularChannelConfig(ADC1, ADC_Channel_7, 1, ADC_SampleTime_7Cycles5);
/* Enable ADC1 */
//ADC_Cmd(ADC1, ENABLE);
ADC_ITConfig(ADC1, ADC_IT_EOC, DISABLE);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
ADC_DMACmd(ADC1, ENABLE);
// ADC_ExternalTrigConvCmd(ADC1,ENABLE);
NVIC_Configuration();
//ADC_ExternalTriggerConfig
/* wait for ADRDY */
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_RDY));
TIM1_Config();
/* Start ADC1 Software Conversion */
ADC_StartConversion(ADC1);
ADC_InitStructure.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_RisingEdge;
ADC_Init(ADC1, &ADC_InitStructure);
/* Infinite loop */
while (1)
{
}
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
static void DMA_Config(void)
{
DMA_InitTypeDef DMA_InitStructure;
/* Enable DMA2 clock -------------------------------------------------------*/
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
/* DMA1 channel1 configuration ----------------------------------------------*/
DMA_DeInit(DMA1_Channel1);
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC_CDR_ADDRESS;//ADC1_DR_Address;//????
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)TemDat;//ADC_RCVTab;//????
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;//dma??????
DMA_InitStructure.DMA_BufferSize = 200;//??DMA?????????? word
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//??DMA???????,????
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//??DMA???????,
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;//??????
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;//??????
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;//??DMA?????:?????????
DMA_InitStructure.DMA_Priority = DMA_Priority_High;//??DMA?????
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;//??DMA?2?memory????????
DMA_Init(DMA1_Channel1, &DMA_InitStructure);
DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE);
/* Enable DMA1 channel1 */
DMA_Cmd(DMA1_Channel1, ENABLE);
}
void TIM1_Config(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
/* Enable TIM3 clock */
RCC_APB1PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
TIM_TimeBaseStructure.TIM_Prescaler = 12;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period = 200;//SystemCoreClock/ECG_SAMPLING_FREQ/13;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0x0;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
/* Channel1 Configuration in PWM mode */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
TIM_OCInitStructure.TIM_Pulse = 125;//SystemCoreClock/ECG_SAMPLING_FREQ/26;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OC3Init(TIM1, &TIM_OCInitStructure); //3ºÅͨµÀ
/* TIM3 enable counter */
TIM_Cmd(TIM1, ENABLE);
}
void DMA1_Channel1_IRQHandler(void)
{
int i;
i = 8;
if(DMA_GetITStatus(DMA1_IT_TC1)==SET)
{
// Send_Flag=1;
// GPIO_WriteBit(GPIOE,GPIO_Pin_13,1-GPIO_ReadOutputDataBit(GPIOE,GPIO_Pin_13));
// DMA_ClearITPendingBit(DMA1_IT_TC1);
// DMA_ClearITPendingBit(DMA1_IT_GL1);
DMA_ClearFlag(DMA1_FLAG_TC1);
// ADC_ClearFlag(ADC1, ADC_FLAG_EOS);
// ADC_ClearFlag(ADC1, ADC_FLAG_EOSMP);
// DMA_Config();
DMA_ClearFlag(DMA1_IT_GL1);
ADC_StartConversion(ADC1);
}
else
if(DMA_GetITStatus(DMA1_IT_HT1) == SET)
{
// DMA_ClearITPendingBit(DMA1_IT_HT1);
DMA_ClearITPendingBit(DMA1_IT_GL1);
}
}
|