STM32 WS2812B

From Stm32World Wiki
Revision as of 02:41, 22 April 2021 by Lth (talk | contribs)
Jump to navigation Jump to search
STM32Dev WS2812B RGB LED.jpg

When developing the STM32Dev board a WS2812B RGB LED was including connected to the PC6 GPIO.

The WS2812B LED contains 3 LEDS: red, green and blue and each of these LEDS can be set at 256 different brightness levels. These levels are controlled with a bit stream running at 800 kHz and multiple LEDS (up to 1000-ish) can be chained after each other.

Searching the Internet there are a lot of suggestions and implementations dealing with the ws2812 LEDs, so obviously I decided to take a different approach. This approach is described on this page.

Example

Before digging into the details, here's an example of a STM32F103 driving an 8 x 8 matrix of WS2812B LEDs:

Protocol Analysis

WS2812 LEDs are daisy chained together like this:

WS2812B Chain.png

When sending data each LED need 24 bit - 8 bit for each color. The first LED in the chain will "use" the first 24 bit and then pass any following bit to the next LED in the chain and so forth. After a reset (a pause with no data) this cycle repeats.

WS2812B Data Transmission Method.png

For each individual LED the 24 bits are expected like this:

WS2812 bits.png

Notice that for the WS2812B the order is GRB (Green, Red, Blue).


Library on Github

The library is available on Github:

https://github.com/lbthomsen/stm32-ws2812b

Links