打印
[STM32F3]

求助4通道SDADC采集问题,只能获取三个?

[复制链接]
1683|7
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
DongweiMiao|  楼主 | 2015-7-30 16:46 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
使用SDADC1的0P,SDADC2的0P,SDADC3的0P和1P,SDADC的0P(channel_0)没取得数据

配置如下
SDADC_AINStructTypeDef SDADC_AINStructure;
  GPIO_InitTypeDef   GPIO_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;
        DMA_InitTypeDef     DMA_InitStructure;
  uint32_t SDADCTimeout = 0;
  
  /* HADA6017_SDADC APB2 interface clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SDADC1|RCC_APB2Periph_SDADC2|RCC_APB2Periph_SDADC3, ENABLE);
  /* PWR APB1 interface clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
  /* Enable HADA6017_SDADC analog interface */
  PWR_SDADCAnalogCmd(PWR_SDADCAnalog_1|PWR_SDADCAnalog_2|PWR_SDADCAnalog_3, ENABLE);

  /* Set the SDADC divider: The SDADC should run @6MHz */
  /* If Sysclk is 72MHz, SDADC divider should be 12 */
  RCC_SDADCCLKConfig(RCC_SDADCCLK_SYSCLK_Div12);
        /* GPIOE Peripheral clock enable */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOE|RCC_AHBPeriph_GPIOD, ENABLE);
        GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Pin   =  GPIO_Pin_12 | GPIO_Pin_15;
  GPIO_Init(GPIOE, &GPIO_InitStructure);
        GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Pin   =  GPIO_Pin_14 | GPIO_Pin_13;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

  SDADC_VREFSelect(SDADC_VREF_Ext);
  //---------------------------//
  Delay(5);
  
  /* Enable HADA6017_SDADC */
  SDADC_Cmd(SDADC1, ENABLE);
        SDADC_Cmd(SDADC2, ENABLE);
        SDADC_Cmd(SDADC3, ENABLE);
  /* Enter initialization mode */
  SDADC_InitModeCmd(SDADC1, ENABLE);
        SDADC_InitModeCmd(SDADC2, ENABLE);
        SDADC_InitModeCmd(SDADC3, ENABLE);
  SDADCTimeout = SDADC_INIT_TIMEOUT;
  /* wait for INITRDY flag to be set */
  while((SDADC_GetFlagStatus(SDADC1, SDADC_FLAG_INITRDY) == RESET) && (--SDADCTimeout != 0));
  if(SDADCTimeout == 0)
  {
    /* INITRDY flag is not set */
    return 1;
  }
        SDADC_AINStructure.SDADC_InputMode = SDADC_InputMode_SEZeroReference;//;SDADC_InputMode_SEOffset
  SDADC_AINStructure.SDADC_Gain = SDADC_Gain_1;
  SDADC_AINStructure.SDADC_CommonMode = SDADC_CommonMode_VSSA;
  SDADC_AINStructure.SDADC_Offset = 0;
  SDADC_AINInit(SDADC1, SDADC_Conf_0, &SDADC_AINStructure);
        SDADC_AINInit(SDADC2, SDADC_Conf_0, &SDADC_AINStructure);
        SDADC_AINInit(SDADC3, SDADC_Conf_0, &SDADC_AINStructure);
//        SDADC_AINInit(SDADC3, SDADC_Conf_1, &SDADC_AINStructure);
       
  SDADC_ChannelConfig(SDADC1, SDADC_Channel_0, SDADC_Conf_0);
        SDADC_ChannelConfig(SDADC2, SDADC_Channel_0, SDADC_Conf_0);
        SDADC_ChannelConfig(SDADC3, SDADC_Channel_0, SDADC_Conf_0);
        SDADC_ChannelConfig(SDADC3, SDADC_Channel_1, SDADC_Conf_0);
  /* select channel 0 */
  SDADC_InjectedChannelSelect(SDADC1, SDADC_Channel_0);
        SDADC_InjectedChannelSelect(SDADC2, SDADC_Channel_0);
        SDADC_InjectedChannelSelect(SDADC3, SDADC_Channel_0);
        SDADC_InjectedChannelSelect(SDADC3, SDADC_Channel_1);
  /* Select an external trigger */
  SDADC_ExternalTrigInjectedConvConfig(SDADC1, SDADC_ExternalTrigInjecConv_T19_CC2);
        SDADC_ExternalTrigInjectedConvConfig(SDADC2, SDADC_ExternalTrigInjecConv_T19_CC3);
        SDADC_ExternalTrigInjectedConvConfig(SDADC3, SDADC_ExternalTrigInjecConv_T19_CC4);
  /* Select rising edge */
  SDADC_ExternalTrigInjectedConvEdgeConfig(SDADC1, SDADC_ExternalTrigInjecConvEdge_Rising);
        SDADC_ExternalTrigInjectedConvEdgeConfig(SDADC2, SDADC_ExternalTrigInjecConvEdge_Rising);
        SDADC_ExternalTrigInjectedConvEdgeConfig(SDADC3, SDADC_ExternalTrigInjecConvEdge_Rising);
  /* Exit initialization mode */
  SDADC_InitModeCmd(SDADC1, DISABLE);
        SDADC_InitModeCmd(SDADC2, DISABLE);
        SDADC_InitModeCmd(SDADC3, DISABLE);
  /* Enable end of injected conversion interrupt */
  SDADC_ITConfig(SDADC1, SDADC_IT_JEOC, ENABLE);
        SDADC_ITConfig(SDADC3, SDADC_IT_JEOC, ENABLE);
        SDADC_ITConfig(SDADC2, SDADC_IT_JEOC, ENABLE);

  /* NVIC Configuration */
  NVIC_InitStructure.NVIC_IRQChannel = SDADC1_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
       
        NVIC_InitStructure.NVIC_IRQChannel = SDADC2_IRQn;
  NVIC_Init(&NVIC_InitStructure);
       
        NVIC_InitStructure.NVIC_IRQChannel = SDADC3_IRQn;
  NVIC_Init(&NVIC_InitStructure);

  /* configure calibration to be performed on conf0 */
  SDADC_CalibrationSequenceConfig(SDADC1, SDADC_CalibrationSequence_1);
        SDADC_CalibrationSequenceConfig(SDADC2, SDADC_CalibrationSequence_1);
        SDADC_CalibrationSequenceConfig(SDADC3, SDADC_CalibrationSequence_1);
  /* start HADA6017_SDADC Calibration */
  SDADC_StartCalibration(SDADC1);
        SDADC_StartCalibration(SDADC2);
        SDADC_StartCalibration(SDADC3);
  /* Set calibration timeout: 5.12 ms at 6 MHz in a single calibration sequence */
  SDADCTimeout = SDADC_CAL_TIMEOUT;
  /* wait for HADA6017_SDADC Calibration process to end */
  while((SDADC_GetFlagStatus(SDADC1, SDADC_FLAG_EOCAL) == RESET) && (--SDADCTimeout != 0));

  if(SDADCTimeout == 0)
  {
    /* EOCAL flag can not set */
    return 2;
  }
SDADC_SoftwareStartInjectedConv(SDADC3);

中断处理:
if(SDADC_GetFlagStatus(SDADC3, SDADC_FLAG_JEOC) != RESET)//SDADC_FLAG_JEOC
  {
    nAdVal= SDADC_GetInjectedConversionValue(SDADC3, &ChannelIndex);
                if(ChannelIndex == 1)
                {
                        adValue[2][ad2cnt]=nAdVal;ad2cnt++;
                        if(ad2cnt>=para[SAMP_NUM].i1)
                        {
                                ad2cnt = 0;dis[31].i1++;
                        }
                }
                if(ChannelIndex == 0x10002)
                {
                        adValue[3][ad3cnt]=nAdVal;ad3cnt++;
                        if(ad3cnt>=para[SAMP_NUM].i1)
                        {
                                ad3cnt = 0;
                        }
                }

  }
评论
仰望星期五 2020-11-19 11:53 回复TA
最近在这里也遇到点问题,能沟通下吗。Q1179552873 
沙发
DongweiMiao|  楼主 | 2015-7-31 10:00 | 只看该作者
找到原因了

使用特权

评论回复
板凳
amanda_s| | 2015-7-31 17:13 | 只看该作者
什么原因?也给大家分享一下吧。

使用特权

评论回复
地板
DongweiMiao|  楼主 | 2015-8-1 07:49 | 只看该作者
amanda_s 发表于 2015-7-31 17:13
什么原因?也给大家分享一下吧。

SDADC_InjectedChannelSelect(SDADC3, SDADC_Channel_0);
SDADC_InjectedChannelSelect(SDADC3, SDADC_Channel_1);
改为
SDADC_InjectedChannelSelect(SDADC3, SDADC_Channel_0|SDADC_Channel_1);

使用特权

评论回复
评论
仰望星期五 2020-11-19 11:53 回复TA
最近在这里也遇到点问题,能沟通下吗。Q1179552873 
5
PT2016| | 2019-10-23 13:36 | 只看该作者
你好,请问你还有stm32f373的sdadc相关历程可以参考吗

使用特权

评论回复
6
香水城| | 2020-11-19 16:52 | 只看该作者
stm32CubeF3的库里有例程 可以参考。

\Repository\STM32Cube_FW_F3_V1.11.1\Projects\STM32373C_EVAL\Examples\SDADC

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

9

主题

49

帖子

1

粉丝