5 years or so ago I was obsessed with these ws281x chips. It was back when I was searching around for the MCU I wanted to spend my time focusing on. Getting the ws281x working on a chip became my standard test to see how flexible the chips architecture really was. If I could make a chip drive a w281x pixel without flogging myself, then I'd probably be happy writing code for the chip. I got the msp430s going pretty easily with its SPI and also by cycle count bit banging. The pic24f easily did it with cycle counting and a small asm routine even with the free compiler. The LPC1114 has a really flexible SPI peripheral and that was easy to get going. The LPC81x series has a SCT (State Configurable Timer) peripheral which offers nano second level logic based on a state table. That is easily the slickest and did everything without the cpu getting involved.RogerClark wrote:From reading some other experimental blogs about the WS2812B, I was also wondering if all that was required to send a pixel 1 or 0, was just the length of time that the input is at in logic High state, and that perhaps a short pulse of 100nS followed by logic low for 100nS would be OK.
Ah but the STM32F103 for all its nice things isn't the easiest way to drive these leds. To be honest I find the STM32 SPI peripheral lacking even compared to the msp430 and lpc111x. It is not that flexible by itself, you have to use multiple peripherals to make it happy.
One approach to this problem for the STM32F103 I've thought about, but haven't implemented, is driving the SPI peripheral as a slave. I'd use the MISO pin as the output and send it to the led chip. I'd drive the SPI_CLK using a timer, that way you'd have much more control over the SPI clock. Of course I'd just ignore MOSI. Then the problem is to create an array of pulses you could just DMA into it. Which I guess is what you are doing now. The advantage would you could fine tune the SPI_CLK so the bits work out to your advantage. Personally I'd just use 8 bytes per GRB so you'd end up using 24 bytes per led pixel. However then you could drive the clock at 6.4MHz and have more bit resolution for tweaking. 800kHz / 8 bits yields a decent bit rate of 156.25 ns so 0b11000000 is 312.5 ns and 0b11110000 is 625 ns.
The code would look something like this
https://gist.github.com/RickKimball/976 ... 9d46a53939
(ignore that this is using an msp430f5529 and dma) ( Also, there are comments talking about the bit timing based on the SYSCLK speed in that code below)
The one other thing I spent some time doing was figuring out what timing my led chip is really using. Turn on your scope and watch the data you are sending in to the led. Make note of your timings then measure the data out pin coming out of the led chip going into the next chip. Those numbers are the timing your ws281x chip really wants. I don't remember the numbers but I do remember being surprised in that all the numbers I found in online data sheets didn't match the timing the chip was generating. Which of course is what the led chip really wants to be fed.