Short version:
Need help with C programming to select channel/s for ADC in STM32F3(Dicovery board). Please find the code that I have written as of now at the end of the question. It would be great if anyone can refer to some resources for bare metal programming.
Long Version:
I am learning programming ARM controllers; what I have is a ST32F303 Discovery board and I believe the method I am trying is called bare metal programing. I have experience in writing plain C code for AVR microcontrollers but that was quite straight forward and almost all the registers were same throughout the series. But when it came to ARM I was totally surprised to see the number of things(files) that we have to get right for even compiling the code properly. By the way I am having a Linux system so I put together the gnu arm toolchain with Eclipse.
After some research and numerous Youtube videos I finalized on two materials
- STM32Snippets
- NewbieHack - This chaps Youtube series which is for
Of course I am referring the reference manual of the controller in hand too. But the problem is that both of the above resources are not straight forward ones for stm32F3, But I am using the same workflow for writing for F3. Right now I am stuck with ADC as I cant figure out how to select a channel for conversion and some advice and guidance would be helpful
Here is the code I have written so far
/*
* ADC in ARM
*
* Author : Easwaran
*
*/
#include "stm32f30x_conf.h"
int main (void)
{
//ADC calibration
ADC1->CR &= ~ADC_CR_ADEN; //Disables ADC; 0 in ADCEN to disable ADC.
// ADC1->CR
ADC1->CR |= ADC_CR_ADCAL; //put a 1 in calibration register | CR is the control register for ADC1
while ((ADC1->CR & ADC_CR_ADCAL) != 0)
{
//waiting till the calibration is over; ie the bit turns 0
}
//select a clock source
RCC->AHBENR |= RCC_AHBENR_ADC12EN; // enables both ADC1 & 2
RCC->CR |= RCC_CR_HSEON;
while((RCC->CR & RCC_CR_HSERDY) != 1)
{
//to make sure the clock has started
}
ADC1->CR = ADC12_CCR_CKMODE; // this is weird
// enable ADC
ADC1-> CR = ADC_CR_ADEN;
while((ADC1->ISR & ADC_ISR_ADRD) == 0)
{
//waiting to get ready
}
//sampling time
ADC1->SMPR1 |= ADC_SMPR1_SMP0_0 | ADC_SMPR1_SMP0_1 | ADC_SMPR1_SMP0_2;
//set the channel - here internal temp register
while(1)
{
//start conversion
}
}