Main
Main
Main
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
* Copyright (c) 2024 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
TIM_HandleTypeDef htim3;
mydelay1--;
}
}
uint32_t Read_ADC2_MANUAL(uint32_t channel_number){
uint32_t result_ADC;
ADC2->SQR3=channel_number;
ADC2->CR2|=0x00000001;
ADC2->CR2 |=0x00400001;
while(ADC2->SR ){
if(ADC2->SR==0x12){
ADC2->CR2 &= 0xFFFFFFFE;
result_ADC=ADC2->DR;
ADC2->SR=0;
}
//while(staradc){;}
//ADC_Enable(&hadc1);
//ADC_Enable(&hadc1);
//HAL_ADC_Start_IT(&hadc1);
//HAL_ADC_PollForConversion(&hadc1, 10);
return result_ADC;
}
uint32_t Read_ADC_MANUAL(uint32_t channel_number){
uint32_t result_ADC;
ADC1->SQR3=channel_number;
ADC1->CR2|=0x00000001;
ADC1->CR2 |=0x00400001;
while(ADC1->SR ){
if(ADC1->SR==0x12){
ADC1->CR2 &= 0xFFFFFFFE;
result_ADC=ADC1->DR;
ADC1->SR=0;
}
}
//while(staradc){;}
//ADC_Enable(&hadc1);
//ADC_Enable(&hadc1);
//HAL_ADC_Start_IT(&hadc1);
//HAL_ADC_PollForConversion(&hadc1, 10);
return result_ADC;
}
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc1)
{
//adcval[0]= ADC1->DR;
// HAL_ADC_Stop_DMA(hadc1);
staradc=0;
}
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
//HAL_ADC_Start(&hadc1);
flag=1;
}
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
if(flag){flag=0;
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, 1);
adcval[0] = Read_ADC_MANUAL(0);
//mydelays(1);
adcval[1] = Read_ADC_MANUAL(1);
//mydelays(1);
adcval[2] = Read_ADC_MANUAL(2);
adcval[3] = Read_ADC2_MANUAL(3);
//mydelays(1);
adcval[4] = Read_ADC2_MANUAL(4);
//mydelays(1);
adcval[5] = Read_ADC2_MANUAL(5);
// mydelays(1);
//adcval[2] = Read_ADC_MANUAL(2);
HAL_GPIO_WritePin(LED2_GPIO_Port, LED2_Pin, 0);
}
/* USER CODE END WHILE */
}
/* USER CODE END 3 */
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
/**
* @brief ADC1 Initialization Function
* @param None
* @retval None
*/
static void MX_ADC1_Init(void)
{
/**
* @brief ADC2 Initialization Function
* @param None
* @retval None
*/
static void MX_ADC2_Init(void)
{
/**
* @brief TIM3 Initialization Function
* @param None
* @retval None
*/
static void MX_TIM3_Init(void)
{
/**
* @brief GPIO Initialization Function
* @param None
* @retval None
*/
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */