OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 12671|回复: 1

stm32f407 定时器触发ADC

[复制链接]

1

主题

5

帖子

0

精华

新手上路

积分
41
金钱
41
注册时间
2013-3-12
在线时间
1 小时
发表于 2013-3-14 12:46:56 | 显示全部楼层 |阅读模式
ADC1和TIM1的配置如下,ADC为啥启动不了呢, ADC1ConvertedValue 的值一直是0

void _ADC1_CH2_DMA_Config(void)
{
 ADC_InitTypeDef       ADC_InitStructure;
 ADC_CommonInitTypeDef ADC_CommonInitStructure;
 DMA_InitTypeDef       DMA_InitStructure;
 GPIO_InitTypeDef      GPIO_InitStructure;

 /* Enable ADC3, DMA2 and GPIO clocks ****************************************/
 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2 | RCC_AHB1Periph_GPIOA, ENABLE);
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);

 /* DMA2 Stream0 channel2 configuration **************************************/
 DMA_InitStructure.DMA_Channel = DMA_Channel_0; 
 DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC1_DR_ADDRESS;
 DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADC1ConvertedValue;//(uint32_t)&ADC1ConvertedValue;
 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
 DMA_InitStructure.DMA_BufferSize = 1;
 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//DMA_MemoryInc_Disable;
 DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
 DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
 DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;//DMA_Mode_Circular;
 DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
 DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;        
 DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
 DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
 DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
 DMA_Init(DMA2_Stream0, &DMA_InitStructure);
 DMA_Cmd(DMA2_Stream0, ENABLE);

 /* Configure ADC1 Channel2 pin as analog input ******************************/
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
 GPIO_Init(GPIOA, &GPIO_InitStructure);

 /* ADC Common Init **********************************************************/
 ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
 ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
 ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
 ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
 ADC_CommonInit(&ADC_CommonInitStructure);

 /* ADC1 Init ****************************************************************/
 ADC_InitStructure.ADC_Resolution = ADC_Resolution_8b;
 ADC_InitStructure.ADC_ScanConvMode = DISABLE;//ENABLE;
 ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;//ENABLE;
 ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Rising;
 ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
 ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
 ADC_InitStructure.ADC_NbrOfConversion = 1;
 ADC_Init(ADC1, &ADC_InitStructure);

 /* ADC1 regular channel2 configuration *************************************/
 ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 1, ADC_SampleTime_3Cycles);
 /* 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);
 
 ADC_SoftwareStartConv(ADC1);

}
void TIM_Config(void)
{
 TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
 TIM_OCInitTypeDef  TIM_OCInitStructure;
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
 /* Time Base configuration */
 TIM_TimeBaseStructure.TIM_Prescaler = 8-1;
 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
 TIM_TimeBaseStructure.TIM_Period = 30;
 TIM_TimeBaseStructure.TIM_ClockDivision = 0;
 TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
 TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
 
 /* Channel 1, 2,3 and 4 Configuration in PWM mode */
 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
 TIM_OCInitStructure.TIM_Pulse = 6;
 TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
 TIM_OC1Init(TIM1, &TIM_OCInitStructure);
 TIM_ARRPreloadConfig(TIM1, ENABLE);
 TIM_OC1PreloadConfig (TIM1, TIM_OCPreload_Enable);
 TIM_CtrlPWMOutputs(TIM1, ENABLE);
 /* TIM1 counter enable */
 TIM_Cmd(TIM1, ENABLE);
}
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165309
金钱
165309
注册时间
2010-12-1
在线时间
2108 小时
发表于 2013-3-14 14:07:10 | 显示全部楼层
参考下本论坛别人的代码。
搜索下。
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2024-11-22 17:00

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表