Initialization of ADC Pin in stm32f769i_discovery.c file
//Initialization of ADC Pin in stm32f769i_discovery.c file
void BSP_Analog_Init()
{
ADC_ChannelConfTypeDef sConfig = {0};
ADC_HandleTypeDef hadc1;
/* 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 = ADC_SCAN_DISABLE;
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_RIGHT;
hadc1.Init.NbrOfConversion = 1;
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_6;
sConfig.Rank = ADC_REGULAR_RANK_1;
sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN ADC1_Init 2 */
/* USER CODE END ADC1_Init 2 */
}
Function to read ADC Pin defined in stm32f769i_discovery.c file
//Function to read ADC Pin defined in stm32f769i_discovery.c file
uint32_t BSP_AdcValue()
{
//ADC_HandleTypeDef hadc1;
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1,0);
uint32_t Analog_data = HAL_ADC_GetValue(&hadc1);
float voltage = (3.3f * Analog_data/4096.0f);
HAL_Delay(100);
return Analog_data;
}
Calling BSP_AdcValue(); function in DeviceDriver.c file to get and update the value to the GUI
//Calling BSP_AdcValue(); function in DeviceDriver.c file to get and update the value to the GUI
static void AdcWorkerThread( const void* arg )
{
uint32_t simulatedAdcValue = 0;
while ( DeviceInitialized )
{
/* in order to simplify the example, the ADC value is just simulated - it
could be read from a real ADC by using corresponding BSP functions... */
//simulatedAdcValue = ( simulatedAdcValue + 1 ) % 2000;
simulatedAdcValue = BSP_AdcValue();
//EwPrint( "Set Temp: %0.2f\n", aValue );
EwPrint("%d", simulatedAdcValue);
/*
Important note: This function is a separate thread/task and not executed
in the context of the main GUI thread/task. NEVER make a direct function
call to a method of the driver class or any other generated code
from an interrupt handler or any other thread/task.
EwInvoke() or EwInvokeCopy() have to be used to schedule the invocation of
the desired method in the context of the GUI thread/task.
*/
EwInvoke( UpdateAdcValueProc, &simulatedAdcValue);
/* sleep for a certain period... */
EwBspOsDelay( 1000 );
}
/* terminate the worker thread */
WorkerThread = 0;
EwBspOsThreadDestroy( EwBspOsThreadGetHandle());
}
To the pin what i have initialized as ADC Pin i.e ADC1_IN6, I am giving 3.3volt to that pin.
I am using STM32F769NI DISCOVERY Board.