Skip to main content
Ehsan Behravan
Associate II
May 6, 2017
Question

which channel which data

  • May 6, 2017
  • 9 replies
  • 2227 views
Posted on May 06, 2017 at 13:34

Hi there. i have a question about stm32f745 adc. When we use ADC in Scan mode,Continuous,Regular with Interrupt, how to detect which data is for which channel. eos flag bit is not considered in this chip. I have to use counter to know end of all conversions.it's true but i think it's not reliable. my Software and Configuration is:

Configuration:

static void MX_ADC1_Init(void)

{

ADC_ChannelConfTypeDef sConfig;

/**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)

*/

hadc1.Instance = ADC1;

hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;

hadc1.Init.Resolution = ADC_RESOLUTION_12B;

hadc1.Init.ScanConvMode = ENABLE;

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 = 3;

hadc1.Init.DMAContinuousRequests = DISABLE;

hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;

if (HAL_ADC_Init(&hadc1) != HAL_OK)

{

Error_Handler();

}

/**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

*/

sConfig.Channel = ADC_CHANNEL_4;

sConfig.Rank = 1;

sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES;

if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)

{

Error_Handler();

}

/**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

*/

sConfig.Channel = ADC_CHANNEL_5;

sConfig.Rank = 2;

if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)

{

Error_Handler();

}

/**Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.

*/

sConfig.Channel = ADC_CHANNEL_6;

sConfig.Rank = 3;

if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)

{

Error_Handler();

}

}

-------------------------------------------------------------------------------------------

Software:

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)

{

ADCValue[i]=HAL_ADC_GetValue(hadc);

i++;

if (i==3)

{

i=0;

}

}

Note: this post was migrated and contained many threaded conversations, some content may be missing.
    This topic has been closed for replies.

    9 replies

    Tesla DeLorean
    Guru
    May 7, 2017
    Posted on May 07, 2017 at 03:19

    Well the idea is that you DMA into an array which is a multiple of the sample count, and then get an interrupt when that is full, or half full, and the array is all nicely aligned.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Ehsan Behravan
    Associate II
    May 7, 2017
    Posted on May 07, 2017 at 07:17

    Thanks for your reply.

    I didn't use DMA. is there any way without DMA??

    i have to use counter for detecting which adc channel generated this data.

    is there any flag register that determine active adc channel or something like this??

    thanks alot

    S.Ma
    Principal
    May 7, 2017
    Posted on May 07, 2017 at 08:24

    If using ADC normal channels, all share a single DR per ADC. DMA is the right plumbing when continuous data flow is happening. 3 ADC for 3 DMA channels going to 3 memory buffers, if running independentlt.  Otherwise, there are some ADC flavors with injected channels which have one DR per input on some STM32.