stm32l476 ADC没准备好

问题描述 投票:1回答:1

我试图在STM32L476 Nucleo板上调出一个ADC。我想我配置好的东西,但我必须错过一步。我知道这可以使用HAL API和CubeMX完成,但我更喜欢在启动新板时进行寄存器级访问。这是我的代码 - 我认为它被评论到足以让它可以理解。我删除了剩下的代码以保持简单。

我不明白的问题是,当代码启动while循环时 - ADC未就绪 - 即ADC1-> ISR [0]未设置 - 并且未设置。我已经确认这些位设置在我认为他们应该使用keil的位置。

谁能发现缺少的东西?

#include <stm32l4xx.h>
#include <stdio.h>

#ifdef __cplusplus
extern "C"
#endif

int main(void)
{

    uint32_t adcResult = 0;

    /* Configure the clocks - using MSI as SYSCLK @16MHz */
    RCC->CR             &=  0xFFFFFF07;     //Clear ~MSIRANGE bits and MSIRGSEL bit
    RCC->CR             |=  0x00000089;     //Set MSI to 16MHz and MSIRGSEL bit
    char *dataPtr = NULL;

    //init ADC1
    ADC1->CR     &= 0xDFFFFFFF;      //Take ADC out of deep power down - i break at this point to allow enough time - doesn't help
    ADC1->CR     |= 0x10000000;    //Enable ADC1 votage regulator
    RCC->AHB2ENR |= 0x00002001;    //Enable the ADC clock, and GPIOA clk
    GPIOA->ASCR  |= 0x00000001;    //Connect analog switch to GPIOA[0]
    GPIOA->MODER |= 0x00000003;    //Set A0 for analog input mode
    ADC1->ISR    |= 0x00000001;    //Clear the ADRDY bit in the ADCx_ISR register by writing ‘1’.
    ADC1->SQR1   |= 0x00000040;    //Set for a sequence of 1 conversion on CH0


    while (1)
    {
            ADC1->CR |= 0x00000004;       //Convst
            while(!(ADC1->ISR & 0x4));
            adcResult = ADC1->DR;
            sprintf(dataPtr, "%d", adcResult);
    }
}
stm32 keil
1个回答
0
投票

我终于解决了这个问题。如果有人进入同一个地方。我已将SYSCLK设置为ADC时钟源,但这需要在RCC-> CCIPR [29:28]中设置。

这是小事......

© www.soinside.com 2019 - 2024. All rights reserved.