打扰下,有一个奇葩的问题很困扰。STM32F103的,定时器触发ADC中断再通过DMA传送数据。在定时0.01秒或者更慢的时候可以触发,定时0.001秒或者更快就无法触发。我采样周期设的1.5个周期。这是为啥?为啥定时器设快了就不能触发了? 心急QAQ 下附源代码: void ADC_DMA(void) { ADC_InitTypeDef ADC_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; DMA_InitTypeDef DMA_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; NVIC_InitTypeDef NVIC_InitStructure; //==================================== RCC_ADCCLKConfig(RCC_CFGR_ADCPRE_DIV6); RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_ADC2|RCC_APB2Periph_ADC1,ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1|RCC_AHBPeriph_DMA2,ENABLE); GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AIN; GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1; GPIO_Init(GPIOA,&GPIO_InitStructure); //Timer1 RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE); TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Period = 1000; //通过这两个设置采样频率,但为什么在低于等于500Hz的时候可以触发ADC,高于500Hz的时候不能触发。。。 TIM_TimeBaseStructure.TIM_Prescaler = (144 - 1); TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); /* TIM1 channel1 configuration in PWM mode */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = 0x7f; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OC1Init(TIM1, &TIM_OCInitStructure); NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); TIM_ClearFlag(TIM1, TIM_FLAG_Update); TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE); /* DMA1ͨµÀ1ÅäÖÃ*/ DMA_DeInit(DMA1_Channel1); //¿ªÆôDMA1µÄµÚһͨµÀ DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address; //DMA¶ÔÓ¦µÄÍâÉè»ùµØÖ· DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ADCConvertedValue; //ÄÚ´æ´æ´¢»ùµØÖ· DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; //DMAµÄת»»Ä£Ê½ÎªSRCģʽ£¬ÓÉÍâÉè°áÒƵ½ÄÚ´æ DMA_InitStructure.DMA_BufferSize = 2*fuck; //DMA»º´æ´óС£¬1000¸ö DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; //½ÓÊÕÒ»´ÎÊý¾Ýºó£¬É豸µØÖ·½ûÖ¹ºóÒÆ DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; //¹Ø±Õ½ÓÊÕÒ»´ÎÊý¾Ýºó£¬Ä¿±êÄÚ´æµØÖ·ºóÒÆ DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;//¶¨ÒåÍâÉèÊý¾Ý¿í¶ÈΪ16λ DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; //DMA°áÒÆÊý¾Ý³ß´ç£¬HalfWord¾ÍÊÇΪ16λ DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; //ת»»Ä£Ê½£¬Ñ»·»º´æģʽ¡£ DMA_InitStructure.DMA_Priority = DMA_Priority_High; //DMAÓÅÏȼ¶¸ß DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; //M2Mģʽ½ûÓà DMA_Init(DMA1_Channel1, &DMA_InitStructure); /* ʹÄÜDMA1ͨµÀ1 */ DMA_Cmd(DMA1_Channel1, ENABLE); /* ADC1ÅäÖÃ*/ ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult; //¶ÀÁ¢µÄת»»Ä£Ê½ ADC_InitStructure.ADC_ScanConvMode = ENABLE; //¿ªÆôɨÃèģʽ ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; //¿ªÆôÁ¬Ðøת»»Ä£Ê½ ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1; //ADCÍⲿ¿ª¹Ø£¬¹Ø±Õ״̬ ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //¶ÔÆ뷽ʽ,ADCΪ12λÖУ¬ÓÒ¶ÔÆ뷽ʽ ADC_InitStructure.ADC_NbrOfChannel = 1; //¿ªÆôͨµÀÊý£¬1¸ö ADC_Init(ADC1, &ADC_InitStructure); /* ADC2ÅäÖÃ*/ ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult; //¶ÀÁ¢µÄת»»Ä£Ê½ ADC_InitStructure.ADC_ScanConvMode = ENABLE; //¿ªÆôɨÃèģʽ ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; //¿ªÆôÁ¬Ðøת»»Ä£Ê½ ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1; //ADCÍⲿ¿ª¹Ø£¬¹Ø±Õ״̬ ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //¶ÔÆ뷽ʽ,ADCΪ12λÖУ¬ÓÒ¶ÔÆ뷽ʽ ADC_InitStructure.ADC_NbrOfChannel = 1; //¿ªÆôͨµÀÊý£¬1¸ö ADC_Init(ADC2, &ADC_InitStructure); ADC_ExternalTrigConvCmd(ADC2, ENABLE); /* ADC1ͨµÀ14ÅäÖÃ*/ ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_1Cycles5); ADC_RegularChannelConfig(ADC2, ADC_Channel_1, 1, ADC_SampleTime_1Cycles5); ADC_DMACmd(ADC1, ENABLE); ADC_Cmd(ADC1, ENABLE); ADC_Cmd(ADC2, ENABLE); ADC_ResetCalibration(ADC1); ADC_ResetCalibration(ADC2); while(ADC_GetResetCalibrationStatus(ADC1)); while(ADC_GetResetCalibrationStatus(ADC2)); /* ¿ªÊ¼Ð£×¼ADC1 */ ADC_StartCalibration(ADC1); ADC_StartCalibration(ADC2); while(ADC_GetCalibrationStatus(ADC1)); while(ADC_GetCalibrationStatus(ADC2)); // ADC_SoftwareStartConvCmd(ADC1, ENABLE); // ADC_SoftwareStartConvCmd(ADC2, ENABLE); ADC_ExternalTrigConvCmd(ADC1, ENABLE); // ADC_ITConfig(ADC1,ADC_IT_EOC,ENABLE); TIM_Cmd(TIM1, ENABLE); TIM_CtrlPWMOutputs(TIM1,ENABLE); } 在线急求。急的我心疼QAQ |
【MCU实战经验】基于STM32F103C8T6的hart总线调试器设计
求教STM32F103进入STOP模式后用外部中断唤醒的问题
基于STM32F103RCT6的无源蜂鸣器音乐播放(生日快乐歌)
STM32F103c8t6有没有DAC 功能?
STM32F103x中文数据手册
新手求教,为何在我电脑上找不到STM32F1Xx.h文件
金龙107例程汇总(STM32F107)
万利STM32F107VC 原理图
STM32F103 ADC多通道检测必须要DMA吗?
【官方例程】STM32F107以太网官方例程
RE:STM32F103关于TIM1触发ADC采样的频率设置异常