OpenEdv-开源电子网

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

内部AD转换+DMA问题

[复制链接]

8

主题

30

帖子

0

精华

初级会员

Rank: 2

积分
88
金钱
88
注册时间
2014-9-15
在线时间
2 小时
发表于 2015-1-6 15:55:12 | 显示全部楼层 |阅读模式
5金钱
用的f4跑ucos,用内部AD+DMA做两路AD转换,为啥DMA不工作,,给跪了,修改了好几天了都没有成效,望哥哥们给看看,不胜感激
[mw_shl_code=c,true]#include <stdio.h> #include "LCD_RA8875.h" #include "stm32f4xx.h" #include "stm32f4xx_rcc.h" #include "stm32f4xx_adc.h" #include "stm32f4xx_dma.h" #include "stm32f4xx_gpio.h" #include "AD.h" #include "Key.h" #include "adc_1.h" #include "ucos_ii.h" #include "GRAPH.h" #define ADC_CONV_COUNT 5 //×??????? #define ADC_CH_NUM 2 uint16_t adc_value_final[ADC_CH_NUM]; uint16_t adc_value[ADC_CH_NUM * ADC_CONV_COUNT]; void ADC_DMA_Config(void) { ADC_InitTypeDef ADC_InitStructure; ADC_CommonInitTypeDef ADC_CommonInitStructure; DMA_InitTypeDef DMA_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; /* Enable ADCx, DMA and GPIO clocks ****************************************/ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2, ENABLE); ADC_DeInit(); DMA_DeInit(DMA2_Stream3);//????DMA2?????÷0 /* DMA2 Stream0 channel1 configuration **************************************/ DMA_InitStructure.DMA_Channel = DMA_Channel_1; DMA_InitStructure.DMA_PeripheralBaseAddr =(u32)(0x4001214C); DMA_InitStructure.DMA_Memory0BaseAddr = (u32)&adc_value; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; DMA_InitStructure.DMA_BufferSize =(ADC_CH_NUM * ADC_CONV_COUNT); 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_Init(DMA2_Stream3, &DMA_InitStructure); //DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_ITConfig(DMA2_Stream3,DMA_IT_TC , ENABLE); DMA_Cmd(DMA2_Stream3, ENABLE); /* Configure ADC3 Channel7 pin as analog input ******************************/ 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); /* 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_DMAAccessMode_1;ADC_DMAAccessMode_Disabled ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles; ADC_CommonInit(&ADC_CommonInitStructure); /* ADC3 Init ****************************************************************/ ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfConversion = ADC_CH_NUM;//???¨?????ò???????ò×?????ADC?¨???????? ADC_Init(ADC2, &ADC_InitStructure); //ADC_TempSensorVrefintCmd(ENABLE);//???????????? /* ADC3 regular channel7 configuration *************************************/ ADC_RegularChannelConfig(ADC2, ADC_Channel_8, 1, ADC_SampleTime_3Cycles); ADC_RegularChannelConfig(ADC2, ADC_Channel_9, 2, ADC_SampleTime_3Cycles); /* Enable DMA request after last transfer (Single-ADC mode) */ ADC_MultiModeDMARequestAfterLastTransferCmd(ENABLE); ADC_DMARequestAfterLastTransferCmd(ADC2, ENABLE); DMA_ITConfig(DMA2_Stream3,DMA_IT_TC | DMA_IT_HT , ENABLE); ADC_DMACmd(ADC2, ENABLE); /* Enable ADC3 DMA */ ADC_Cmd(ADC2, ENABLE); /* Enable ADC3 */ ADC_SoftwareStartConv(ADC2);/* Start ADC Software Conversion */ } /* ????????AD???????? */ void ADC_Sampling(void) { u8 i,j; uint16_t sum; GUI_DispDecAt( DMA_GetFlagStatus(DMA2_Stream3,DMA_FLAG_TCIF3) ,730,220,5); ADC_SoftwareStartConv(ADC2);/* Start ADC Software Conversion */ //if(DMA_GetFlagStatus(DMA2_Stream3,DMA_FLAG_TCIF2) == SET) //{ for(i=0; i<ADC_CH_NUM; i++) { sum=0; for(j=0; j<ADC_CONV_COUNT; j++) sum+=adc_value[j*ADC_CONV_COUNT+i]; adc_value_final=sum/ADC_CONV_COUNT; } DMA_ClearFlag(DMA2_Stream3,DMA_FLAG_TCIF3); //} } /**** ???????¨?¨?????? */ int ADC_GetChannelValue(u8 ch) { if(ch<=0 || ch >ADC_CH_NUM) { return -1; } else { return adc_value_final[ch-1]; } } void NVIC_Config_DMA2(void) { NVIC_InitTypeDef NVIC_InitStructure;//???????í?????????????????á?????ü???????????á???????????? TIM_GenerateEvent NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);/*?è??NVIC??????·?×é??·????? // ×???1?????????¨??????????????×???3?????????¨?ì???????? // ??????????·?×é???????????????????????ì?????????????????????????÷????????·????÷??????????×??ù???????? // ???????ò?????????è?¨???? */ NVIC_InitStructure.NVIC_IRQChannel = DMA2_Stream3_IRQn; //?????????à?????????¨??????TIM2 ??????????????????IRQn_Type NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //?è???????????? NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //?è???ì???????? NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //???????¨???????? NVIC_Init(&NVIC_InitStructure);//?÷?????????????????????????? } void DMA2_Stream3_IRQHandler(void) { GUI_DispDecAt(DMA_GetITStatus(DMA2_Stream3 , DMA_IT_TCIF3) ,750,190,5); if(DMA_GetITStatus(DMA2_Stream3 , DMA_IT_TCIF3) == SET) { DMA_ClearITPendingBit(DMA2_Stream3 , DMA_IT_TCIF3); ADC_Sampling(); } } [/mw_shl_code]

,,

正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

11

主题

62

帖子

0

精华

初级会员

Rank: 2

积分
126
金钱
126
注册时间
2014-9-6
在线时间
0 小时
发表于 2015-1-6 16:19:02 | 显示全部楼层
这代码你自己看过没?那么多显示不出来的注释是什么原因搞清楚没?
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165309
金钱
165309
注册时间
2010-12-1
在线时间
2108 小时
发表于 2015-1-6 22:51:46 | 显示全部楼层
帮顶....
回复

使用道具 举报

8

主题

30

帖子

0

精华

初级会员

Rank: 2

积分
88
金钱
88
注册时间
2014-9-15
在线时间
2 小时
 楼主| 发表于 2015-1-7 14:53:35 | 显示全部楼层
回复【2楼】吴工wyy:
---------------------------------
注释显示不出来是因为字体是中文的原因,把代码复制到keil中就可以看到注释了,程序运行和代码没关系啊,,
回复

使用道具 举报

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

本版积分规则



关闭

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

正点原子公众号

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

GMT+8, 2024-11-23 12:54

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

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