c++ - STM32 NVIC ADC 中断未触发

标签 c++ c interrupt stm32 cmsis

我有一个 STM32F411VET,我想在 ADC 转换完成后触发中断。文档说明如下:

In Single conversion mode the ADC does one conversion. This mode is started with the CONT bit at 0 by either:

  • setting the SWSTART bit in the ADC_CR2 register (for a regular channel only) Once the conversion of the selected channel is complete:

If a regular channel was converted:

  • The converted data are stored into the 16-bit ADC_DR register
  • The EOC (end of conversion) flag is set
  • An interrupt is generated if the EOCIE bit is set

Then the ADC stops.

因此,我有以下代码:

启用中断

SET_BIT(ADC1->CR1, ADC_CR1_EOCIE);      // enable interrupt generation
NVIC_EnableIRQ(ADC_IRQn);       // allow interrupt in NVIC
__enable_irq();     // change cpu flags to enable interrupts

配置 ADC

void ConfigureADC()
{
    // PA1 - ADC_IN1
    SET_BIT(GPIOA->MODER, GPIO_MODER_MODE1_0 | GPIO_MODER_MODE1_1); 
    SET_BIT(RCC->APB2ENR, RCC_APB2ENR_ADC1EN);      // enable ADC1 clock
    SET_BIT(ADC1->CR2, ADC_CR2_ADON);       // enable ADC1
    SET_BIT(ADC1->CR1, ADC_CR1_RES_1);      // 8-bit conversion
    SET_BIT(ADC->CCR, ADC_CCR_ADCPRE_0);    // prescaler - /4
    SET_BIT(ADC1->SQR3, 1);     // channel 1 (PA1)
    SET_BIT(ADC1->CR2, ADC_CR2_CONT);       // Continious mode
}

中断处理程序

void ADC_IRQHandler()
{
    vConverted = true;
    CLEAR_BIT(ADC1->SR, ADC_SR_EOC);        // Software clears EOC flag
}

在 Debug模式下或直接从 ADC1->DR 寄存器读取时,我得到了很好的结果。

让我担心的是我无法在 uVision5(我正在使用的 IDE)中调试中断处理程序。

问题是中断处理程序没有被执行,我不知道如何正确调试它。


感谢大家的帮助。

最佳答案

我应该注意,使用的是 C++,因此,编译后的函数名称与代码中的名称不匹配,因此它们不会被绑定(bind)/替换。 IRQ 处理程序未被引用,因此未包含在编译代码中。

要使函数“C”链接,应使用 extern "C"

extern "C"
{
    void ADC_IRQHandler();
    // Other handlers
}

要获得有关 extern "C" 的更多信息,请参阅 that answer .

关于c++ - STM32 NVIC ADC 中断未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43669113/

相关文章:

c++ - 将 COFF lib 文件转换为 OMF 格式

c - 下面的控制表达式是否在 for 循环中递增?

iOS AVAudioSession 中断通知未按预期工作

linux - 中断处理程序可以写入 FIFO

c++ - 检查 "1"或 "0"是否位于 "x"的 10 次幂序列 (1101001000...) C++

c++ - 在 C++ 中右对齐 getline() 输入

在 C 中复制数组并清除 char 数组中的垃圾

c - int 矩阵中的段错误

embedded - 为什么 INT0 的向量数是 1 而不是 datasheet 中的 2?

boost-bind - 在 std::find_if 中使用 boost bind 编译错误