你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

STM32F303RE官方开发板ADC+DMA异常

[复制链接]
Kimwolf 提问时间:2016-8-9 21:47 /
现象为ADC1DualConvertedValue【0】与ADC1DualConvertedValue【1】数据正常
ADC1DualConvertedValue【3】也就是ADC1通道4数据异常
请各位大神帮帮忙
  1. /* 宏定义 --------------------------------------------------------------------*/
  2. #define ADC1_CDR_ADDRESS    ((uint32_t)&ADC1->DR)
  3. #define ADC2_CDR_ADDRESS    ((uint32_t)&ADC2->DR)

  4. /* 变量 ----------------------------------------------------------------------*/  
  5. extern        u16 ADC1DualConvertedValue[4];
  6. extern        u16 ADC2DualConvertedValue[3];

  7. void K_DMA_Configuration(void)
  8. {
  9.         DMA_InitTypeDef DMA_InitStructure;
  10.   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
  11.         RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);

  12.   DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_CDR_ADDRESS;                                                                        //Specifies the peripheral base address for DMAy Channelx.
  13.   DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ADC1DualConvertedValue;                        //Specifies the memory base address for DMAy Channelx
  14.   DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;                                                                                                                //Specifies if the peripheral is the source or destination
  15.   DMA_InitStructure.DMA_BufferSize = 3;                                                                                                                                                                        //Specifies the buffer size, in data unit, of the specified Channel
  16.   DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;                                                        //Specifies whether the Peripheral address register is incremented or not.
  17.   DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;                                                                                                //Specifies whether the memory address register is incremented or not.
  18.   DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;                //Specifies the Peripheral data width
  19.   DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;                                                //Specifies the Memory data width.
  20.   DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;                                                                                                                                //Specifies the operation mode of the DMAy Channelx.
  21.   DMA_InitStructure.DMA_Priority = DMA_Priority_High;                                                                                                                //Specifies the software priority for the DMAy Channelx
  22.   DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;                                                                                                                                        //Specifies if the DMAy Channelx will be used in memory-to-memory transfer.
  23.   DMA_Init(DMA1_Channel1, &DMA_InitStructure);
  24.         
  25.   DMA_InitStructure.DMA_PeripheralBaseAddr = ADC2_CDR_ADDRESS;
  26.   DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ADC2DualConvertedValue;
  27.         DMA_Init(DMA2_Channel1, &DMA_InitStructure);

  28.   DMA_Cmd(DMA1_Channel1, ENABLE);
  29.   DMA_Cmd(DMA2_Channel1, ENABLE);
  30. }  

  31. void  K_Adc_Init(void)
  32. {         
  33.         ADC_CommonInitTypeDef ADC_CommonInitStructure;
  34.         ADC_InitTypeDef       ADC_InitStructure;         
  35.         GPIO_InitTypeDef                         GPIO_InitStructure;
  36.         
  37.         RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div1);                //配置ADC时钟
  38.         RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
  39.         RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12, ENABLE);
  40.                      
  41.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_3|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;        //ADC1 CH124 ADC2 CH234
  42.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;                //模拟输入引脚
  43.   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  44.         GPIO_Init(GPIOA, &GPIO_InitStructure);        
  45.         
  46.   ADC_StructInit(&ADC_InitStructure);

  47.   ADC_VoltageRegulatorCmd(ADC1, ENABLE);
  48.   ADC_VoltageRegulatorCmd(ADC2, ENABLE);
  49.   delay_ms(10);
  50.   
  51.   ADC_SelectCalibrationMode(ADC1, ADC_CalibrationMode_Single);
  52.   ADC_StartCalibration(ADC1);
  53.   ADC_SelectCalibrationMode(ADC2, ADC_CalibrationMode_Single);
  54.   ADC_StartCalibration(ADC2);
  55.   
  56.   while(ADC_GetCalibrationStatus(ADC1) != RESET );
  57. //  calibration_value_1 = ADC_GetCalibrationValue(ADC1);
  58.   while(ADC_GetCalibrationStatus(ADC2) != RESET );
  59. //  calibration_value_2 = ADC_GetCalibrationValue(ADC2);
  60.    
  61.   ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;            //ADC independent mode                                                     
  62.   ADC_CommonInitStructure.ADC_Clock = ADC_Clock_SynClkModeDiv1;                                //Synchronous clock mode divided by 1                    
  63.   ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_1;          //DMA12~10位分辨率         
  64.   ADC_CommonInitStructure.ADC_DMAMode = ADC_DMAMode_Circular;         //DMA连续模式         
  65.   ADC_CommonInitStructure.ADC_TwoSamplingDelay = 2;                                                                          //采样延迟0~f      
  66.   ADC_CommonInit(ADC1, &ADC_CommonInitStructure);
  67.         ADC_CommonInit(ADC2, &ADC_CommonInitStructure);
  68.   
  69.   ADC_InitStructure.ADC_ContinuousConvMode = ADC_ContinuousConvMode_Enable;                                //连续转换
  70.   ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;                                                                                                         //12位精度
  71.   ADC_InitStructure.ADC_ExternalTrigConvEvent = ADC_ExternalTrigConvEvent_0;                        //ADC external trigger event 0
  72.   ADC_InitStructure.ADC_ExternalTrigEventEdge = ADC_ExternalTrigEventEdge_None;                //ADC No external trigger for regular conversion
  73.   ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;                                                                                                        //ADC Data alignment right                                                                                                        
  74.   ADC_InitStructure.ADC_OverrunMode = ADC_OverrunMode_Disable;                                                                                //ADC Overrun Mode disable   
  75.   ADC_InitStructure.ADC_AutoInjMode = ADC_AutoInjec_Disable;                                                                                        //ADC Auto injected Mode disable  
  76.   ADC_InitStructure.ADC_NbrOfRegChannel = 3;
  77.   ADC_Init(ADC1, &ADC_InitStructure);
  78.   ADC_Init(ADC2, &ADC_InitStructure);
  79.   
  80.   ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_1Cycles5);
  81.   ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 2, ADC_SampleTime_1Cycles5);
  82.         ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 3, ADC_SampleTime_1Cycles5);
  83.         
  84.         ADC_RegularChannelConfig(ADC2, ADC_Channel_2, 1, ADC_SampleTime_1Cycles5);
  85.         ADC_RegularChannelConfig(ADC2, ADC_Channel_3, 2, ADC_SampleTime_1Cycles5);
  86.         ADC_RegularChannelConfig(ADC2, ADC_Channel_4, 3, ADC_SampleTime_1Cycles5);

  87.   ADC_Cmd(ADC1, ENABLE);
  88.   while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_RDY));
  89.   ADC_Cmd(ADC2, ENABLE);
  90.   while(!ADC_GetFlagStatus(ADC2, ADC_FLAG_RDY));
  91.         
  92.   ADC_DMACmd(ADC1, ENABLE);
  93.   ADC_DMAConfig(ADC1, ADC_DMAMode_Circular);
  94.         ADC_DMACmd(ADC2, ENABLE);
  95.         ADC_DMAConfig(ADC2, ADC_DMAMode_Circular);

  96.   ADC_StartConversion(ADC1);
  97.         ADC_StartConversion(ADC2);        
  98. }        


复制代码


收藏 评论2 发布时间:2016-8-9 21:47

举报

2个回答
无薪税绵 回答时间:2016-8-13 17:48:48
通道4是不是被复用了?
feixiang20 回答时间:2016-8-13 19:57:59
参考意见
先调试通道4的AD,以便定位问题是AD部分还是DMA部分。
硬件上接固定电压,软件上在转换完成后把数据保存一段,然后观察数值对不对,据此判断是AD问题还是DMA问题。

评分

参与人数 1ST金币 +2 收起 理由
zero99 + 2

查看全部评分

所属标签

相似问题

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
微信公众号二维码 微信公众号
手机版二维码 手机版