Skip to main content
pierrehenri
Associate
May 19, 2014
Question

STM32F4 (F4 discovery board) interrupt Issue

  • May 19, 2014
  • 3 replies
  • 812 views
Posted on May 19, 2014 at 15:14

Hi everybody, 

I have an unstable behavior on an ADC interrupt.

My user code is very simple, I initialize my different peripherals (timer, ADC, GPIO) then I just a have an infinite  loop.

My Callback for my ADC interrupt just get the ADC value. The ADC is configured to start conversion on a trigger from timer 2.

I observe that the number of code lines in my program give two different result:

- All is fine: I have a periodic IT on my ADC

- Error: the Interrupt happens just one time and then never.

The code lines I add to get the different behaviors are independent from the program, it can be variable initialization, variable indentation, ..

As IDE i use IAR ewarm 6.30.

Any ideas whats wrong? I got no errors on the compiler, or debugger.

Thanks for your help,
    This topic has been closed for replies.

    3 replies

    raptorhal2
    Lead
    May 20, 2014
    Posted on May 20, 2014 at 02:58

    We have had a lot of rain lately, so the cool morning fog seems to have clouded my crystal ball. Do you mind showing us the code for the error condition ?

    Cheers, Hal

    pierrehenri
    Associate
    May 20, 2014
    Posted on May 20, 2014 at 09:37

    Hey Hal,

    My code was generated with STM32Cube (I have attached the project file).

    In the options of the project, I delete optimizations of the code.

    Here is the function main with my user code:

    int main(void)

    {

    /* USER CODE BEGIN 1 */

    uint8_t i = 0;

    /* USER CODE END 1 */

    /* MCU Configuration----------------------------------------------------------*/

    /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

    HAL_Init();

    /* Configure the system clock */

    SystemClock_Config();

    /* Initialize all configured peripherals */

    MX_GPIO_Init();

    MX_ADC1_Init();

    MX_I2S2_Init();

    MX_TIM1_Init();

    MX_TIM2_Init();

    MX_USART3_UART_Init();

    /* USER CODE BEGIN 2 */

    HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12, GPIO_PIN_SET);

    HAL_GPIO_WritePin(GPIOD, GPIO_PIN_14, GPIO_PIN_SET);

    HAL_ADC_Start_IT(&hadc1);

    HAL_TIM_OC_Start(&htim2, TIM_CHANNEL_1);

    /* USER CODE END 2 */

    /* USER CODE BEGIN 3 */

    /* Infinite loop */

    while (1)

    {

    }

    /* USER CODE END 3 */

    }

    Here is the callback of my ADC interrupt:

    /* USER CODE BEGIN 0 */

    #define NB_MEAN_SAMPLE_PHOTODIODE 10000.0

    uint8_t sEndRecord = 0;

    float sMeanPhotodiodePower = 0;

    uint8_t sDetectObject = 0;

    uint16_t sNbSamplePhotodiode = 0;

    float wADCValue = 0.0;

    void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)

    {

    if(sNbSamplePhotodiode < NB_MEAN_SAMPLE_PHOTODIODE)

    {

    sMeanPhotodiodePower = HAL_ADC_GetValue(hadc)/NB_MEAN_SAMPLE_PHOTODIODE + sMeanPhotodiodePower;

    sNbSamplePhotodiode ++;

    }

    else

    {

    if ((wADCValue=(float)HAL_ADC_GetValue(hadc))<(sMeanPhotodiodePower-30))

    {

    sDetectObject ++;

    }

    else

    {

    sDetectObject = 0;

    }

    }

    }

    With this simple project, we can just enter once in the ADC interrupt.

    But If, for example, I comment

    if ((wADCValue=(float)HAL_ADC_GetValue(hadc))<(sMeanPhotodiodePower-30))

    {

    sDetectObject ++;

    }

    else

    {

    sDetectObject = 0;

    }

    My ADC interrupt is periodically called.

    This workstooby commenting the configuration of an I/O

    For example this I/O:

    GPIO_InitStruct.Pin = GPIO_PIN_12;

    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;

    GPIO_InitStruct.Pull = GPIO_NOPULL;

    GPIO_InitStruct.Speed = GPIO_SPEED_MEDIUM;

    HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

    Thanks for your interest,

    ________________

    Attachments :

    MainProject.ioc : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0nZ&d=%2Fa%2F0X0000000bdm%2FfqwxhhCK5QAmQ.qMgTT00tFwVEoGEBsiuF6BLqPr7jQ&asPdf=false
    waclawek.jan
    Super User
    May 21, 2014
    Posted on May 21, 2014 at 09:08

    This does not really explain how is the ADC triggered.

    If you suspect this is a flaw in the Cube library, you should post in the dedicated sub-forum https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Java/AllItems.aspx

    JW