








#include <stdio.h>

int ADCValue;
float Voltage;
int _write(int file, unsigned char* p, int len)
{
HAL_StatusTypeDef status = HAL_UART_Transmit(&huart3, p, len, 100);
return (status == HAL_OK ? len : 0);
}

int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_ADC1_Init();
MX_USART3_UART_Init();
MX_USB_OTG_FS_PCD_Init();
/* USER CODE BEGIN 2 */
__HAL_UART_ENABLE_IT(&huart3, UART_IT_RXNE);
__HAL_UART_ENABLE_IT(&huart3, UART_IT_TC);
printf("ADC Program\n\r");
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_ADC_Start(&hadc1);
if(HAL_ADC_PollForConversion(&hadc1, 1000000) == HAL_OK)
{
ADCValue = HAL_ADC_GetValue(&hadc1);
}
printf("ADC = %d\r\n", ADCValue);
Voltage = 3.3 * ((float)ADCValue / 4095.0);
printf("Voltage = %f\r\n", Voltage);
HAL_Delay(500);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}

void HAL_Delay(uint32_t Delay)
{
uint32_t tickstart = HAL_GetTick();
while((HAL_GetTick() - tickstart) < Delay)
{
}
}




