1.1K
#include "main.h" /* Private variables ---------------------------------------------------------*/ ADC_HandleTypeDef hadc1; UART_HandleTypeDef huart1; /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_ADC1_Init(void); static void MX_USART1_UART_Init(void); /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ uint32_t ADC_VAL = 0; uint8_t MSG[20]; uint8_t MSG2[50]="ERREUR YOUR ADC VAL IS > 4000 \n\r"; uint8_t MSG3[50]="ERREUR YOUR ADC VAL IS < 500 \n\r"; void HAL_ADC_LevelOutOfWindowCallback(ADC_HandleTypeDef * hadc) { ADC_VAL = HAL_ADC_GetValue(&hadc1); if(ADC_VAL>3990)) { HAL_UART_Transmit_IT(&huart1, MSG2, sizeof(MSG2)); } else HAL_UART_Transmit_IT(&huart1, MSG3, sizeof(MSG3)); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, 0); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, 1); } /* USER CODE END 0 */ int main(void) { HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); MX_ADC1_Init(); MX_USART1_UART_Init(); if(HAL_ADC_Start(&hadc1)!=HAL_OK) { Error_Handler(); } while (1) { while(HAL_ADC_PollForConversion(&hadc1, 2)!=HAL_OK) { Error_Handler(); } ADC_VAL = HAL_ADC_GetValue(&hadc1); sprintf(MSG,"ADC VAL = %u\n\r",ADC_VAL); HAL_UART_Transmit_IT(&huart1, MSG, sizeof(MSG)); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, 0); HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_0); HAL_Delay(1000); } }