I want ADC Interrupt Service Routine to be called after each End of Conversion. However it is not being called.
Here's is my code:
#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);
}
Here's the disassembly after the interrupt occurs,
I tried changing
void ADC_IRQHandler(void)
to,
void ADC1_IRQHandler(void)
but it still didn't worked.
The Micro-controller I am using is STM32F103RB. Thanks!
Found the problem.
The ADC ISR was,
void ADC1_2_IRQHandler(void)
This ISR is called for both ADC 1 and ADC 2.
User contributions licensed under CC BY-SA 3.0