2013-07-09 07:58 AM
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 2uint16_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); } }}2013-07-09 08:25 AM
NVIC?
2013-07-09 08:29 AM
*facepalm*
Thanks for the help!