Welcome to ROSMASTER M3 repository
15.Driving RGB light strip
Driving RGB light strips
Driving RGB light strips1. Experimental Purpose2. Hardware Connection3. Core code analysis4. Compile, download and burn firmware5. Experimental Results
1. Experimental Purpose
Learn how to control a WS2812 RGB light strip using the SPI functionality of the STM32 controller board.
2. Hardware Connection
As shown in the figure below, the STM32 control board has an integrated RGB interface, but you need to connect an additional RGB light strip. You need to prepare your own RGB light strip and connect the type-C data cable to the computer and the USB Connect interface of the STM32 control board.
The RGB light strip is driven by the WS2812 chip, and the circuit design uses SPI+DMA to simulate the WS2812 control timing to drive the RGB light strip.

3. Core code analysis
The path corresponding to the program source code is:
xxxxxxxxxxBoard_Samples/STM32_Samples/RGB
According to the pin assignment, the signal pin of the RGB light strip is connected to PE6 (SPI4-MOSI), so the SPI4 is initialized to master mode. The clock frequency of SPI4 is 120MHz, divided by 32, so the final communication frequency of SPI4 is 3.75Mhz.



xxxxxxxxxxvoid MX_SPI4_Init(void){hspi4.Instance = SPI4;