I checked that with my simple WS2812 driver below. Yes. The problem is, that the granularity of the SPI timing is not sufficient. At 3200000, the bit time is ~500ns, at 3800000 the bit time decreases to 250 ns.
Code: Select all
from machine import SPI, disable_irq, enable_irq
from time import sleep, sleep_us
def send_spi(data, spi):
no_pixel = len(data)
buffer = bytearray(no_pixel * 3 * 3)
index = 0
for pixel in data:
for byte in pixel:
bits = 0
mask = 0x80
while mask:
bits <<= 3
if byte & mask:
bits |= 0x06
else:
bits |= 0x04
mask >>= 1
buffer[index] = (bits >> 16) & 0xff
buffer[index + 1] = (bits >> 8) & 0xff
buffer[index + 2] = (bits) & 0xff
index += 3
sleep_us(60) # ensure initial reset
state = disable_irq()
spi.write(buffer)
enable_irq(state)
def run(rate = 3200000):
data = 6 * [
(85, 0, 0), # green
(0, 85, 0), # red
(0, 0, 85), # blue
(85, 85, 85), # white
]
print(data)
blank = 24 * [(0, 0, 0)]
spi = SPI(1, baudrate=rate, polarity=0, firstbit=SPI.MSB, bits=8)
for _ in range(5):
send_spi(data, spi)
sleep(1)
send_spi(blank, spi)
sleep(1)
edit: That was at a clock rate of 120 Mhz. Setting the clock to 192 Mhz got a better match to 3200000 baud (2940000).