2022-08-30 06:47 AM
#include <stdint.h>
#include <stdio.h>
#include "stm32f302x8.h"
void delay1(void);
volatile uint32_t value;
int main(void)
{
RCC->AHBENR = 1U<<28;
RCC->AHBENR |= 1U<<17;
GPIOA->MODER |= (1U<<8); //ADC1_IN5
GPIOA->MODER |= (1U<<9);
ADC1_COMMON->CCR &=~ (1U<<16);
ADC1_COMMON->CCR &=~ (1U<<17);
ADC1_COMMON->CCR |= (1U<<17); //HCLK/2
ADC1->CFGR |= (1U<<13);
ADC1->SQR1 |= 0;
ADC1->SQR1 |= (5U<<6); //ADC1_IN5
ADC1->IER |=ADC_IER_EOCIE;
NVIC_EnableIRQ(ADC1_IRQn);
ADC1->CR &=~(1U<<29);
ADC1->CR |= (1U<<28);
ADC1->CR |= (1U<<0);
delay1();
ADC1->CR |= (1U<<2);
while(1)
{
}
}
void delay1(void)
{
for (int i=0;i<100000;i++)
{
}
}
void ADC1_IRQHandler(void)
{
if((ADC1->ISR & ADC_ISR_EOC))
{
ADC1->ISR |= ADC_ISR_EOC;
value = ADC1->DR;
}
}