I'm pretty shure there a many read-to-use examples out there, but i also like to know how this is to be done

The incoming signal is already set to the logiclevel of the STM32 (3,3V), so it could be directly feed into one of the digital inputs of the Blue Pill an looks like this:
Code: Select all
_____ _ _ _ __ _
_____| |_| |_| |__| |___| |___| |_____
(1) (2) (3) (4) (5)
(2) If the sender prepares to send, he raises the status to HIGH (3,3V)
(3) Then it sends with some duty-cycle (here 50%)
(4) Duty-cycle can change
(5) If sending is done, signal falls back to LOW
I guess if should fed the signal to a interrupt pin which detects a raising edge and triggers a ISR which then put's some timecode into a variable like "raised_at" to know when the signal has raised. Then reprogram the port to act on a falling edge. If that falling edge occures, the ISR will be triggered again and put a timecode into "fall_at" and again reprogram to act on rising edge.
As soon as the next one appears, the ISR see the timecodes in both variables and could calc a duty-cycle by:
high_time = fall_at - raised_at
low_time = now - fall_at
ratio = high_time / low_time
Next, it should carry out, let's say 20 measures into an integral value to get a good mean-value. This should then be send to an upstream server. For that i need a counter and a variable.