This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

ADC

Hello Guys, I am try to get the STM32F446RE to read analog signals from a potentiometer and I just cant seem to get it right please help me out, can I please get an example code that works cause even uploading the code I have written just isn't working right now.

Parents
  • Here is my attempt to initialize it 

    //set clock to 14MHz prscaler
    ADC->CCR |= ADC_CCR_ADCPRE_0;
    ADC->CCR |= ADC_CCR_ADCPRE_1;
    ADC->CCR |= ADC_CCR_TSVREFE;

    //RCC clock for ADC and for alternate function
    RCC->APB2ENR |= RCC_APB2ENR_ADC1EN;

    //Enable GPIO port
    CLOCK_INIT_PORTA();

    //configure input push pull
    //setting up the input
    //setting up the mode
    GPIOA->MODER |= (GPIO_MODER_MODE2_1);
    GPIOA->MODER |= (GPIO_MODER_MODE2_0);//11 input output

    //setting up the PUPDR
    //since we have pulled down push pull alternate function
    GPIOA->PUPDR &=~(GPIO_PUPDR_PUPD2_0);
    GPIOA->PUPDR &=~(GPIO_PUPDR_PUPD2_1);//analog value

    //Enable end of conversion interrupt
    ADC1->CR1 |= ADC_CR1_EOCIE;



    //ADC Resolution 8 bit
    ADC1->CR1 &=~ ADC_CR1_RES_0;
    ADC1->CR1 |= ADC_CR1_RES_1;

    //Set sampling rate choose maximum for the highst precision
    ADC1->SMPR2 |= ADC_SMPR2_SMP2_0;
    ADC1->SMPR2 |= ADC_SMPR2_SMP2_1;
    ADC1->SMPR2 |= ADC_SMPR2_SMP2_2;

    //set channels in sequence reg
    ADC1->SQR3 |= ADC_SQR3_SQ1_1;

    //Enable ADC that is ADON
    //Enable continuous mode
    ADC1->CR2 |= (ADC_CR2_ADON)|(ADC_CR2_CONT);

    //delai for 2ms
    wait_For_t(20);

    //turn on ADC adon for the second time
    //delay 2 ms
    ADC1->CR2 |= ADC_CR2_ADON;
    wait_For_t(20);

    //Run clibration
    //delay to allow the finish
    wait_For_t(2);

Reply
  • Here is my attempt to initialize it 

    //set clock to 14MHz prscaler
    ADC->CCR |= ADC_CCR_ADCPRE_0;
    ADC->CCR |= ADC_CCR_ADCPRE_1;
    ADC->CCR |= ADC_CCR_TSVREFE;

    //RCC clock for ADC and for alternate function
    RCC->APB2ENR |= RCC_APB2ENR_ADC1EN;

    //Enable GPIO port
    CLOCK_INIT_PORTA();

    //configure input push pull
    //setting up the input
    //setting up the mode
    GPIOA->MODER |= (GPIO_MODER_MODE2_1);
    GPIOA->MODER |= (GPIO_MODER_MODE2_0);//11 input output

    //setting up the PUPDR
    //since we have pulled down push pull alternate function
    GPIOA->PUPDR &=~(GPIO_PUPDR_PUPD2_0);
    GPIOA->PUPDR &=~(GPIO_PUPDR_PUPD2_1);//analog value

    //Enable end of conversion interrupt
    ADC1->CR1 |= ADC_CR1_EOCIE;



    //ADC Resolution 8 bit
    ADC1->CR1 &=~ ADC_CR1_RES_0;
    ADC1->CR1 |= ADC_CR1_RES_1;

    //Set sampling rate choose maximum for the highst precision
    ADC1->SMPR2 |= ADC_SMPR2_SMP2_0;
    ADC1->SMPR2 |= ADC_SMPR2_SMP2_1;
    ADC1->SMPR2 |= ADC_SMPR2_SMP2_2;

    //set channels in sequence reg
    ADC1->SQR3 |= ADC_SQR3_SQ1_1;

    //Enable ADC that is ADON
    //Enable continuous mode
    ADC1->CR2 |= (ADC_CR2_ADON)|(ADC_CR2_CONT);

    //delai for 2ms
    wait_For_t(20);

    //turn on ADC adon for the second time
    //delay 2 ms
    ADC1->CR2 |= ADC_CR2_ADON;
    wait_For_t(20);

    //Run clibration
    //delay to allow the finish
    wait_For_t(2);

Children