
// STM32 ADC HAL
#include <stm32f10x_cl.h>

void InitADC (void) {

  RCC->APB2ENR |= (1<<4);                      /* enable clock for GPIOC      */
  GPIOC->CRL &= 0xFFF0FFFF;                    /* Configure ADC.14 input.     */

  RCC->APB2ENR |= (1<<9);                      /* enable clock for ADC1       */
  ADC1->SQR1  = 0x00000000;                    /* one conversion              */
  ADC1->SQR3  = (14<< 0);                      /* set order to chn14          */
  ADC1->SMPR1 = ( 5<<12);                      /* sample time (55,5 cycles)   */ 

  ADC1->CR1   =  0x00000100;                   /* independant mode, SCAN mode */
  ADC1->CR2   =  0x000E0003;                   /* data align right            */
                                               /* continuous conversion       */
                                               /* EXTSEL = SWSTART            */
                                               /* enable ADC                  */ 
  ADC1->CR2  |= 0x00000008;                    /* Reset calibration           */
  while (ADC1->CR2 & 0x00000008);

  ADC1->CR2  |= 0x00000004;                    /* Start calibration           */
  while (ADC1->CR2 & 0x00000004);

  ADC1->CR2  |=  0x00500000;        
}

int GetValADC (void) {
  return(ADC1->DR);	
}
