cancel
Showing results for 
Search instead for 
Did you mean: 

Injected ADC channels only return 1 value

Daniel O'Neill
Associate II
Posted on January 24, 2018 at 09:44

I'm using an STM32F401RET with code generated in the cube(v4.23) with F4 library(v1.18).

The ADC is set up to sample one channel under a trigger from a timer with the values going to DMA. When 256 samples have been collected the conversion complete call back is called and I copy the data off and start an injected sequence consisting of CH15, Vref and Temp ADC channels.

When I do this only the first injected channel data register has data in it. I have gone through the config register values and they all look correct.

Also if I manually change the ADC_JSQR->JL value then the captured adc value changes, and follows the order of the ranked values. I.e. Len=3 result=rank1_ADC, 

Len=2 result=rank2_ADC, Len=1 result=rank3_ADC.

User code below(removed data storing):

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)

{

HAL_ADC_Stop_DMA(&hadc1);

HAL_ADCEx_InjectedStart(hadc);

HAL_ADCEx_InjectedPollForConversion(hadc,8);

HAL_ADC_Start_DMA(&hadc1, (uint32_t *)acBatteryDataDMA, ADC_AC_DATA_LEN);

}

Config Code below:

void MX_ADC1_Init(void)

{

ADC_ChannelConfTypeDef sConfig;

ADC_InjectionConfTypeDef sConfigInjected;

/**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 = DISABLE;

hadc1.Init.ContinuousConvMode = DISABLE;

hadc1.Init.DiscontinuousConvMode = DISABLE;

hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;

hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T2_TRGO;

hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;

hadc1.Init.NbrOfConversion = 1;

hadc1.Init.DMAContinuousRequests = DISABLE;

hadc1.Init.EOCSelection = ADC_EOC_SEQ_CONV;

if (HAL_ADC_Init(&hadc1) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

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

*/

sConfig.Channel = ADC_CHANNEL_14;

sConfig.Rank = 1;

sConfig.SamplingTime = ADC_SAMPLETIME_112CYCLES;

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

{

_Error_Handler(__FILE__, __LINE__);

}

/**Configures for the selected ADC injected channel its corresponding rank in the sequencer and its sample time

*/

sConfigInjected.InjectedChannel = ADC_CHANNEL_15;

sConfigInjected.InjectedRank = 1;

sConfigInjected.InjectedNbrOfConversion = 3;

sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_112CYCLES;

sConfigInjected.ExternalTrigInjecConvEdge = ADC_EXTERNALTRIGINJECCONVEDGE_NONE;

sConfigInjected.ExternalTrigInjecConv = ADC_INJECTED_SOFTWARE_START;

sConfigInjected.AutoInjectedConv = DISABLE;

sConfigInjected.InjectedDiscontinuousConvMode = DISABLE;

sConfigInjected.InjectedOffset = 0;

if (HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

/**Configures for the selected ADC injected channel its corresponding rank in the sequencer and its sample time

*/

sConfigInjected.InjectedChannel = ADC_CHANNEL_VREFINT;

//sConfigInjected.InjectedChannel = ADC_CHANNEL_14;

sConfigInjected.InjectedRank = 2;

if (HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

/**Configures for the selected ADC injected channel its corresponding rank in the sequencer and its sample time

*/

sConfigInjected.InjectedChannel = ADC_CHANNEL_TEMPSENSOR;

sConfigInjected.InjectedRank = 3;

if (HAL_ADCEx_InjectedConfigChannel(&hadc1, &sConfigInjected) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

}

0 REPLIES 0