cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to get ADC INTERRUPT

pavan2
Associate II
Posted on January 29, 2009 at 03:20

Unable to get ADC INTERRUPT

16 REPLIES 16
pavan2
Associate II
Posted on May 17, 2011 at 13:00

i am trying to get ADC reading in interrupt.i have kept adc in continuous conversion mode, with EOC interrupt enabled.

i assumed that i should get interrupt after each EOC from where i can then collect the ADC reading.

but i have been unable to get any interrupt from ADC.

i checked the ADC by polling, where i get correct the reading.

i am using RIDE 7 with GCC. and ST library functions.

NVIC CONFIGURATION

NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQChannel;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;//0;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);

ADC CONFIGURATION

GPIO_InitTypeDef GPIO_InitStructure;

ADC_InitTypeDef ADC_InitStructure;

RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;

GPIO_Init(GPIOC, &GPIO_InitStructure);

ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;

ADC_InitStructure.ADC_ScanConvMode = DISABLE;

ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;

ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;

ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

ADC_InitStructure.ADC_NbrOfChannel = 1;

ADC_Init(ADC1, &ADC_InitStructure);

ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1,ADC_SampleTime_239Cycles5);

ADC_Cmd(ADC1, ENABLE);

ADC_ResetCalibration(ADC1);

while(ADC_GetResetCalibrationStatus(ADC1)!= RESET);

ADC_StartCalibration(ADC1);

while(ADC_GetCalibrationStatus(ADC1) != RESET);

interrupt handler

void ADC1_2_IRQHandler(void)

{

if(ADC_GetITStatus(ADC1, ADC_IT_EOC) != RESET)

{

ADC_TEMP1 = ADC_GetConversionValue(ADC1)&0x0FFF;

}

}

i trigger ADC using

ADC_SoftwareStartConvCmd(ADC1, ENABLE);

after this i assume i should get interrupt on each conversion.

i guess i am missing something.

but dont know what.

thanks in advance.

pavan k

[ This message was edited by: pavan.karmakar on 28-01-2009 06:38 ]

jgalea
Associate II
Posted on May 17, 2011 at 13:00

Hello, I have a similar problem. Im trying to convert the ADCs with DMA but Im having no DMA interrupt. Not sure if the ADC is working. I also posted in the forum:

http://www.st.com/mcu/forums-cat-7896-23.html

. I also sent a technical question to ST as I still did not have a reply from the forum. If a get a technical answer from ST, I will send it to you. Thanks Johann

jgalea
Associate II
Posted on May 17, 2011 at 13:00

Hello. I still have no answer from St technical support. In the meantime Im working to fix the line. I will notify you. thanks. To tell you the truth, I ran out of ideas, as followed examples. Im feeling in the corner 🙂

pavan2
Associate II
Posted on May 17, 2011 at 13:00

i am right now trying to get the ADC working using DMA, i will update on successful implementation.

thank you

pavan k

jgalea
Associate II
Posted on May 17, 2011 at 13:00

Hello, I have a similar problem. Im trying to convert the ADCs with DMA but Im having no DMA interrupt. Not sure if the ADC is working. I also posted in the forum:

http://www.st.com/mcu/forums-cat-7896-23.html

. I also sent a technical question to ST as I still did not have a reply from the forum. If a get a technical answer from ST, I will send it to you. Thanks Johann

sofiene
Associate III
Posted on May 17, 2011 at 13:01

Hi jgalea;

I have the following code that works correctly (ADC-DMA):

int main(void)

{

#ifdef DEBUG

debug();

#endif

/* System clocks configuration ---------------------------------------------*/

RCC_Configuration();

/* NVIC configuration ------------------------------------------------------*/

NVIC_Configuration();

/* GPIO configuration ------------------------------------------------------*/

GPIO_Configuration();

/* DMA1 channel1 configuration ----------------------------------------------*/

DMA_DeInit(DMA1_Channel1);

DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)ADC1_DR_Address;

DMA_InitStructure.DMA_MemoryBaseAddr = (u32)ADCConvertedValue;

DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;

DMA_InitStructure.DMA_BufferSize = NumberOfSample;

DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;

DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;

DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;

DMA_InitStructure.DMA_Priority = DMA_Priority_High;

DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;

DMA_Init(DMA1_Channel1, &DMA_InitStructure);

/* Enable DMA1 channel1 */

DMA_Cmd(DMA1_Channel1, ENABLE);

/* Enable DMA Transfer complete interrupt */

DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE);

/* ADC1 configuration ------------------------------------------------------*/

ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;

ADC_InitStructure.ADC_ScanConvMode = ENABLE;

ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;

ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;

ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

ADC_InitStructure.ADC_NbrOfChannel = 1;

ADC_Init(ADC1, &ADC_InitStructure);

/* ADC1 regular channel14 configuration */

ADC_RegularChannelConfig(ADC1, ADC_Channel_13, 1, ADC_SampleTime_1Cycles5);

/* Enable ADC1 DMA */

ADC_DMACmd(ADC1, ENABLE);

/* Enable ADC1 */

ADC_Cmd(ADC1, ENABLE);

/* Enable ADC1 reset calibaration register */

ADC_ResetCalibration(ADC1);

/* Check the end of ADC1 reset calibration register */

while(ADC_GetResetCalibrationStatus(ADC1));

/* Start ADC1 calibaration */

ADC_StartCalibration(ADC1);

/* Check the end of ADC1 calibration */

while(ADC_GetCalibrationStatus(ADC1));

/* Start ADC1 Software Conversion */

ADC_SoftwareStartConvCmd(ADC1, ENABLE);

while (1)

{

if (PrintFlag == 1)

{

printf(''%d\n'',ADC_Average);

PrintFlag = 0;

}

}

//////////////// DMA IRQ routine //////////////////////

void DMA1_Channel1_IRQHandler(void)

{

for (n=0; n

{

ADC_Sum = ADC_Sum + ADCConvertedValue[n];

}

ADC_Average = ADC_Sum/NumberOfSample;

ADC_Sum=0;

PrintFlag = 1;

DMA_ClearFlag(DMA1_FLAG_TC1);

}

}

//////////////// NVIC config //////////////////////

void NVIC_Configuration(void)

{

NVIC_InitTypeDef NVIC_InitStructure;

#ifdef VECT_TAB_RAM

/* Set the Vector Table base location at 0x20000000 */

NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);

#else /* VECT_TAB_FLASH */

/* Set the Vector Table base location at 0x08000000 */

NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);

#endif

/* Setting the priority grouping bits length */

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

/* Enable the DMA global Interrupt */

NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQChannel;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

}

jgalea
Associate II
Posted on May 17, 2011 at 13:01

Hello. Im going to try it now and notify you many thanks Johann

jgalea
Associate II
Posted on May 17, 2011 at 13:01

Hello. Thanks for the code. Unluckily the DMA did not occur in mine. Please, was the ADC1_DR_Address set as ((u32)0x40012444C)?. Please how was ADCConvertedValue decalred? Thanks Johann

sofiene
Associate III
Posted on May 17, 2011 at 13:01

First I'm M3allem and not Johann :);

Sorry I missed some declaration in my code:

#define ADC1_DR_Address ((u32)0x4001244C)

#define NumberOfSample 50

u16 ADCConvertedValue[NumberOfSample];

B.R.

M3allem