Skip to main content
Maciej Skrzypczak
Associate II
Nov 18, 2017 11:02 PM UTC
Question

Interrupt first steps problem

Posted on November 19, 2017 at 00:02

Hi, 

I'm using a stm32f767ZI microcontroller on NUCLEO eval board in Keil uVision environment. I have huge problems with my first steps beacause of interrupts handling. I have some questions about it and I didnt find my answer in examples. 

I expect the program to keep blinking an LED using Timer6 interrupt. This is where my problems begin.

My code:

#include 'stm32f7xx.h'              // Device header

#include 'basic_timer.h'            // External library (my own)

int diode;

int main ()

{

diode_init();

//***TIMER REGISTERS BELOW:

//***Advanced High Performance Bus enabled for TIM6

RCC -> APB1ENR |= RCC_APB1ENR_TIM6EN;

//***Timer6 counter value?

TIM6-> CNT |= 1;

//Timer6 prescaler 

TIM6 -> PSC |= 16000;

//Timer overflow value:

TIM6 -> ARR |= 16000;

//Interrupt Enable:

TIM6->DIER |= TIM_DIER_UIE;

//***TIMER REGISTERS END

//***Below is the part that allow the acces to NVIC 

// ***Clear previous interrupt

NVIC_ClearPendingIRQ(TIM6_DAC_IRQn);

//*** Set interrupt priority

NVIC_SetPriority(TIM6_DAC_IRQn, 1);

// ***Enable interrupt

NVIC_EnableIRQ(TIM6_DAC_IRQn);

//***End of NVIC

while(1)

{}}

//Now the interrupt handling: 

void TIM6_DAC_IRQHandler (void)

{

   static int licznik;

   licznik++;

if (licznik > 1000)

{

            licznik = 0;

            if (diode== 1)

                   diode = 0;

            else

                   diode = 1;

}

}

My questions are: 

*Is my interrupt handling correct 

*Do i need to access NVIC with my clear enable etc commands?

*(

//***Timer6 counter value  

TIM6-> CNT |= 1): is that added value every tick ? 

*Do i have to enable interrupts with '__enable_irq();' command?

    This topic has been closed for replies.

    1 reply

    S.Ma
    Principal
    Nov 19, 2017 2:39 AM UTC
    Posted on November 19, 2017 at 03:39

    Why not start from a nucleo timer board example from Cube?

    Besides coding standard, declare a global variable (volatile) for your counter outside the interrupt function.

    Did you enable/configure completely the timer? 

    Using the debugger will let you know if the timer registers looks good.

    Put a breakpoint in the ISR to check the program indeed goes there...