ADC 中断未被调用
ADC interrupt not getting called
我希望在每次转换结束后调用 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);
}
这是中断发生后的反汇编,
我试过改变
void ADC_IRQHandler(void)
到,
void ADC1_IRQHandler(void)
但是还是不行。
我用的微控制器是STM32F103RB。谢谢!
找到问题了。
ADC ISR 是,
void ADC1_2_IRQHandler(void)
此 ISR 为 ADC 1 和 ADC 2 调用。
我希望在每次转换结束后调用 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);
}
这是中断发生后的反汇编,
我试过改变
void ADC_IRQHandler(void)
到,
void ADC1_IRQHandler(void)
但是还是不行。
我用的微控制器是STM32F103RB。谢谢!
找到问题了。
ADC ISR 是,
void ADC1_2_IRQHandler(void)
此 ISR 为 ADC 1 和 ADC 2 调用。