完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
ADC中要选择TIM4_CC4 event,定时器中药选择TIM4_CC4 event的输出源
|
|
|
|
stm32f302中我已经选择了,但是用软件触发可以触发AD进入中断,可用定时器就不能触发AD进入中断,麻烦帮我看下我下面配置那里有错?谢谢。 AD中的配置代码 void ADC1_DMA_Configuration(void) //ADC²ÉÑù³õʼ»¯ÅäÖà { GPIO_InitTypeDef GPIO_InitStructure; ADC_InitTypeDef ADC_InitStructure; ADC_CommonInitTypeDef ADC_CommonInitStructure; DMA_InitTypeDef DMA_InitStructure; /* Configure the ADC clock */ RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div2); /* Enable the DMA1¡¢GPIOA ¡¢GPIOB and ADC1 Clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1 | RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_ADC12, ENABLE); if (SysTick_Config(SystemCoreClock / 1000000)) { while (1) {} } /* Configure PA0/PA1/PA2/PA3/PA6/PA7/PB0/PB1 (ADC Channel1/2/3/4/5/10/15/11/12) in analog mode */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | 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_0 | GPIO_Pin_1; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Configure DMA1_Channel1 */ DMA_DeInit(DMA1_Channel1); DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_ADDRESS; DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ADC_ConvertedValue; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = 8; 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_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel1, &DMA_InitStructure); DMA_ITConfig(DMA1_Channel1,DMA_IT_TC,ENABLE); /* Enable DMA1 Channel1 */ DMA_Cmd(DMA1_Channel1, ENABLE); /* Configure ADC1 */ ADC_DeInit(ADC1); /* Calibration procedure */ ADC_VoltageRegulatorCmd(ADC1, ENABLE); /* Insert delay equal to 10us */ Delay(10); ADC_SelectCalibrationMode(ADC1, ADC_CalibrationMode_Single); ADC_StartCalibration(ADC1); while(ADC_GetCalibrationStatus(ADC1) != RESET ); calibration_value = ADC_GetCalibrationValue(ADC1); /* Configure the ADC1 in continuous mode */ ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent; ADC_CommonInitStructure.ADC_Clock = ADC_Clock_AsynClkMode; ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; ADC_CommonInitStructure.ADC_DMAMode = ADC_DMAMode_Circular; ADC_CommonInitStructure.ADC_TwoSamplingDelay = 5; ADC_CommonInit(ADC1, &ADC_CommonInitStructure); ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; ADC_InitStructure.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Disable; ADC_InitStructure.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_5; //TIM4_CC4 event ADC_InitStructure.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_RisingEdge; 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 = 8; ADC_Init(ADC1, &ADC_InitStructure); /* ADC1 regular channel1 configuration */ ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_19Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 2, ADC_SampleTime_19Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 3, ADC_SampleTime_19Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 4, ADC_SampleTime_19Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 6, ADC_SampleTime_19Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 7, ADC_SampleTime_19Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 8, ADC_SampleTime_19Cycles5); ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 9, ADC_SampleTime_19Cycles5); /* Enable ADC1 */ ADC_Cmd(ADC1, ENABLE); /* wait for ADRDY */ while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_RDY)); /* ADC1 DMA Enable */ ADC_DMACmd(ADC1, ENABLE); ADC_DMAConfig(ADC1, ADC_DMAMode_Circular); TIM_Cmd(TIM4,ENABLE); }定时器TIM4的配置代码: void TIM4_Configuration(void) //TIM4¶¨Ê±50usÈí¼þ´¥·¢×ª»»ADC1²ÉÑùת»» { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; /* TIM4 clock enable */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); /* Time Base configuration */ TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Period = 50; TIM_TimeBaseStructure.TIM_Prescaler = 72 - 1; //72M/(71+1) = 1,000,000 -->1us TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_Pulse = 25; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OC4Init(TIM4,&TIM_OCInitStructure); TIM_CtrlPWMOutputs(TIM4, ENABLE); TIM_Cmd(TIM4,ENABLE); TIM_OC4PreloadConfig(TIM4, TIM_OCPreload_Enable); } |
|
|
|
定时器配置中少了void TIM_SelectOutputTrigger(TIM_TypeDef* TIMx, uint16_t TIM_TRGOSource);这个函数,用这个配置输出触发信号
|
|
|
|
djw200988 发表于 2018-10-31 17:22 非常感谢你的回复,我试试,谢谢。 |
|
|
|
djw200988 发表于 2018-10-31 17:22 我选择的TIM_SelectOutputTrigger(TIM4,TIM_TRGOSource_Update);和TIM_SelectOutputTrigger(TIM4,TIM_TRGOSource_ENABLE);还是不能触发AD进入中断,到底我哪里配置有问题? |
|
|
|
本帖最后由 风子 于 2015-6-5 14:31 编辑
刚刚帮你测试了下,ADC选TIM4_CC4不需要TIM_SelectOutputTrigger,ADC选择EXT12(TIM4_TRGO event) 才需要TIM_SelectOutputTrigger();你应该是其他地方的程序有问题,比如ADC配置或者中断配置//如果还不行,你把ADC触发信号换成EXT12(TIM4_TRGO event)试一下,TIM_SelectOutputTrigger这个函数选出来的应该是TIM4_TRGO event |
|
|
|
我遇到同样问题,正在郁闷中
|
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
2085 浏览 1 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
1924 浏览 3 评论
4518 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
2069 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
2581 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-22 01:43 , Processed in 0.773043 second(s), Total 86, Slave 69 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号