Alternative use of timer output compare (pwm) and input compare on the same channel
Hi,
I use a timer channel and a DMA stream to generate a PWM signal.
At Transfer Complete interruption, I swap the channel to input capture mode to get an answer from external device, using the same DMA.
At transfer (reception) complete, I swap again to output compare mode.
It works, except that after having received data and reconfigured the timer channel to output compare, the first two data loaded by the dma into the CCR are not taken in account and the timer channel output stays 1 for two periods.
(It does the same if under debug I manually disable the DMA and force a value into the CCR)
The peripheral don't understand the command and of course do not send any answer. But after that, the timer channel is set again to output compare for next cycle and the output works again normally for one cycle.
So one in two of the cycle works : I send the command, I read the peripheral answer, but I can't send a right command just after having received an answer.
If I configure the external device to do not send answer, it works perfectly, I can send data, turn in input compare, later turn again in output compare and send the data correctly.
So the problem occurs only when the external device send an answer and a TC IT occurs.
To set in output compare mode I use TIM_OCxInit() and TIM_OCxPreloadConfig()
To set in input compare I use TIM_ICInit()
I also change the direction of DMA
I do miss something but do not know what.
Can anybody help?
Thanks in advance.
Ludovic
