cancel
Showing results for 
Search instead for 
Did you mean: 

How can I convert additional regular conversion?

Jace
Associate II

I'm using MCSDK_v5.4.3 but I don't know how can I convert additional ADC channel.

Below is ADC initialization code. added channel 9 and 10.

But I can't convert channel 9 and 10.

How can I convert ch.9 & 10.

Some sample code will very helpful to me.

Thanks

static void MX_ADC1_Init(void)

{

 /* USER CODE BEGIN ADC1_Init 0 */

 /* USER CODE END ADC1_Init 0 */

 ADC_InjectionConfTypeDef sConfigInjected = {0};

 ADC_ChannelConfTypeDef sConfig = {0};

 /* USER CODE BEGIN ADC1_Init 1 */

 /* USER CODE END ADC1_Init 1 */

 /** Common config 

 */

 hadc1.Instance = ADC1;

 hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV1;

 hadc1.Init.Resolution = ADC_RESOLUTION_12B;

 hadc1.Init.ScanConvMode = ADC_SCAN_ENABLE;

 hadc1.Init.ContinuousConvMode = DISABLE;

 hadc1.Init.DiscontinuousConvMode = DISABLE;

 hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;

 hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;

 hadc1.Init.DataAlign = ADC_DATAALIGN_LEFT;

 hadc1.Init.NbrOfConversion = 4;

 hadc1.Init.DMAContinuousRequests = DISABLE;

 hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;

 hadc1.Init.LowPowerAutoWait = DISABLE;

 hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;

 if (HAL_ADC_Init(&hadc1) != HAL_OK)

 {

  Error_Handler();

 }

 /** Configure Injected Channel 

 */

 sConfigInjected.InjectedChannel = ADC_CHANNEL_1;

 sConfigInjected.InjectedRank = ADC_INJECTED_RANK_1;

 sConfigInjected.InjectedSingleDiff = ADC_SINGLE_ENDED;

 sConfigInjected.InjectedNbrOfConversion = 3;

 sConfigInjected.InjectedSamplingTime = ADC_SAMPLETIME_19CYCLES_5;

 sConfigInjected.ExternalTrigInjecConvEdge = ADC_EXTERNALTRIGINJECCONV_EDGE_RISING;

 sConfigInjected.ExternalTrigInjecConv = ADC_EXTERNALTRIGINJECCONV_T1_TRGO;

 sConfigInjected.AutoInjectedConv = DISABLE;

 sConfigInjected.InjectedDiscontinuousConvMode = DISABLE;

 sConfigInjected.QueueInjectedContext = ENABLE;

 sConfigInjected.InjectedOffset = 0;

 sConfigInjected.InjectedOffsetNumber = ADC_OFFSET_NONE;

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

 {

Error_Handler();

 }

 /** Configure Injected Channel 

 */

 sConfigInjected.InjectedChannel = ADC_CHANNEL_7;

 sConfigInjected.InjectedRank = ADC_INJECTED_RANK_2;

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

 {

  Error_Handler();

 }

 /** Configure Injected Channel 

 */

 sConfigInjected.InjectedChannel = ADC_CHANNEL_6;

 sConfigInjected.InjectedRank = ADC_INJECTED_RANK_3;

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

 {

  Error_Handler();

 }

 /** Configure Regular Channel 

 */

 sConfig.Channel = ADC_CHANNEL_2;

 sConfig.Rank = ADC_REGULAR_RANK_1;

 sConfig.SingleDiff = ADC_SINGLE_ENDED;

 sConfig.SamplingTime = ADC_SAMPLETIME_61CYCLES_5;

 sConfig.OffsetNumber = ADC_OFFSET_NONE;

 sConfig.Offset = 0;

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

 {

  Error_Handler();

 }

 /** Configure Regular Channel 

 */

 sConfig.Channel = ADC_CHANNEL_8;

 sConfig.Rank = ADC_REGULAR_RANK_2;

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

 {

  Error_Handler();

 }

 /* USER CODE BEGIN ADC1_Init 2 */

 /** Configure Regular Channel 

 */

 sConfig.Channel = ADC_CHANNEL_9;

 sConfig.Rank = ADC_REGULAR_RANK_3;

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

 {

  Error_Handler();

 }

 /** Configure Regular Channel 

 */

 sConfig.Channel = ADC_CHANNEL_10;

 sConfig.Rank = ADC_REGULAR_RANK_4;

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

 {

  Error_Handler();

 }

 /* USER CODE END ADC1_Init 2 */

}

5 REPLIES 5
TDK
Guru

Are you saying this code converts channels 2 and 8 just fine but doesn't convert 9 and 10? Seems odd.

Make sure you're initializing the pins for channels 9/10.

If you feel a post has answered your question, please click "Accept as Solution".
Jace
Associate II

I added initializing code for 9 & 10 and pin assignment also as below.

void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc)

{

 GPIO_InitTypeDef GPIO_InitStruct = {0};

 if(hadc->Instance==ADC1)

 {

  __HAL_RCC_ADC1_CLK_ENABLE();

  __HAL_RCC_GPIOC_CLK_ENABLE();

  __HAL_RCC_GPIOA_CLK_ENABLE();

  GPIO_InitStruct.Pin = M1_CURR_AMPL_W_Pin|M1_CURR_AMPL_V_Pin|M1_TEMPERATURE_Pin|ADC_9_Pin;

  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  GPIO_InitStruct.Pin = M1_CURR_AMPL_U_Pin|M1_BUS_VOLTAGE_Pin|ADC_10_Pin;

  GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

 }

}

What I want to ask is how can I use below functions related regular conversion.

such as

uint8_t RCM_RegisterRegConv(RegConv_t * regConv);

uint8_t RCM_RegisterRegConv_WithCB (RegConv_t * regConv, RCM_exec_cb_t fctCB, void *data);

uint16_t RCM_ExecRegularConv (uint8_t handle);

bool RCM_RequestUserConv(uint8_t handle);

uint16_t RCM_GetUserConv(void);

void RCM_ExecUserConv (void);

RCM_UserConvState_t RCM_GetUserConvState(void);

Thanks

MR.3
Associate II

Hello,

Did you resolve the above issue??

if yes can you please let me know the solution?

Thank you.

Laurent Ca...
Lead II

Dear @Jace​ 

Do you have still this problem to solve?

Best regards

Laurent Ca...

Laurent Ca...
Lead II

Dear @Jace​ 

I guess you don't have to solve this problem anymore, therefore I consider this thread closed.

If not, feel free to reopen it by posting an answer.

Best regards

Laurent Ca...