Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


ADC conversion for multiple channels but not together

Hi

I am using the 32MF072 device and I have 8 ADC inputs.
What I want to do is to just read each input then read another at some other time.
So I dont really want to use DMA.
I have used the code from the examples in the CUBEMX files, and I can get it to work but it
doesnt work correctly all the time. I just have a voltage set on the pin but sometimes it reads the
correct voltage and other times 0V. Here is the code below. So really I am just selecting the channel
I want then starting the conversion. But maybe I have some of the settings wrong?
Thanks
Jon

static void MX_ADC_Init(void)
{

ADC_ChannelConfTypeDef sConfig;

/**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
*/
hadc.Instance = ADC1;
hadc.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
hadc.Init.Resolution = ADC_RESOLUTION_12B;
hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD;
hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc.Init.LowPowerAutoWait = DISABLE;
hadc.Init.LowPowerAutoPowerOff = DISABLE;
hadc.Init.ContinuousConvMode = DISABLE;
hadc.Init.DiscontinuousConvMode = DISABLE;
hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc.Init.DMAContinuousRequests = DISABLE;
hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED;
if (HAL_ADC_Init(&hadc) != HAL_OK)
{
_Error_Handler(FILE, LINE);
}
}

uint16_t MX_ADC_Start(uint32_t channel)
{
ADC_ChannelConfTypeDef sConfig;
uint16_t uhADCxConvertedValue = 0;

/**Configure for the selected ADC regular channel to be converted.
*/
sConfig.Channel = channel;
sConfig.Rank = ADC_RANK_CHANNEL_NUMBER;
sConfig.SamplingTime = ADC_SAMPLETIME_28CYCLES_5;
if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK)
{
/* Starting Error */
Error_Handler();
}


/*##-3- Start the conversion process #######################################*/
if (HAL_ADC_Start(&hadc) != HAL_OK)
{
/* Start Conversation Error */
Error_Handler();
}

/*##-4- Wait for the end of conversion #####################################*/
/* For simplicity reasons, this example is just waiting till the end of the
conversion, but application may perform other tasks while conversion
operation is ongoing. */
if (HAL_ADC_PollForConversion(&hadc, 10) != HAL_OK)
{
/* End Of Conversion flag not set on time */
Error_Handler();
}
else
{
/* ADC conversion completed */
/*##-5- Get the converted value of regular channel ########################*/
uhADCxConvertedValue = HAL_ADC_GetValue(&hadc);
}

return uhADCxConvertedValue;
}

 

Newest Forum Posts

  1. Монтаж камина с грилем в Москве - установка и барбекю by KpddomErorb, 2025-05-10 18:28
  2. SPI on Nucleo_STMH533RE by royjamil, 2025-05-04 20:13
  3. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-25 07:37
  4. SPI on Nucleo_STMH533RE by royjamil, 2025-03-23 11:31
  5. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-23 09:33
  6. Configuring DMA for ADC in SW? by sam.hodgson, 2025-03-04 12:58
  7. Build a project in "release" mode by info@creosrl.it, 2025-02-20 18:12
  8. Build a project in "release" mode by info@creosrl.it, 2025-02-20 17:05
  9. Build a project in "release" mode by tang, 2025-02-20 10:36
  10. Build a project in "release" mode by info@creosrl.it, 2025-02-19 17:35

Last-Modified Blogs