2023-12-07 9:50 PM
HI,
I am trying to get ADC read but the result is only the first read repeatedly even I change the voltage on ADC channel input it remains the same,
ADC Innitialization
static void MX_ADC3_Init(void)
{
/* USER CODE BEGIN ADC3_Init 0 */
/* USER CODE END ADC3_Init 0 */
ADC_ChannelConfTypeDef sConfig = {0};
/* USER CODE BEGIN ADC3_Init 1 */
/* USER CODE END ADC3_Init 1 */
/** Common config
*/
hadc3.Instance = ADC3;
hadc3.Init.Resolution = ADC_RESOLUTION_16B;
hadc3.Init.ScanConvMode = ADC_SCAN_DISABLE;
hadc3.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
hadc3.Init.LowPowerAutoWait = DISABLE;
hadc3.Init.ContinuousConvMode = ENABLE;
hadc3.Init.NbrOfConversion = 1;
hadc3.Init.DiscontinuousConvMode = DISABLE;
hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc3.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DR;
hadc3.Init.Overrun = ADC_OVR_DATA_PRESERVED;
hadc3.Init.LeftBitShift = ADC_LEFTBITSHIFT_NONE;
hadc3.Init.OversamplingMode = DISABLE;
if (HAL_ADC_Init(&hadc3) != HAL_OK)
{
Error_Handler();
}
/** Configure Regular Channel
*/
sConfig.Channel = ADC_CHANNEL_9;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
sConfig.SingleDiff = ADC_SINGLE_ENDED;
sConfig.OffsetNumber = ADC_OFFSET_NONE;
sConfig.Offset = 0;
sConfig.OffsetSignedSaturation = DISABLE;
if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ADC3_Init 2 */
/* USER CODE END ADC3_Init 2 */
}
Main Loop
while(1)
{
HAL_ADC_Start(&hadc3);
uint16_t currentADCValue=HAL_ADC_GetValue(&hadc3);
sprintf(disp,"D1: %d\n\r",currentADCValue);
HAL_UART_Transmit(&huart8, (uint8_t*)disp, sizeof(disp), HAL_MAX_DELAY);
}
Solved! Go to Solution.
2023-12-08 6:25 AM
See a working example using HAL_ADC_DMA_Start here:
2023-12-07 10:01 PM
while(1)
{
HAL_ADC_Start(&hadc3);
HAL_ADC_PollForConversion(&hadc3,HAL_MAX_DELAY);
uint16_t currentADCValue=HAL_ADC_GetValue(&hadc3);
sprintf(disp,"D1: %d\n\r",currentADCValue);
HAL_UART_Transmit(&huart8, (uint8_t*)disp, sizeof(disp), HAL_MAX_DELAY);
}
2023-12-07 11:15 PM
That worked for me, with continuous mode disabled, but when I try to read two and continuous mode enabled and scan conversion mode enabled and with DMA to circular and full word setting I get only zeros.
the ranking for channels and regular conversions is enabled.
while(1)
{
uint32_t currentADCValue[2]={0};
HAL_ADC_DMA_Start(&hadc3,currentADCValue,2);
sprintf(disp,"D1: %ld D2: %ld\n\r",currentADCValue[0],currentADCValue[1]);
HAL_UART_Transmit(&huart8, (uint8_t*)disp, sizeof(disp), HAL_MAX_DELAY);
}
2023-12-08 6:25 AM
See a working example using HAL_ADC_DMA_Start here:
2023-12-08 6:55 AM
Hello @anonymous_stm
It should be HAL_ADC_Start_DMA instead of HAL_ADC_DMA_Start
To use correctly HAL_ADC_DMA_Start() function, you need to check its definition.
HAL_StatusTypeDef HAL_ADC_Start_DMA(ADC_HandleTypeDef *hadc, uint32_t *pData, uint32_t Length)
* @param pData Destination Buffer address.
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
We’re moving the ST Community to a new platform to give you a better and more reliable community experience.