Closed morcibacsi closed 4 years ago
How about reading the pins state. The transition should always have been toward that state.
Or set state = !state
in every interrupt (but that could get out of sync).
Hi @morcibacsi , I would be better to raise such question in the forum: https://www.stm32duino.com/ Otherwise I agree with @AnHardt , reading pin state should do the job (like any GPIO pin).
Have a look at the ISR functions here: https://github.com/0xCAFEDECAF/VanBus .
I would like to decode a 125kbs signal, where one bit is 8 microseconds long. The protocol is called VAN bus which is an automotive bus which was used in the early 2000s. I am using a blue pill (STM32F103CBT6). My first idea was to use the input capture to measure the pulse widths. I found the example for the hardware timer here: https://github.com/stm32duino/STM32Examples/blob/master/examples/Peripherals/HardwareTimer/InputCapture/InputCapture.ino
If I use TIMER_INPUT_CAPTURE_BOTHEDGE then the data I am capturing seems to be fine as it is the multiple of 8 which is the length of 1 bit in the protocol.
However I got stuck with the InputCapture_IT_callback as I can't find the way to decide the direction of the pulse (whether I had an interrupt on the falling or on the rising edge).
As you can see in the code below I tried a TIMER_INPUT_CAPTURE_FALLING and tried to switch the capture direction every time an interrupt occured but it seems it is too slow and it seems I miss some transitions.
So my question is there any way to get the direction of the pulse? Or maybe the input capture is not what I should use? If that is the case what should I try? Any hint/tip is greatly appreciated.