I have been trying to control a small 8-led board with WS2812B’s using some SPI examples. Since i have SPI1 used already for other communication, and SPI6 does not have regular DMA, i chose SPI2 (Daisy pin D20), it was not working for a long time because i supposed that baud prescaler is applied to a 400Mhz but then I kinda brute-forced and it worked with a prescaler 4 so i suspect that SPI1,2,3 is driven from some other PLL. So i hope someone could sched a light to some questions i got:
what is the actual SPI frequency before prescaler (and which PLL is used - i tried reading the code but somehow it goes deep into HAL and i have little knowledge about low level clock registers)
I have the first LED being off color (seems like green is always at max level), and it is not related to that data signal is 3.3V - i have added LVC1G125 (powered from 5v) and it is still the same, i even tried connecting two led boards in parallel, one with and other without level shifting and they look exactly the same. My theory is that i would need more precise control over SPI frequency so maybe changing the PLL clock or so, because i suspect that LED controller part which is collecting data to shift to next pixel is more tolerant and thus '‘fixes’ the timing problems while the pther part which drives PWM on the LED is not that good with vague timings. Is there any side effects if i change PLL for SPIs 1,2,3? And what is proper approach for this? Direct HAL calls or…? Btw, the SPI1 is in use but as slave (other MCU is talking to it)
I would like also to try the other, timer PWM + DMA approach, if i can’t fix SPI, but all the examples i have found are for STM32F series and mainly also involving STM32CubeIDE while i would like to either have an example for STM23H MCU or at least to know the timer frequencies etc in words, not in IDE screenshots, so i could try to port example to Daisy. Did anyone try it and could share anything about it?
FYI i have connected it to ther MCU where i know clocks, and setting it to even a perfect bitrate (6.4Mbaud) was not fixing the issue. I have a feeling that maybe newer LEDs are more timing sensitive or so, because whatever worked for other a couple of years ago is not working well now. So i give up SPI approach, leaving the timer PWM + DMA to try. If anyone by any chance have a STM32H7xx code to peek into or so, let me know, because STM32 is a new platform for me and i have no idea what changes would i need to change code using STM32F series to work on Daisy
I’m really sorry for the delay in response.
So for that particular LED, you would need to use hardware PWM and not SPI.
We unfortunately, at the moment, don’t have a support and example available for using the WS2812 with the Daisy.
I believe the Fast LED library that’s made for Arduino IDE should work?
You could consider using the SK9822 LED which infrasonicaudio made a PR for that was merged to libdaisy. It uses SPI.
Hey, no worries. This project has two MCUs one for audio/mmcsd (guess which) and other for low level hardware stuff, exhanging data with SPI. Initially wanted to offload this task from other MCU which must bitbang 3.5Mhz bus keeping the right timings, but … ended up using UART-based solution on that NXP MCU for RGB LEDs. Required some nasty coding using state machines though to fit the timings. As of now - schematics finished, PCB routed, prototypes soldered, so not a time to revert this decision
Well, still will try your suggestions when i have more time just to close this question for myself but only after other things are ready
Hi, We (@Nico ) managed to create an SPI+DMA method that drives the WS2812B. The main problem with the test code that we posted is that the baud prescaler is incorrect. The issue of the first LED being the wrong colour (green) can also be mitigated by adding a small number of leading 0 bits. I’m not sure if this counts as a hack or an acceptable solution. It works quite smoothly now for eight leds. I can make a pull request if it helps.