Writing a driver for a WS8212B LED Strip

Post here all questions related to LibMaple core if you can't find a relevant section!
Post Reply
andywm
Posts: 3
Joined: Wed Jan 22, 2020 12:22 am

Writing a driver for a WS8212B LED Strip

Post by andywm »

Hi, I'm new to STM32 based dev boards.

I have a project where I need to drive an LED light strip. I don't need any fancy animations or anything. Initially I tried my go to, FastLED, but it blew up the executable size beyond what I have available. Plus I don't think it actually supports the hardware even if it fit in memory.

I had a look at the protocol from the data sheet for the WS8212B: https://cdn-shop.adafruit.com/datasheets/WS2812B.pdf - aside from the insane timing requirements it looked straight forward enough to implement in a day or so.

https://github.com/andywm/STM32_Arduino ... 8212Driver

Didn't quite go to plan though, it.. somewhat works. It will turn on roughly the number of LEDs I request. This is a bit fragile though, as it will usually start with the number I request then slowly add a few. Or not. This behaviour is inconsistient.

However, all of the LEDs it does turn on are solid white regardless of what colour pattern I program in. I assume the strip is reading every bit as a 1.

I have debugged the output my sequencing code is producing, it is as far as it's concerned setting the right timings for the bit pattern I feed in. I got an oscillioscope recently, but I'm still learning to use that.. But when set to the 500ns range I see pulses which look correct to my untrained eye and inexperienced at using this tool brain. I'll see if I can figure out how to capture that data...

I'm hoping someone on here can help me out as I've been trying to debug this for days now, I'm as confused as ever.
andywm
Posts: 3
Joined: Wed Jan 22, 2020 12:22 am

Re: Writing a driver for a WS8212B LED Strip

Post by andywm »

Additional information. I'm using platformio.
For wider context, an example program using my library is

Code: Select all

#include <Arduino.h>
#include <ws8212.h>

LEDStripDefinition<8> leds;

void setup()
{
	initialise_ws8212_lib(PA7);
	for( int i =0; i<leds.GetNumberOfLEDs(); i++ )
	{
		leds.GetLEDs()[i] = Colour::Blue;
	}
}

void loop()
{
	delay(500);
	writeToLEDs(leds);
}
fredbox
Posts: 125
Joined: Thu Dec 19, 2019 3:05 am
Answers: 2

Re: Writing a driver for a WS8212B LED Strip

Post by fredbox »

Check out Rogers writeup on NeoPixels: https://www.rogerclark.net/arduino-stm3 ... g-spi-dma/
User avatar
fpiSTM
Posts: 1757
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Writing a driver for a WS8212B LED Strip

Post by fpiSTM »

If you use the STM32 core (Arduino_Core_STM32) you can try the Adafruit NeoPixel Library:
https://github.com/adafruit/Adafruit_NeoPixel
andywm
Posts: 3
Joined: Wed Jan 22, 2020 12:22 am

Re: Writing a driver for a WS8212B LED Strip

Post by andywm »

I'm using Maple, not stm32 core. Roger's write up is interesting. I hadn't realised SPI could be used like that.

I might just use his library for my project, I tried using it, it works more or less. I did have an issue of it randomly pulsing colours on refresh before settling. And the goal of this project isn't to write an LED strip driver afterall..

Buuut. I reduced my version down to one pulse. The zero is too long.

Even having reduced the HW timer interrupt to 1 tick, and replacing digitalWrite with directly writing to the io register;

Code: Select all

gpioa->regs->BSRR = BIT(7) , gpioa->regs->BRR = BIT(7) 
It's still about 450-550ns after I've tried to reduce it.

I wonder what the overhead of that interrupt is. I might try spinning on a loop instead of using an interrupt for the 0 bit.
Post Reply

Return to “General discussion”