cancel
Showing results for 
Search instead for 
Did you mean: 

SDADC1 does not work when start the DMA on STM32F373

dongjingui
Associate
Posted on July 18, 2013 at 04:17

Hi,everyone

I have a question about SDADC and DMA.when I

enable

the DMA with'' DMA_Cmd(DMA2_Channel3, ENABLE)'' in program and the SDADC1 stop convert immediately.

here is my code:

void SDADC1_Config()

 {

   SDADC_InitTypeDef SDADC_InitStructure;

   SDADC_AINStructTypeDef SDADC_AINStructure;

   GPIO_InitTypeDef GPIO_InitStructure;

      

    

   uint32_t SDADCTimeout = 0;

   RCC_APB2PeriphClockCmd(RCC_APB2Periph_SDADC1, ENABLE);

   

   SDADC_DeInit(SDADC1);  

   /* PWR APB1 interface clock enable */

   RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);

   

   /* Enable SDADC analog interface */

   PWR_SDADCAnalogCmd(PWR_SDADCAnalog_1, 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);

   /* GPIO Peripheral clock enable */

   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOE, ENABLE);

   /* SDADC channel 3P pin configuration: PE7 */

   GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_AN;

   GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

   GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_7;

   GPIO_Init(GPIOE, &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);

   /* Insert delay equal to ~5 ms */

//    Delay(2);

   SDADC_Cmd(SDADC1, ENABLE);

   SDADC_InitModeCmd(SDADC1, ENABLE);

   SDADCTimeout = 30;

   /* wait for INITRDY flag to be set */

   while((SDADC_GetFlagStatus(SDADC1, SDADC_FLAG_INITRDY) == RESET) && (--SDADCTimeout != 0));

//    if(SDADCTimeout == 0)

//    {

//      /* INITRDY flag can not set */

//      return 1;

//    }

   

   SDADC_AINStructure.SDADC_InputMode =SDADC_InputMode_SEOffset; //SDADC_InputMode_SEZeroReference;

   SDADC_AINStructure.SDADC_Gain =  SDADC_Gain_1_2;//GAIN is 0.5

   SDADC_AINStructure.SDADC_CommonMode = SDADC_CommonMode_VSSA;

   SDADC_AINStructure.SDADC_Offset = 0;

   SDADC_AINInit(SDADC1, SDADC_Conf_0, &SDADC_AINStructure);

 

   /* Channel3 configuration */

   SDADC_InitStructure.SDADC_Channel = SDADC_Channel_3;

   SDADC_InitStructure.SDADC_ContinuousConvMode = ENABLE;

   SDADC_InitStructure.SDADC_FastConversionMode = DISABLE;

   SDADC_Init(SDADC1, &SDADC_InitStructure);

    

     SDADC_DMAConfig(SDADC1,SDADC_DMATransfer_Regular, ENABLE);

     SDADC_ChannelConfig(SDADC1, SDADC_Channel_3, SDADC_Conf_0);

    

   SDADC_InitModeCmd(SDADC1, DISABLE);

      

   /* configure calibration to be performed on conf0 */

   SDADC_CalibrationSequenceConfig(SDADC1, SDADC_CalibrationSequence_1);

   /* start PT100_SDADC Calibration */

   SDADC_StartCalibration(SDADC1);

   /* Set calibration timeout: 5.12 ms at 6 MHz in a single calibration sequence */

   SDADCTimeout = 4*30720 ;

   /* wait for PT100_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 successfully configured */

//    return 0;

 

    SDADC_SoftwareStartConv(SDADC1);   

      

 }    

    

 

 void DMA2_Configuration(void)

{

    DMA_InitTypeDef   DMA_InitStructure;

  NVIC_InitTypeDef NVIC_InitStructure;

  /* Enable DMA2 clock */

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);

 

  /* Config the DMA2 channel 3 */

  DMA_DeInit(DMA2_Channel3);

 

  DMA_InitStructure.DMA_PeripheralBaseAddr  = ((uint32_t)&SDADC1->RDATAR);

  DMA_InitStructure.DMA_MemoryBaseAddr      = (uint32_t)&Volt_Buffer;

  DMA_InitStructure.DMA_DIR                 = DMA_DIR_PeripheralSRC;

  DMA_InitStructure.DMA_BufferSize          = N;

  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_Low;

  DMA_InitStructure.DMA_M2M                 = DMA_M2M_Disable;

  DMA_Init(DMA2_Channel3, &DMA_InitStructure);

    

    

    NVIC_InitStructure.NVIC_IRQChannel = DMA2_Channel3_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

      

  /* Enable DMA2 Channel3 Transfer half and Complete interrupt */

  DMA_ITConfig(DMA2_Channel3, DMA_IT_TC , ENABLE);

    

       /* Enable DMA2 Channel3 */

  DMA_Cmd(DMA2_Channel3, ENABLE);

 

}

 

Who can tell me,how to use 16bit SDADC with DMA??  

2 REPLIES 2
Posted on July 18, 2013 at 04:58

Unfortunately the code is insufficiently complete to really evaluate.

One line does trouble me, and suspect it causes the DMA to fault.

DMA_InitStructure.DMA_MemoryBaseAddr      = (uint32_t)&Volt_Buffer;

I don't see a definition for the buffer but assume it's uint16_t Volt_Buffer[N];

The correct code would be

DMA_InitStructure.DMA_MemoryBaseAddr      = (uint32_t)&Volt_Buffer[0];

or

DMA_InitStructure.DMA_MemoryBaseAddr      = (uint32_t)Volt_Buffer;
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
dongjingui
Associate
Posted on July 18, 2013 at 05:22

thanks very much!  I changed ,but the SDADC is still does not work......