楼主你好!(ADC+DMA) 我使用的是单个ADC多通道采集。 在配置的时候,使用了DMA 发送过半中断
这是stm32f4xx_it.c
中断程序
void DMA2_Stream0_IRQHandler(void)
{
//??????·???DMA·?????°?????
if(DMA_GetFlagStatus(DMA2_Stream0,DMA_FLAG_HTIF0)==SET)
{
int i;
printf("ok");
for(i=0;i<256;i++)
{
data= (ADC_ConvertedValue >> 8) & 0xff;
}
printf("%f ",Rx_Buffer*16*3.3*2/4096);
SPI_FLASH_PageWrite(data, MyWriteAddr, 256);
MyWriteAddr+=256;
// printf("ok");
DMA_ClearFlag(DMA2_Stream0,DMA_FLAG_HTIF0);
}else if(DMA_GetFlagStatus(DMA2_Stream0,DMA_FLAG_TCIF0)==SET)
{
int i;
for(i=256;i<512;i++)
{
data= (ADC_ConvertedValue >> 8) & 0xff;
}
SPI_FLASH_PageWrite(data, MyWriteAddr, 256);
MyWriteAddr+=256;
// printf("yes");
DMA_ClearFlag(DMA2_Stream0,DMA_FLAG_TCIF0);
}
if(MyWriteAddr>=0x3fffff)
{
DMA_ITConfig(DMA2_Stream0,DMA_IT_TC | DMA_IT_HT,DISABLE);
GPIO_ResetBits(GPIOB,GPIO_Pin_5);
printf("
-------ADC×????á???????????????------
");
}
}
贴过来乱码出无关紧要!
这个是ADC配置 用了DMA中断!
#include "adc.h"
#define ADC1_DR_Address ((uint32_t)0x4001224C)
__IO uint16_t ADC_ConvertedValue[CH_NUM]={0};
//__IO u16 ADC_ConvertedValueLocal;
/*
* ????????ADC1_GPIO_Config
* ?è?? ??????ADC1??DMA2???±??????????PC.01
* ????: ??
* ???? ????
* ?÷?? ???????÷??
*/
/* ????????ADC1_Mode_Config
* ?è?? ??????ADC1???¤×÷??????DMA????
* ????: ??
* ???? ????
* ?÷?? ???????÷??
*/
/* ????????ADC1_Config
* ?è?? ??????ADC1???¤×÷??????DMA????
* ????: ??
* ???? ????
* ?÷?? ???????÷??
*/
static void ADC1_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
DMA_InitTypeDef DMA_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
/* Enable DMA clock */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
/* Enable GPIOC clock */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
/* Enable ADC1 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
/* DMA channel0 configuration */
DMA_DeInit(DMA2_Stream0);
DMA_InitStructure.DMA_Channel = DMA_Channel_0;
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address; //ADC???·
DMA_InitStructure.DMA_Memory0BaseAddr = (u32)&ADC_ConvertedValue;//???????·
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStructure.DMA_BufferSize = CH_NUM;
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_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_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA2_Stream0, &DMA_InitStructure);
//DMA_ITConfig(DMA2_Stream0,DMA_IT_TC,ENABLE);
DMA_Cmd(DMA2_Stream0, ENABLE);
/* Configure C.01 as analog input */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
GPIO_Init(GPIOC, &GPIO_InitStructure); // C0,PC1,PC2,?????±?????è??????
/* ADC1 configuration */
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;//ADC?±??21MHz
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
ADC_CommonInit(&ADC_CommonInitStructure);
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;//????ADC????
ADC_InitStructure.ADC_ScanConvMode = ENABLE; //?????¨?è???????¨?è?????????à?¨??????
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; //????????×?????????????????????ADC×???
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;//????????????·?×???
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Left; //????????×ó????
ADC_InitStructure.ADC_NbrOfConversion = 4; //??×??????¨??????4
ADC_Init(ADC1, &ADC_InitStructure);
/*????ADC1???¨??10,11,12??3?????ù???????ò????1,2,3,4 */
ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_3Cycles);
ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 2, ADC_SampleTime_3Cycles);
ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 3, ADC_SampleTime_3Cycles);
ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 4, ADC_SampleTime_3Cycles);
//ADC_DMARequestAfterLastTransferCmd(ADC1, ENABLE);
/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
/*??????×??????÷ */
/*ADC_ResetCalibration(ADC1);*/
/*??????×??????÷?????ê?? */
/*while(ADC_GetResetCalibrationStatus(ADC1));*/
/* ADC??×? */
/*ADC_StartCalibration(ADC1);*/
/* ??????×??ê??*/
/*while(ADC_GetCalibrationStatus(ADC1));*/
}
void NVIC_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure one bit for preemption priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
/* ????P[A|B|C|D|E]0???????? */
NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/*
* ????????ADC1_Init
* ?è?? ????
* ???? ????
* ???? ????
* ?÷?? ???????÷??
*/
void ADC_start(void)
{
/* ??????????????????·????ù???????í????·?ADC×??? */
ADC_SoftwareStartConv(ADC1);
/* Enable ADC1 DMA */
ADC_DMACmd(ADC1, ENABLE);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
/* Enable DMA channel0 */
DMA_Cmd(DMA2_Stream0, ENABLE);
DMA_ITConfig(DMA2_Stream0,DMA_IT_TC | DMA_IT_HT,ENABLE);
}
void ADC1_Init(void)
{
ADC1_Config();
NVIC_Config();
}
求解为什么我的DMA中断进不去,还是我的ADC没有工作,本人做的是一个数据采集,其他led exti usart 均已调试成功!
跪求大神指点。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
---------------------------------
回复【2楼】jinstm32:
---------------------------------
---------------------------------
sum+=adc_value[j*ADC_CONV_COUNT+i];
这一句有点问题吧
应该是sum+=adc_value[j*(ADC_CONV_COUNT-1)+i];吧
这个地方应该是#define ADC1_DR_Address ((uint32_t)0x4001204C)
由于ADC1_DR_Address = ADC1_BASE + 0x4c,
/***stm32f4xxx.h******************************/
#define ADC1_BASE (APB2PERIPH_BASE + 0x2000)
#define ADC3_BASE (APB2PERIPH_BASE + 0x2200)
#define APB2PERIPH_BASE (PERIPH_BASE + 0x00010000)
#define ERIPH_BASE ((uint32_t)0x40000000)
/*******************************************/
故而,你所给的宏定义的值得应该为ADC3_DR_Address。
一周热门 更多>