ADC中断没有被调用

时间:2018-04-30 18:31:12

标签: c keil adc isr

我希望在每次转换结束后调用ADC中断服务程序。但它没有被召唤。

这是我的代码:

#define RCC_APB2ENR   (*((volatile unsigned long*) 0x40021018))

#define ADC1_CR1      (*((volatile unsigned long*) 0x40012404))
#define ADC1_CR2      (*((volatile unsigned long*) 0x40012408))
#define ADC1_SMPTR2   (*((volatile unsigned long*) 0x40012410))
#define ADC1_SQR1     (*((volatile unsigned long*) 0x4001242C))
#define ADC1_SQR3     (*((volatile unsigned long*) 0x40012434))
#define ADC1_DR       (*((volatile unsigned long*) 0x4001244C))

#define NVIC_SETENA_0 (*((volatile unsigned long*) 0xE000E100))
#define NVIC_CLRENA_0 (*((volatile unsigned long*) 0xE000E180))


volatile short conversionResult = -1;

void ADC_IRQHandler(void)       // ADC Interrupt service routines
{   

    if((ADC1_CR2 & 0x00000002) == 0x00000002)       // check if EOC bit set
        conversionResult = ADC1_DR;     
    else
        conversionResult = -1;          
}


void ADC_Init(short mode)
{
    // enable ADC Interrupts
    NVIC_SETENA_0 |= 0x00040000;

    // enable clock for ADC_1
    RCC_APB2ENR |= 0x0000200;

    ADC1_CR2 &= 0x00000000;             // resetting controll registers
    ADC1_CR1 &= 0x00000000;

    ADC1_CR1 |= 0x00000020;             // EOC interrupt enable

    if(mode == 1)                       // continous mode
        ADC1_CR2 |= 0x00000002;


    ADC1_CR2 |= 0x00000001;         // Waking up from power Down State

    // Perfroming Calibration

    ADC1_CR2 |= 0x00000004;
    while((ADC1_CR2 & 0x00000004) != 0);
}


void ADC_ChannelConfig(short channelNumber, short sampleTime)
{
    //selecting channel
    ADC1_SQR3 |= channelNumber; 

    //setting sample time for this channel
    int temp = sampleTime;
    temp = (temp << channelNumber * 3);

    ADC1_SMPTR2 |= temp;
}

void ADC_StartConversion()
{
    ADC1_CR2 |= 0x00000001;         // enable adc again to start conversion
}

int main(void)
{
    ADC_Init(0);
    ADC_ChannelConfig(2, 3);

    ADC_StartConversion();

    while(1)
    {
    }

    return (1);
}

这是中断发生后的反汇编, enter image description here

我尝试过更改

  

void ADC_IRQHandler(void)

要,

  

void ADC1_IRQHandler(void)

但它仍然没有奏效。

我使用的微控制器是STM32F103RB。谢谢!

1 个答案:

答案 0 :(得分:0)

发现问题。

ADC ISR是,

  

void ADC1_2_IRQHandler(void)

为ADC 1和ADC 2调用此ISR。