Can anyone help me figure out what I'm doing wrong? (trying to use ADC on STM32F3 discovery board)
I wrote this code to initialize ADC1. What Im trying to do is take input from a Joystick and map it accordingly and send a corresponding PWM output to a LED.
RCC->CFGR |= RCC_CFGR2_ADCPRE12_DIV2;
RCC->AHBENR |= RCC_AHBENR_ADC12EN; //enable clock
ADC1->CR &= ~(ADC_CR_ADVREGEN_1 | ADC_CR_ADVREGEN_0);
ADC1->CR |= ADC_CR_ADVREGEN_0; //voltage regulator enable sequence
ADC1->CR &= ~ADC_CR_ADCALDIF;
ADC1->CR |= ADC_CR_ADCAL; //start calibration
while((ADC1->CR)& ADC_CR_ADCAL); //wait till calibrated
ADC1->CR |= ADC_CR_ADEN;
while(!( (ADC1->ISR) & ADC_ISR_ADRDY ));
ADC1->SQR1 |= ADC_SQR1_SQ1_1 | ADC_SQR1_SQ1_0; //channel 3 in sequence 1
ADC1->SMPR1 |= ADC_SMPR1_SMP3_2 | ADC_SMPR1_SMP3_1; //sampling rate for ch3
ADC1->CFGR |= ADC_CFGR_CONT; //set to continuous conversion mode
ADC1->CR |= ADC_CR_ADSTART;The program is stuck in one of the while loops (I'm guessing due to some problem with ADC calibration? idk). I know this because the rest of my code never executes, if it did, I would be able to see an output on the LED. It would be a great help if someone can help me figure out what I'm doing wrong here.
