Page 1 of 1

Using SPI1 disables TIMER1 compare interupt

Posted: Sun May 14, 2017 4:49 pm
by abhisheksafui
Is there any relation between timer 1 and spi 1. I was using timer 1 channel 1 compare match interrupt, but as sson as i enabled SPI 1, the timer interrupt never gets called. Just changing the timer number re enables the interrupt. How do I use both of them?

Re: Using SPI1 disables TIMER1 compare interupt

Posted: Sun May 14, 2017 5:48 pm
by stevestrong
Which pin do you use for SPI1 chip select ?
Because the PA8..PA11 pins are timer 1 related and they will be overwritten by pinMode().

Re: Using SPI1 disables TIMER1 compare interupt

Posted: Sun May 14, 2017 10:01 pm
by RogerClark
We have an open issue with pinmode disabling other timers to turn off pwm.
But it doesnt seem to be necessary to turn off the timer ( I thought it was Timer 4 but I would need to double check)

If we comfirm that pinmode does not need to disable any timers, and chance to Core, Perhaps it would fix this.

Re: Using SPI1 disables TIMER1 compare interupt

Posted: Mon May 15, 2017 8:45 am
by rmdMoba
Yes, I found this issue when using timer 4. But it's not limited to timer 4. If you set a non-pwm mode on any pwm capable pin, then the corresponding timerchannel is disabled. The timer_set_mode() function for this timer/channel ist called with parameter 'TIMER_DISABLED'. This clears the compareOutputEnable Bit of that channel and detaches the attached ISR's. The main problem is that the ISR's are detached.
My fix at the moment is, to not call the timer_set_mode() fuction when a non-pwm mode is set. This doesn't clear the compareOutputEnable Bit if it was set by a previous pwm mode. But that doesn't seem to matter, because the output pin is disconnected from the timer by the gpio configuration in non pwm modes. In my tests the fix worked so far when setting PWM - reset to OUTPUT - and set PWM again. But I will do some more tests with different port modes.
You can check if that fix solves your problem too by editing the ..../hardware\Arduino_STM32\STM32F1\cores\maple\stm32f1\wirish_digital_f1.cpp.
The fix is fairly simple, as you can see here

Re: Using SPI1 disables TIMER1 compare interupt

Posted: Mon May 15, 2017 5:06 pm
by abhisheksafui
Yes that fixed the problem. But before that fix i found that shifting my pins to 7,6,4,3 and 2 also enabled all the timers. 4 and 3 are pwm pins why didn't they interfere any timer?

When I use pin 27 as output, timer 1 stops. How do I know which pins are related to which timer?
As someone said that pins 8-11 are associated with timer 1, then why pin 27 stops timer 1?

Re: Using SPI1 disables TIMER1 compare interupt

Posted: Mon May 15, 2017 5:50 pm
by abhisheksafui
Ok thanks. I found out the pin map 24-27 maps to PORTA8-11.