STM32F0 Data Transmission – Half Duplex Pulse Width Encoded

Well there’s the title! I’ve been working on creating a pretty simplistic half duplex data transmission through PWM. The protocol is currently half duplex because I’ve only just started writing it! Currently, data is encoded into the pulse width of the square wave sent between the two microcontrollers (currently an STM32F051 discovery for the receiver and an STM32F072 for the transmitter) with defined pulse widths for the Start, Stop, High bit and Low bit conditions. To cut to the chase, the current fastest data rate achievable is: 2.71kB/s (2779.225B/s for a perfect 48MHz clock)!

Alright, not the fastest data transfer protocol but pretty easily implementable and only requires one of the timer channels on your STM32 chip, with the ability to further increase the speed with DMA. Decoding is actually done in an interrupt so its not particularly efficient with respect to microcontroller time either. The bitrate could also be increased by sending multiple bits per period. By defining two extra times, PW00 (pulse width for two 0 bits), PW01, PW10 and PW11, two bits per period could be sent, effectively doubling the current achieved data rate! Obviously, you could have bit definitions for every possible period value (with a timer period of 255, you could essentially have 255 different bit definitions) though the problem here comes with system noise and clock drift potentially causing errors.

Currently, the timer is ran with a period of 100 and a maximum prescalar of 18. The protocol is pretty simple and consists of a start condition, followed by 8 bit periods (more bit periods will make each frame more efficient!). After the start condition and 8 bit periods, the transmitter sends a stop/idle condition of a low pulse width that can be used to detect the presence of the receiver. The stop/idle condition is also used to reset the receiver state machine. Full duplex is actually achievable with a single timer and two pins (like USART) by slowing down the transmission frequency so the processor can handle the full duplex data transfer.

Connecting the two STM32F0 discovery boards! The thick orange wire is to my oscilloscope.

Transmitting a single frame. The longest pulse width is the start condition, followed by a 1-bit, then a 0-bit and so on. The shortest pulse width  furthest left is the stop/idle condition.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s