AnsweredAssumed Answered

using cdc vcp with adc in dma Mode

Question asked by Jamal Panah on Dec 17, 2017
Latest reply on Dec 20, 2017 by AvaTar

Hello,

i am trying to send data from the adc over the usb otg fs as virtual com port to my pc where i receive the data with a terminal program(HTerm).

Using the ADC in 8bit Mode works perfectly. The settings are the following:

For the ADC:

  hadc1.Instance = ADC1;
  hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
  hadc1.Init.Resolution = ADC_RESOLUTION_8B;
  hadc1.Init.ScanConvMode = DISABLE;
  hadc1.Init.ContinuousConvMode = ENABLE;
  hadc1.Init.DiscontinuousConvMode = DISABLE;
  hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  hadc1.Init.NbrOfConversion = 1;
  hadc1.Init.DMAContinuousRequests = ENABLE;
  hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  if (HAL_ADC_Init(&hadc1) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }


For the DMA:

    hdma_adc1.Instance = DMA2_Stream0;
    hdma_adc1.Init.Channel = DMA_CHANNEL_0;
    hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY;
    hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE;
    hdma_adc1.Init.MemInc = DMA_MINC_ENABLE;
    hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
    hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
    hdma_adc1.Init.Mode = DMA_CIRCULAR;
    hdma_adc1.Init.Priority = DMA_PRIORITY_LOW;
    hdma_adc1.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
    if (HAL_DMA_Init(&hdma_adc1) != HAL_OK)
    {
      _Error_Handler(__FILE__, __LINE__);
    }


But now i want to use the ADC in 12bit Mode. Therefor i have to change:

For the ADC:

  hadc1.Init.Resolution = ADC_RESOLUTION_12B;

For the DMA:

    hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
    hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;

 

But now the vcp is recognized as unknown device. I also found out that specially changing the DMA_PDATAALIGN_BYTE and DMA_MDATAALIGN_BYTE to DMA_PDATAALIGN_HALFWORD and DMA_MDATAALIGN_HALFWORD leads to the problem. Does someone know what i did wrong? because i can't see any connection betweeen the usb otg and the adc.

 

Thank You!

Outcomes