打印
[STM32F3]

用stm32f373的sdadc采样的问题

[复制链接]
4866|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
c914620529|  楼主 | 2015-4-24 09:22 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 c914620529 于 2015-4-24 09:23 编辑

配置了sdadc  基本都是参考st官方固件的   但是官方的例程中用的中断读取采样的值,但是又没有写中断,不知道adc返回的值是怎么弄的,我配置好之后读取的值都是-32768,不知道怎么回事。。我用的查询的方式读取的,请大神们看看怎么回事
void SDADC3_Config(void)
{
  

  SDADC_AINStructTypeDef SDADC_AINStructure;
  GPIO_InitTypeDef   GPIO_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;
// DMA_InitTypeDef   DMA_InitStructure;
//  SDADC_InitTypeDef SDADC_InitStructure;
  
  uint32_t SDADCTimeout = 0;
  
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);
  /* MPX2102_SDADC APB2 interface clock enable */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SDADC3, ENABLE);

  /* PWR APB1 interface clock enable */
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
  /* Enable MPX2102_SDADC analog interface */
  PWR_SDADCAnalogCmd(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_Div8);

  /* GPIOE Peripheral clock enable */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOD, ENABLE);

  /* MPX2102_SDADC channel D8 */
  GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Pin   =   GPIO_Pin_8 ;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

  /* Select External reference: The reference voltage selection is available
     only in SDADC1 and therefore to select the VREF for SDADC2/SDADC3, SDADC1
     clock must be already enabled */
  SDADC_VREFSelect(SDADC_VREF_Ext );

  
  /* Enable MPX2102_SDADC */
  SDADC_Cmd(SDADC3, ENABLE);

  /* Enter initialization mode */
  SDADC_InitModeCmd(SDADC3, ENABLE);
  SDADCTimeout = 30;
  /* wait for INITRDY flag to be set */
  while(SDADC_GetFlagStatus(SDADC3, SDADC_FLAG_INITRDY) == RESET );

//  if(SDADCTimeout == 0)
//  {
//    /* INITRDY flag is not set */
//    return 1;
//  }

  /* Analog Input configuration conf0: use differential mode and gain = 4 */
  SDADC_AINStructure.SDADC_InputMode = SDADC_InputMode_SEZeroReference;
  SDADC_AINStructure.SDADC_Gain = SDADC_Gain_1  ;
  SDADC_AINStructure.SDADC_CommonMode = SDADC_CommonMode_VSSA;
  SDADC_AINStructure.SDADC_Offset = 0;
  SDADC_AINInit(SDADC3, SDADC_Conf_0, &SDADC_AINStructure);

  /* Enable DMA transfer for injected conversions */
  //SDADC_DMAConfig(SDADC3, SDADC_DMATransfer_Injected, ENABLE);
  
  /* select MPX2102_SDADC channel 6 to use conf0 */
  SDADC_ChannelConfig(SDADC3, SDADC_Channel_6, SDADC_Conf_0);

//  /* select channel 8 */
  SDADC_InjectedChannelSelect(SDADC3, SDADC_Channel_6);
  SDADC_InjectedContinuousModeCmd(SDADC3,ENABLE);
  
//      /* Channel configuration for regular conversion*/
//        SDADC_InitStructure.SDADC_Channel = SDADC_Channel_6;
//        SDADC_InitStructure.SDADC_ContinuousConvMode = DISABLE;
//        SDADC_InitStructure.SDADC_FastConversionMode = DISABLE;
//        SDADC_Init(SDADC3, &SDADC_InitStructure);
//  
//        SDADC_RegularSynchroSDADC1(SDADC3,ENABLE);
         
  /* Select an external trigger */
SDADC_ExternalTrigInjectedConvConfig(SDADC3, SDADC_ExternalTrigInjecConv_T19_CC4);
//  /* Select rising edge */
  SDADC_ExternalTrigInjectedConvEdgeConfig(SDADC3, SDADC_ExternalTrigInjecConvEdge_Rising);

  /* Exit initialization mode */
  SDADC_InitModeCmd(SDADC3, DISABLE);

//  /* Enable end of injected conversion interrupt */
//  SDADC_ITConfig(SDADC3, SDADC_IT_JEOC, ENABLE);
//
// // SDADC_SoftwareStartInjectedConv(SDADC3);
//  
//  /* NVIC Configuration */
//  NVIC_InitStructure.NVIC_IRQChannel = SDADC3_IRQn;
//  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
//  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
//  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
//  NVIC_Init(&NVIC_InitStructure);

  /* configure calibration to be performed on conf0 */
  SDADC_CalibrationSequenceConfig(SDADC3, SDADC_CalibrationSequence_1);
  /* start MPX2102_SDADC Calibration */
  SDADC_StartCalibration(SDADC3);
  /* Set calibration timeout: 5.12 ms at 6 MHz in a single calibration sequence */
  SDADCTimeout = 4*30720;
  /* wait for MPX2102_SDADC Calibration process to end */
  while(SDADC_GetFlagStatus(SDADC3, SDADC_FLAG_EOCAL) == RESET);
}

在main中 一直读取返回值
while(1)
{
       if(SDADC_GetFlagStatus(SDADC3, SDADC_FLAG_JEOC) != RESET)
    {
        /* Get the converted value */
        ChannelIndex=SDADC_Channel_6;
        InjectedConvData = SDADC_GetInjectedConversionValue(SDADC3, &ChannelIndex);        }
}
并且上面SDADC_GetInjectedConversionValue函数的通道参数选择不能直接用SDADC_Channel_6  不知所以然。。

沙发
CS_Police| | 2015-4-30 17:39 | 只看该作者
不知道这个对你有没有用?
在st官网上搜索AN4207, Getting started with STM32F37x/38x SDADC (Sigma-Delta ADC)
另外可以运行一下cube库或者外设库的例子, 不要做任何关于sdadc的修改,看看结果是否有什么不同。

使用特权

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

本版积分规则

1

主题

2

帖子

0

粉丝