cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f0 interrupt

d4ng3r09
Associate II
Posted on March 24, 2014 at 18:59

Hi,

i want to start an interrupt to leave the sleep mode after a precise that my ADC reads.

Could some body help me and put what i shall do in a nut shell?

thank you for your attention 

PS: i am using an stm32f0 discovery board 
4 REPLIES 4
Posted on March 24, 2014 at 22:56

What does you code for the ADC look like now?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
d4ng3r09
Associate II
Posted on March 24, 2014 at 23:44


this is my initialisation for the ADC to get the value from the sensor.
what i want to do is to start an interrupt if this value is above,let's say, X .
void
AdcConfiguration(){
ADC_InitStruct.ADC_Resolution = ADC_Resolution_12b;
/* Initialize the ADC_ContinuousConvMode member */
ADC_InitStruct.ADC_ContinuousConvMode = ENABLE;
/* Initialize the ADC_ExternalTrigConvEdge member */
ADC_InitStruct.ADC_ExternalTrigConvEdge =ADC_ExternalTrigConvEdge_None;
/* Initialize the ADC_ExternalTrigConv member */
ADC_InitStruct.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_TRGO;
/* Initialize the ADC_DataAlign member */
ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right;
/* Initialize the ADC_ScanDirection member */
ADC_InitStruct.ADC_ScanDirection = ADC_ScanDirection_Upward ;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_1;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
GPIO_Init(GPIOA, &GPIO_InitStructure);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
ADC_Init(ADC1,&ADC_InitStruct);
ADC_ChannelConfig( ADC1,ADC_Channel_1,ADC_SampleTime_239_5Cycles);
ADC_Cmd(ADC1, ENABLE);
ADC_StartOfConversion(ADC1);
}
void main(void)
{AdcConfiguration();
while(1)
 {

 ADC_StartOfConversion(ADC1);
 value=ADC_GetConversionValue(ADC1);
}

 }
}

Posted on March 25, 2014 at 00:03

Is there a comparator mode that might do that?

/* ADC1 IRQ STM32F0-Discovery sourcer32@gmail.com */
#include ''stm32f0xx.h''
/**************************************************************************************/
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable ADC Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = ADC1_COMP_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/**************************************************************************************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; // PA.1 ADC IN1
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
/**************************************************************************************/
void ADC1_Configuration(void)
{
ADC_InitTypeDef ADC_InitStructure;
/* ADC1 DeInit */
ADC_DeInit(ADC1);
/* ADC1 Periph clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
/* Initialize ADC structure */
ADC_StructInit(&ADC_InitStructure);
/* Configure the ADC1 in continous mode withe a resolutuion equal to 12 bits */
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_ScanDirection = ADC_ScanDirection_Upward;
ADC_Init(ADC1, &ADC_InitStructure);
/* Convert the ADC1 input with 5 Cycles as sampling time */
ADC_ChannelConfig(ADC1, 1, ADC_SampleTime_55_5Cycles); // PA.1 - IN1
/* ADC Calibration */
ADC_GetCalibrationFactor(ADC1);
/* Enable ADC1 */
ADC_Cmd(ADC1, ENABLE);
/* Wait the ADCEN flag */
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_ADEN));
/* ADC1 regular Software Start Conv */
ADC_StartOfConversion(ADC1);
/* Enable the EOC interrupt for ADC1 */
ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);
}
/**************************************************************************************/
void ADC1_COMP_IRQHandler(void)
{
if (ADC_GetITStatus(ADC1, ADC_IT_EOC) != RESET)
{
uint16_t ADC1ConvertedValue;
/* Get ADC1 converted data */
ADC1ConvertedValue = ADC_GetConversionValue(ADC1);
if (ADC1ConvertedValue > 2000)
{
GPIOC->BSRR = GPIO_Pin_8;
GPIOC->BRR = GPIO_Pin_9;
}
else
{
GPIOC->BRR = GPIO_Pin_8;
GPIOC->BSRR = GPIO_Pin_9;
}
}
}
/**************************************************************************************/
int main(void)
{
NVIC_Configuration();
GPIO_Configuration();
ADC1_Configuration();
while(1);
}
/**************************************************************************************/
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf(''Wrong parameters value: file %s on line %d

'', file, line) */
/* Infinite loop */
while (1)
{}
}
#endif
/**************************************************************************************/

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
d4ng3r09
Associate II
Posted on March 25, 2014 at 12:44

I think i get it . I have then to enable the interrupt manually when the condition occures.I just thought that we have no control on the flags .After reading some of the documentation about the comparators , i believe that i can use  comparator 1 to compare the values on ADC1 and then start the interrupt.But i don t see the purpose of its use in this case because in can still make a simple compairaison like you did.

Anyway thank you for your help !