Nucleo F334R8 - basic example of a Timer TIM2 mystery
Hi guys
So I am developing a small PWM generator around the F334R8, it's overall extremely simple. All the work is done with another MCU sending data on SPI.
On the F334R8, an EXT interrupt is called when the CS line is pulled down. From there the F3 listens on its MOSI line, grabs the data, and then outputs the 3 PWM channels on its HRTIM1.
That part is working really well.
I wanted to have a failsafe timeout using TIM2 on a 1second timer.
Basically every 1s a timer interrupt is called, and the program checks for a flag. If the flag is down, then I know that it's been 1s without proper data coming in and that the PWM output should be disabled.
For some reason I can't get that simple TIM2 to work.
So I decided to pull the Nucleo board again and create a super simple project that does nothing but toggle a LED on a 1s TIM2 timer.
- on the first try I had messed up the RCC because I selected the wrong oscillator. Fixing the oscillator does NOT fix the problem. The LED toggle is still wrong. It toggles at roughly 5Hz, regardless of the TIM2 settings. Changing the period has not impact whatsoever. Still is a slightly different behavior that I am experiencing on the custom board. So, then:
- I created a new project, same everything, but this time I carefully selected the correct oscillator on the first try, set up TIM2, generated code, compiled. And everything works perfect. 1 s toggles. I can change the period and everything works as expected.
So I am leaving the custom board issue aside for now, and I would really try to find out what's going on.
the 2 projects are identical, and couldn't be more simple. Your typical Timer Interrupt tutorial you find online.
However, one works and one does not. I wonder if CubeIDE somehow generated code when I had the wrong RCC config and fails to update that on subsequent code generations? I really don't know and that's why I'm here.
I uploaded both of these 2 basic projects here: https://gofile.io/d/1LTvVN
test-timer is the one that is blinking at the wrong frequency
test-timer-2 is the working test, which toggles the LED correctly
both of them are very similar. I went as far as reading the main.c line by line and couldn't find anything obvious. I also generated the pdf report but they didn't help.
I would appreciate if anyone could help steer me in the right direction.
thank you
