Why does CAN reception in STM32F072 stop working when setting Pulse register for TIM2 or TIM3 to non-zero value?
I’m currently working on a project where I write software for an STM32F072 that will control a couple of stepper motor drivers via PWM with a bit of precision. I’m therefore using TIM2 and TIM3 to control two separate PWM outputs where I can regulate the period time in microseconds.
The board will also be connected to a CAN bus, mainly for receiving messages, but also to send some status messages. I’ve configured settings as far as possible using CubeMX and generated the project from there. After that I’ve coded in IAR EmbeddedWorkbench, which is our main coding environment for embedded.
1. I started by getting the CAN bus up an running, very basic functionality, just by polling via HAL functions. I could receive messages and bounce back replies. Everything was fine.
2. After that I set up TIM2 and TIM3 in CubeMX to use ‘Internal Clock’ as clock source and give PWM as output. I also setup the prescaler to get microsecond count for both timers.
3. I’m using the autoreload-register to set the period time for the PWM output (how often the stepper motor should take a step) and set the ‘On’-time for the PWM-signal using the Pulse register to 50 (i.e. 50 µs). The Pulse value was set directly in CubeMX.
4. When I had gotten the PWM-signals to behave the way I wanted, I noticed that CAN-reception was no longer functional.
I’ve tested this in small steps to localize precisely when this happens and reached the following conclusion. I can set everything up except for the Pulse register (which is set to zero by default) so that CAN is active and TIM2 and TIM3 count and give interrupts, but do not set their output pins high, since Pulse is still zero. If I then change the Pulse value for either TIM2 or TIM3 to something other than zero, CAN-reception stops working. I don’t even seem to get messages into the FIFO.
This is really quite strange, since the Pulse register is in the middle of a lot of settings for TIMx, nowhere near the settings for the CAN peripheral. I have as a final attempt tried activating interrupts for CAN reception. The result here was the same, though. With both Pulse registers (TIM2 and TIM3) set to zero CAN Rx/Tx is working, but with any or both of the Pulse registers non-zero, CAN Rx fails.
Hoping someone can point me in the right direction.
