[SOLVED]Interruptions in the timer do not work

Wed Nov 22, 2017 9:38 am
Hello friends can someone tell me some example of use of the timers with the arduino ide in the core board.
The library of Timer1..Timer3 seems not to work in this board.

I have searched but I do not see any clear example.

Greetings and thank you

Wed Nov 22, 2017 10:45 am
Here is the original leaflabs reference documentation: http://docs.leaflabs.com/static.leaflab … -mini.html
On the right side you have the modules (including Timers).

Wed Nov 22, 2017 11:01 am
Thanks for your answer.

In that web the reference of those libraries I do not have them.

my board is an STMF303 – F303K8 And do not use these libraries

Wed Nov 22, 2017 1:27 pm
I’ve open a discussion around timer management here:
https://github.com/stm32duino/Arduino_C … issues/146

Wed Nov 22, 2017 4:07 pm
I used the <FlexiTimer2.h> and it gives me an error when compiling.

Does not support this micro.

The other two do not compile either.

Thu Nov 23, 2017 6:15 pm
Someone knows why libraries do not work
Timer1 … 2 …

I have tried this example and it does not work either.


TIM6->SR = 0
while (!(TIM6->SR & TIM_SR_UIF)); /* Loop until the update event flag is set */
/* The required time delay has been elapsed */
/* User code can be executed */

Compile without errors but it does not work

Thu Nov 23, 2017 8:22 pm
Maybe clk for this timer is not enable.

https://github.com/stm32duino/Arduino_C … rcc.h#L797

Fri Nov 24, 2017 7:55 am
Hello that example, I have taken it from the sheet of ST AN4776

To use it I include in the project #include <Timer.h>.

I will try your option to see if it works.

Fri Nov 24, 2017 1:11 pm
It’s still not working .. I’m going crazy with the timer :oops: :oops: :oops:

Fri Nov 24, 2017 1:18 pm
if I put this:

TIM6-> SR = 0;
TIM6-> ARR = 250;
TIM6-> CR1 | = TIM_CR1_CEN;
while (! (TIM6-> SR & TIM_SR_UIF));

point A

Never go to point A

RCC->APB1ENR |= RCC_APB1ENR_TIM6EN; <———–new line
TIM6->SR = 0;
TIM6->ARR = 250;
while (!(TIM6->SR & TIM_SR_UIF));

point A

And with the new line, that tells you that the oscillator is internal,
goes to point A immediately without doing any kind of timing

Fri Nov 24, 2017 1:24 pm
i have a set of timer routines for the f3, but that’s built on top of spl.

take a look at the datasheet and it is not that difficult to work out a set of routines of your own, with direct register access.

if i get some time, i may write one myself.

Fri Nov 24, 2017 3:30 pm
I would appreciate it, I just need an example and I continue.
The strange thing is that not even the code of st works.

Fri Nov 24, 2017 10:13 pm
I actually ended up just using my F1 code.

tim3_init(100); //set prescaler to 100
tim3_setpr1(50000ul); //oc1 period to be 50000 ticks
tim3_act1(led12_flp); //install user handler
ei(); //enable global interrupts

Fri Nov 24, 2017 10:27 pm
BTW, this approach (of using output compare channels for timing) allows you to create 4 timing events per TIM2/3/4 (each has 4 output compare channels) with differing periods.

it can be expanded to other chips as well. for more, see here: https://dannyelectronics.wordpress.com/ … ollection/

the basic code should run on other STM32 chips, with minimum re-configuration: mostly to change clock sourcing.

Mon Nov 27, 2017 8:43 am
Hello friend, thank thank you very much for your code.

I have managed to prove it but interruptions do not trigger

Tue Nov 28, 2017 9:51 am
At the end I solved it by putting a function
in the SysTick_Handler, a fudge since there are a lot of timers
without using.

In the timer interrupts do not work.
I have tried with the timer 6, 7, 1,3 and it does not work.

For example the basic timer 6 counts correctly but
even if you set the active interrupt, it never triggers it.

Also if in any timer active this:

Tue Nov 28, 2017 4:54 pm
The way you isr is written it is hard for it not to hang.

1. Read the datasheet and see what you have to do there.

2. Flip a pin in the isr to help you understand what’s going on.

Tue Nov 28, 2017 6:32 pm
Well I do not know, even though I look at the data sheet RM0316 Reference manual
and the modes of configuration:
AN4013 Application note STM32 cross-series timer overview
AN4776 Application note General-purpose timer cookbook

I do not see the fault.


Tue Nov 28, 2017 7:06 pm
This does not trigger the event either:

void tim6_init()
RCC->APB1ENR |= RCC_APB1ENR_TIM6EN; // Enable TIM6 clock
TIM6->PSC = 41999; // Set prescaler to 41999
TIM6->ARR = 5999; // Set auto-reload to 5999
TIM6->CR1 |= TIM_CR1_OPM; // One pulse mode
TIM6->EGR |= TIM_EGR_UG; // Force update
TIM6->SR &= ~TIM_SR_UIF; // Clear the update flag
TIM6->DIER |= TIM_DIER_UIE; // Enable interrupt on update event
NVIC_EnableIRQ(TIM6_DAC_IRQn); // Enable TIM6 IRQ
TIM6->CR1 |= TIM_CR1_CEN; // Enable TIM6 counter

void TIM6_DAC_IRQHandler()
if (TIM6->SR & TIM_SR_UIF != 0) // If update flag is set
TIM6->SR &= ~TIM_SR_UIF; // Interrupt has been handled


Tue Nov 28, 2017 11:52 pm
you are close. so keep working on it.

the following:

IO_OUT(LED_PORT, LED12); //led as output
tim6_init(100); tim6_setpr(10000); tim6_act(led12_flp);
tim7_init(100); tim7_setpr(10000*1.01); tim7_act(led12_flp);
ei(); //enable global interrupts

Wed Nov 29, 2017 8:26 am
Which core you used?

Note that, if the IRQHandler is defined in a cpp file or the ino file, you have to declare the TIM6_DAC_IRQHandler as extern “C”

extern "C" void TIM6_DAC_IRQHandler()

Wed Nov 29, 2017 10:58 am
The code is compiled well and the counter counts according to plan.

Both in your example and in the previous one published by me.

The problem is that when you reach the end of the account, the micro is blocked and never enters the
interruption, it’s as if I was going to look for that interruption and I will not find it, and of course it hangs up.

This happens with the two examples with yours and mine

Any suggestions?

Wed Nov 29, 2017 11:18 am

Core: nucleo STMF303 – F303K8

and that line where I put it, because I tested the start of the program:

extern “C” void TIM6_DAC_IRQHandler();

and I get an error.

core.a(timer.c.o)*: In function TIM6_DAC1_IRQHandler
timer.c*: (.text.TIM6_DAC1_IRQHandler+0x0): multiple definition of TIM6_DAC1_IRQHandler

Wed Nov 29, 2017 11:55 am
never enters the

you haven’t (and couldn’t) establish that. if you try to establish that, you will find the problem with your code.

Any suggestions?

the same as I gave you earlier.

Wed Nov 29, 2017 12:22 pm
Excuse me but I do not understand what you mean.

Wed Nov 29, 2017 1:01 pm
Error is normal with the Arduino_CORE_STM32 as the function TIM6_DAC1_IRQHandler is already defined in the core.

As already said, I have to review timer management, issue opened to track this review:
https://github.com/stm32duino/Arduino_C … issues/146

You issue is linked to this PR:
https://github.com/stm32duino/Arduino_C … 2/pull/150
Core already defined TIMx_IRQHandler while it should not.

Specifically this line:
https://github.com/stm32duino/Arduino_C … 54128R1119

WEAK void TIM6_IRQHandler(void)

Wed Nov 29, 2017 1:49 pm
Many many thanks, everyone.

Summarized for the one that happens to me and does not go crazy … :roll: :roll:

Change the timer.c file
All these void TIM…. for these WEAK void TIM…… and save.

When the interruption is defined in this way:

extern “C” {
void TIM6_DAC_IRQHandler ()
interruption code

And now :lol: :lol: :lol: :lol: :lol:

I almost died in this one.

thanks, thanks, thanks, everyone.

Leave a Reply

Your email address will not be published. Required fields are marked *