#include "MyADC.h" #include "MyTimer.h" #include "Driver_GPIO.h" #define NULL 0 //#define nombreChannel 1 void initADC(int channel){ // activer la clock de l'ADC 1 RCC->APB2ENR |= RCC_APB2ENR_ADC1EN; RCC->CFGR |= 0x8000; ADC1->CR2 |= ADC_CR2_ADON; // Choix du channel ADC1->SQR3 |= channel << 0;// on est sur le premier car on a qu'un seul channel } void startADC(void) { ADC1->CR2 |= ADC_CR2_ADON; } int read(void) { int value ; startADC(); // Recuperer le bit de End of conversion while (!(ADC1->SR & (0x01 << 1))); //on veut masquer les 12 bits les plus bas donc on prend le not de 0x0f >> 12 (111000000000) value = ADC1->DR & (~(0x0f << 12)); return value; }