gpt4 book ai didi

c - ADC 中断未被调用

转载 作者:太空宇宙 更新时间:2023-11-04 04:17:40 26 4
gpt4 key购买 nike

我希望在每次转换结束后调用 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)

但还是不行。

我使用的微 Controller 是STM32F103RB。谢谢!

最佳答案

找到问题了。

ADC ISR 是,

void ADC1_2_IRQHandler(void)

此 ISR 为 ADC 1 和 ADC 2 调用。

关于c - ADC 中断未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50106221/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com