簡體   English   中英

stm32l476 ADC未准備好

[英]stm32l476 ADC not ready

我試圖在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);
    }
}

我解決了這個-終於。 如果有人進入同一個地方。 我已經將SYSCLK設置為ADC時鍾源,但這需要在RCC-> CCIPR [29:28]中進行設置。

這是小事...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM