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

stm32 ADC多通道用DMA传输问题

[复制链接]
wangyou0796 提问时间:2009-6-12 13:58 /
我现在用了4个通道进行ADC处理,但在进行DMA传输时却得不到后面的那个AD的数据,为什么?程序配置如下:
 
/******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
* File Name          : adc_main.c
* Author             : MCD Application Team
* Version            : V2.0.1
* Date               : 06/13/2008
* Description        : Main program body
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "stm32f10x_lib.h"
#include "platform_config.h"
#include
#include "lcd.h"

#define ADC1_DR_ADDRESS ((u32)0x4001244c)
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
ADC_InitTypeDef  ADC_InitStructure;
vu32 ADC_ConvertedValue[4];
extern volatile ErrorStatus HSEStartUpStatus;
extern void Delay(int data);   
/* Private function prototypes -----------------------------------------------*/
void ADC_RCC_Configuration(void);
void ADC_GPIO_Configuration(void);
void ADC_NVIC_Configuration(void);
 
/* Private functions ---------------------------------------------------------*/

/*************************************************
函数: void DMA_Config(void)
功能: DMA配置
参数: 无
返回: 无
**************************************************/
void DMA_Config(void)
{
 DMA_InitTypeDef DMA_InitStructure;//定义DMA初始化结构体
 DMA_DeInit(DMA1_Channel1);//复位DMA通道1
 DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_ADDRESS; //定义 DMA通道外设基地址=ADC1_DR_Address
 DMA_InitStructure.DMA_MemoryBaseAddr =(u32)ADC_ConvertedValue; //定义DMA通道存储器地址
 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;//指定外设为源地址
 DMA_InitStructure.DMA_BufferSize = 4;//定义DMA缓冲区大小1
 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//当前外设寄存器地址不变
 DMA_InitStructure.DMA_MemoryInc = DMA_PeripheralInc_Enable;//当前存储器地址变
 DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;//定义外设数据宽度16位
 DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; //定义存储器数据宽度16位
 DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;//DMA通道操作模式位环形缓冲模式
 DMA_InitStructure.DMA_Priority = DMA_Priority_High;//DMA通道优先级高
 DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;//禁止DMA通道存储器到存储器传输
 DMA_Init(DMA1_Channel1, &DMA_InitStructure);//初始化DMA通道1
 DMA_Cmd(DMA1_Channel1, ENABLE); //使能DMA通道1
}
 

/*******************************************************************************
* Function Name  : main
* Description    : Main program
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
int adc_main(void)
{
#ifdef DEBUG
  debug();
#endif
  /* System clocks configuration ---------------------------------------------*/
  ADC_RCC_Configuration();
  /* NVIC configuration ------------------------------------------------------*/
  ADC_NVIC_Configuration();
  /* GPIO configuration ------------------------------------------------------*/
  ADC_GPIO_Configuration();
  /* ADC1 Configuration ------------------------------------------------------*/
  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;//
  ADC_InitStructure.ADC_ScanConvMode = ENABLE;
  ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
  ADC_InitStructure.ADC_NbrOfChannel = 4;
  ADC_Init(ADC1, &ADC_InitStructure);

  DMA_Config();
  /* ADC1 regular channel10--13 configuration */ 
  ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_239Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 2, ADC_SampleTime_239Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 3, ADC_SampleTime_239Cycles5);
  ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 4, ADC_SampleTime_239Cycles5);

  
  printf("please watch the led1,if it light on and off ,adc ok!\n");
  /* ADC1 regular channel8 configuration */
//  ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 1, ADC_SampleTime_13Cycles5);
  /* Configure high and low analog watchdog thresholds */
//  ADC_AnalogWatchdogThresholdsConfig(ADC1, 0x0B00, 0x0300);
  /* Configure channel8 as the single analog watchdog guarded channel */
//  ADC_AnalogWatchdogSingleChannelConfig(ADC1, ADC_Channel_8);
  /* Enable analog watchdog on one regular channel */
//  ADC_AnalogWatchdogCmd(ADC1, ADC_AnalogWatchdog_SingleRegEnable);
 
 
   /* Enable ADC1 DMA */
      ADC_DMACmd(ADC1, ENABLE); 
 /* Enable AWD interupt */
  
//  ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);
  /* Enable DMA Channel1 complete transfer interrupt */
//  DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE);
  /* Enable ADC1 */
  ADC_Cmd(ADC1, ENABLE);
  /* Enable ADC1 reset calibaration register */  
  ADC_ResetCalibration(ADC1);
  /* Check the end of ADC1 reset calibration register */
  while(ADC_GetResetCalibrationStatus(ADC1));
  /* Start ADC1 calibaration */
  ADC_StartCalibration(ADC1);
  /* Check the end of ADC1 calibration */
  while(ADC_GetCalibrationStatus(ADC1));
  /* Start ADC1 Software Conversion */
  ADC_SoftwareStartConvCmd(ADC1, ENABLE);
// ADC1->CR2 |= 0X00400000;
   while(!DMA_GetFlagStatus(DMA1_FLAG_TC1));
  /* Clear Channel 1 DMA_FLAG_TC flag */
  DMA_ClearFlag(DMA1_FLAG_TC1);
  while (1)
  {
   Delay(1000);
//   printf("%d,%d,%d,%d\n",ADC_ConvertedValue[0],ADC_ConvertedValue[1],ADC_ConvertedValue[2],ADC_ConvertedValue[3]);
  }
}
/*******************************************************************************
* Function Name  : ADC_RCC_Configuration
* Description    : Configures the different system clocks.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void ADC_RCC_Configuration(void)
{
  /* RCC system reset(for debug purpose) */
  RCC_DeInit();
  /* Enable HSE */
  RCC_HSEConfig(RCC_HSE_ON);
  /* Wait till HSE is ready */
  HSEStartUpStatus = RCC_WaitForHSEStartUp();
  if(HSEStartUpStatus == SUCCESS)
  {
    /* Enable Prefetch Buffer */
    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
    /* Flash 2 wait state */
    FLASH_SetLatency(FLASH_Latency_2);
 
    /* HCLK = SYSCLK */
    RCC_HCLKConfig(RCC_SYSCLK_Div1);
 
    /* PCLK2 = HCLK */
    RCC_PCLK2Config(RCC_HCLK_Div1);
    /* PCLK1 = HCLK/2 */
    RCC_PCLK1Config(RCC_HCLK_Div2);
    /* ADCCLK = PCLK2/4 */
    RCC_ADCCLKConfig(RCC_PCLK2_Div4);
 
    /* PLLCLK = 8MHz * 9 = 72 MHz */
    RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
    /* Enable PLL */
    RCC_PLLCmd(ENABLE);
    /* Wait till PLL is ready */
    while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
    {
    }
    /* Select PLL as system clock source */
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
    /* Wait till PLL is used as system clock source */
    while(RCC_GetSYSCLKSource() != 0x08)
    {
    }
  }
/* Enable peripheral clocks --------------------------------------------------*/
  /* Enable ADC1 and GPIO_LED clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIO_LED, ENABLE);
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
}
/*******************************************************************************
* Function Name  : ADC_GPIO_Configuration
* Description    : Configures the different GPIO ports.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void ADC_GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  /* Configure GOIO_LED pin 6 as output push-pull ----------------------------*/
//  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
//  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
//  GPIO_Init(GPIO_LED, &GPIO_InitStructure);
  /* Configure PC.00---PC0.03 (ADC Channel8) 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_AIN;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
}
/*******************************************************************************
* Function Name  : NVIC_Configuration
* Description    : Configures NVIC and Vector Table base location.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void ADC_NVIC_Configuration(void)
{
//  NVIC_InitTypeDef NVIC_InitStructure;
#ifdef  VECT_TAB_RAM 
  /* Set the Vector Table base location at 0x20000000 */
  NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else  /* VECT_TAB_FLASH  */
  /* Set the Vector Table base location at 0x08000000 */
  NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);  
#endif
  /* Configure and enable ADC interrupt */
//  NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQChannel;
//  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
//  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
 // NVIC_Init(&NVIC_InitStructure);
}
 
每次在ADC_ConvertedValue里只有一个数据?其它的数据为0,请大家分析下?谢谢!
 
收藏 评论4 发布时间:2009-6-12 13:58

举报

4个回答
gkfwsq 回答时间:2009-9-4 19:13:58

RE:stm32 ADC多通道用DMA传输问题

用DMA的中断,别用adc的EOC中断
gkfwsq 回答时间:2009-9-4 19:16:16

RE:stm32 ADC多通道用DMA传输问题

用DMA的中断,别用adc的EOC中断
sheweiwei 回答时间:2009-12-1 16:30:07

RE:stm32 ADC多通道用DMA传输问题

DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; //定义存储器数据宽度16位
*****可能应修改存储器数据宽度宽度为32*****
fzxuecumt 回答时间:2009-12-3 21:42:39

RE:stm32 ADC多通道用DMA传输问题

楼上正解!!!!

所属标签

相似问题

关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新和工艺
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版