#define ADC_CDR_ADDRESS ((uint32_t)0x40012308) #define ADC_Buffer_Size 1024 __IO uint32_t ADC_Buffer[ADC_Buffer_Size]; void ADC_init(void) { ADC_InitTypeDef ADC_InitStructure; ADC_CommonInitTypeDef ADC_CommonInitStructure; DMA_InitTypeDef DMA_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; /* Enable peripheral clocks */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2 | RCC_AHB1Periph_GPIOC |RCC_AHB1Periph_GPIOA, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2 | RCC_APB2Periph_ADC3, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); /* Time base configuration */ TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); TIM_TimeBaseStructure.TIM_Period = 4512; TIM_TimeBaseStructure.TIM_Prescaler = 0x4; TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; 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); TIM_ARRPreloadConfig(TIM1, ENABLE); TIM_OC1PreloadConfig (TIM1, TIM_OCPreload_Enable); //TIM1->CR2 =0x00; //TIM1->SMCR = 0x00; //TIM1->DIER = 0x00; /* Configure ADC Channel 12 pin as analog input */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; GPIO_Init(GPIOC, &GPIO_InitStructure); /* Configure ADC Channel 12 pin as analog input */ GPIO_InitStructure.GPIO_Pin = 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); /* DMA2 Stream0 channel0 configuration */ DMA_InitStructure.DMA_Channel = DMA_Channel_0; DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC_CDR_ADDRESS; DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADC_Buffer; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; DMA_InitStructure.DMA_BufferSize = ADC_Buffer_Size; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure.DMA_Priority = DMA_Priority_High; 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); /* Enable the DMA7 Interrupt*/ NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream0_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* DMA2_Stream0 enable */ DMA_ClearITPendingBit(DMA2_Stream0,DMA_IT_TC); DMA_ITConfig(DMA2_Stream0,DMA_IT_TC,ENABLE); DMA_Cmd(DMA2_Stream0, ENABLE); /* Enable ADC1 DMA */ ADC_DMACmd(ADC1, ENABLE); /******************************************************************************/ /* ADCs configuration: triple interleaved with 5cycles delay to reach 6Msps */ /******************************************************************************/ /* ADC Common configuration *************************************************/ ADC_CommonInitStructure.ADC_Mode = ADC_TripleMode_RegSimult; ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles; ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_2; ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2; ADC_CommonInit(&ADC_CommonInitStructure); /* ADC1 regular channel 12 configuration ************************************/ ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; 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 = 3; ADC_Init(ADC1, &ADC_InitStructure); ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 1, ADC_SampleTime_15Cycles); ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 2, ADC_SampleTime_15Cycles); ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 3, ADC_SampleTime_15Cycles); /* ADC2 regular channel 12 configuration ************************************/ ADC_Init(ADC2, &ADC_InitStructure); /* ADC2 regular channel12 configuration */ ADC_RegularChannelConfig(ADC2, ADC_Channel_11, 1, ADC_SampleTime_15Cycles); ADC_RegularChannelConfig(ADC2, ADC_Channel_13, 2, ADC_SampleTime_15Cycles); ADC_RegularChannelConfig(ADC2, ADC_Channel_7, 3, ADC_SampleTime_15Cycles); /* ADC3 regular channel 12 configuration ************************************/ ADC_Init(ADC3, &ADC_InitStructure); /* ADC3 regular channel12 configuration */ ADC_RegularChannelConfig(ADC3, ADC_Channel_10, 1, ADC_SampleTime_15Cycles); ADC_RegularChannelConfig(ADC3, ADC_Channel_12, 2, ADC_SampleTime_15Cycles); ADC_RegularChannelConfig(ADC3, ADC_Channel_13, 3, ADC_SampleTime_15Cycles); /* Enable DMA request after last transfer (multi-ADC mode) ******************/ ADC_MultiModeDMARequestAfterLastTransferCmd(ENABLE); /* Enable ADC1 **************************************************************/ ADC_Cmd(ADC1, ENABLE); /* Enable ADC2 **************************************************************/ ADC_Cmd(ADC2, ENABLE); /* Enable ADC3 **************************************************************/ ADC_Cmd(ADC3, ENABLE); /* TIM1 counter enable */ TIM_Cmd(TIM1,ENABLE); /* TIM1 main Output Enable */ TIM_CtrlPWMOutputs(TIM1,ENABLE); } 程序运行时,DMA中断只开始运行时发生一次,就在没有了,不知那设置错了,请各位指教! |
adc.txt
下载6.3 KB, 下载次数: 169, 下载积分: ST金币 -1
STM32F407 定时器触发DMA 求助大神
【MCU实战经验】基于STM32F407的音频播放器设计
盘古UE-STM32F407工控板原理图
【STM32F429心得\疑问】+STM32F4之FSMC和FMC
STM32F429读取IO口传输的数据速率
STM32F407ZGT6 手摸芯片背部重启
STM32F4 SPI 动作时,软件片选信号被拉高,IO口程序逻辑失控
STM32F401RE NUCLEO求助,串口一直不能进中断
读取STM32F407内部温度传感器值错误
STM32F429多路内部ADC独立采集的办法
RE:STM32F407 ADC 用定时器触发DMA传送问题
RE:STM32F407 ADC 用定时器触发DMA传送问题
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_2;
RE:STM32F407 ADC 用定时器触发DMA传送问题
RE:STM32F407 ADC 用定时器触发DMA传送问题
#include "stm32f10x.h"
#include "SysTick\\systick.h"
#include
#include "USART\\usart.h"
/* Private define ------------------------------------------------------------*/
#define ADC1_DR_Address ((u32)0x4001244C)
#define N 100 //每通道采100次
#define M 6 //为2个通道
/* Private function prototypes -----------------------------------------------*/
void USART_Configuration(void);
void ADC_Configuration(void);
void filter(void);
u16 GetVolt(u16 advalue) ;
/* Private variables ---------------------------------------------------------*/
vu16 ADC_ConvertedValue;
vu16 AD_Value[N][M]; //用来存放ADC转换结果,也是DMA的目标地址
vu16 After_filter[M]; //用来存放求平均值之后的结果
int i;
int main(void)
{
u16 value[M];
Delay_Init();
USART_Configuration();
ADC_Configuration();
printf("\r\n****************************************************************\r\n");
/* Infinite loop */
while (1)
{
filter();
for(i=0;i
回复:STM32F407 ADC 用定时器触发DMA传送问题
RE:STM32F407 ADC 用定时器触发DMA传送问题
//ADC1的DMA数据流中断服务函数
void DMA2_Stream0_IRQHandler(void)
{
u16 i;
if(DMA_GetFlagStatus(DMA_STREAMx_ADC1 ,DMA_FLAG_TCIF0)!=RESET)
{
ADC_DMARequestAfterLastTransferCmd(ADC1x , DISABLE);
ADC_DMACmd(ADC1x , DISABLE);
DMA_Cmd(DMA_STREAMx_ADC1, DISABLE);
while (DMA_GetCmdStatus(DMA_STREAMx_ADC1) != DISABLE){}//等待DMA可配
for(i=0; i<ADC1_DataNum; i++)
{
uwADC1xConvertedVoltage[i] = uhADC1xConvertedValue[i] * 3300/0xFFF;
printf("\r\n通道ADC_Channel_1 采样电压为 ::");
USART_ShowxNum(uwADC1xConvertedVoltage[i], 4);
}
printf("\r\n-------------------");
ADC1DataProcess_Amp(uhADC1xConvertedValue, PGA1_GAIN);
DMA_ClearFlag(DMA_STREAMx_ADC1,DMA_FLAG_TCIF0);
DMA_SetCurrDataCounter(DMA_STREAMx_ADC1,ADC1_DataNum);//数据传输量
DMA_Cmd(DMA_STREAMx_ADC1, ENABLE);
ADC_DMARequestAfterLastTransferCmd(ADC1x , ENABLE);
ADC_DMACmd(ADC1x , ENABLE);
}
}
如果是后者,需要在检测到溢出后,再次从溢出状态恢复,恢复过程看数据手册有关OVR部分内容。