Skip to main content
mattfox
Associate III
July 9, 2013
Question

STM32F3 Discovery - ADC EOC Interrupt

  • July 9, 2013
  • 2 replies
  • 686 views
Posted on July 09, 2013 at 16:58

I'm working on getting my ADC to be interrupt driven.  From my code below, I can verify that the interrupt is set in the IER (interrupt enable register)  for ADC1, and that the EOC bit is high.  For some reason, though, it will never enter the interrupt routine.  I have been using printf statements to debug it, but I haven't been getting any output from the interrupt routine.  Can anyone see what is wrong here?  Thanks for the help!

Also, I imagine some people will suggest I use DMA instead of EOC interrupt.  However, the end use of this code will be much better served by using the EOC interrupt, which is why I'm using this one instead of DMA which may be more logical initially.

#include ''main.h''

#include ''common.h''

#include ''usart.h''

#include ''peripherals.h''

#define A2D_ITERATIONS_DIV2 2

#define A2D_ITERATIONS 1<<A2D_ITERATIONS_DIV2 // Needs to be divisible by 2

uint16_t a2d_value = 0;

uint16_t interrupt = 0;

uint8_t a2d_index = 0;

uint8_t a2d_counter = 0;

__IO uint16_t  ADC1ConvertedValue = 0, ADC1ConvertedVoltage = 0;

int main(void)

{

  

  /* Initialize USART2 */

  USART2_Init(115200, TRUE);

  printf(''UART2 initialized\n\r'');

  /* Initialize ADC */

  ADC_Initialize();

  printf(''ADC initialized\n\r'');

  

  /* Start ADC1 Software Conversion */ 

  ADC_StartConversion(ADC1);   

  

  while(1){

 if(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == SET)

 {

 interrupt = ADC1->IER & ADC_FLAG_EOC;

 printf(''Interrupt? %d \n\r'', interrupt);

 }

  }

}

void ADC1_2_IRQHandler(void)

{

printf(''Here\n\r'');

if(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == SET)

{

a2d_value = ADC1->DR;

if( a2d_index == 0 ){

// motor[0].current_pot_acc += a2d_value;

printf(''PA1: %d\n\r'', a2d_value);

ADC_RegularChannelConfig(ADC1, ADC_Channel_2, 1, ADC_SampleTime_7Cycles5); // PA1

}

else if( a2d_index == 1 ){

// motor[1].current_pot_acc += a2d_value;

printf(''PC3: %d\n\r'', a2d_value);

ADC_RegularChannelConfig(ADC1, ADC_Channel_9, 1, ADC_SampleTime_7Cycles5); // PC3

}

else if( a2d_index == 2 ){

// motor[0].motor_current_acc += a2d_value;

printf(''PC0: %d\n\r'', a2d_value);

ADC_RegularChannelConfig(ADC1, ADC_Channel_6, 1, ADC_SampleTime_7Cycles5); // PC0

}

else if( a2d_index == 3 ){

// motor[1].motor_current_acc += a2d_value;

printf(''PC1: %d\n\r'', a2d_value);

ADC_RegularChannelConfig(ADC1, ADC_Channel_7, 1, ADC_SampleTime_7Cycles5); // PC1

}

else if( a2d_index == 4 ){

// motor[0].extra_analog_acc += a2d_value;

printf(''PC2: %d\n\r'', a2d_value);

ADC_RegularChannelConfig(ADC1, ADC_Channel_8, 1, ADC_SampleTime_7Cycles5); // PC2

}

else if( a2d_index == 5 ){

// motor[1].extra_analog_acc += a2d_value;

printf(''PF2: %d\n\r'', a2d_value);

ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_7Cycles5); // PF2

a2d_counter += 1;

}

a2d_index = (a2d_index + 1) % 6;

if( a2d_counter < A2D_ITERATIONS ){

// Start conversion

ADC_StartConversion(ADC1);

}

}

}
    This topic has been closed for replies.

    2 replies

    Tesla DeLorean
    Guru
    July 9, 2013
    Posted on July 09, 2013 at 17:25

    NVIC?

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    mattfox
    mattfoxAuthor
    Associate III
    July 9, 2013
    Posted on July 09, 2013 at 17:29

    *facepalm*

    Thanks for the help!