Last active
May 1, 2022 10:47
-
-
Save terryspitz/970b801030fc6008e65956263c2f6500 to your computer and use it in GitHub Desktop.
Using PIC SPI to control WS2812b neopixel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void WS281x_Send() { | |
//[My] WS2812b seems sensitive only to timing of high, signal can be low for any period less than 50us reset. | |
//Using PIC at 32Mhz, SPI at FOSC/4 = 8Mhz | |
//Write one SPI byte per WS2812 bit, | |
//for WS2812 1 bit use pattern 0b01111110 which is high for 6x125=750ns | |
//for WS2812 0 bit use pattern 0b00111000 which is high for 3x125=375ns | |
//(keep first SPI bit low as this affects timings - SPI SDO goes high early before the clock starts) | |
//and ignore delays between SPI bytes as it stays low | |
for (char b=0; b < 3 * LED_COUNT; ++b) { | |
char colour = WS281x_buffer[b]; | |
for (char i = 7; i < 8; --i) { | |
SPI1_WriteByte((colour & 1U << i) ? 0b01111110 : 0b00111000); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
v1 tested on PIC16F15214