From 4a7c6c5b7ba8aa21599bd866a8aede97b3cd75e6 Mon Sep 17 00:00:00 2001 From: zouhaitao Date: Wed, 8 Jul 2026 11:50:20 +0800 Subject: [PATCH] fix: resolve byte-to-byte gap stretching in FCOB driver by introducing zero-gap double-buffered SPI transmission queue --- App/main.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/App/main.c b/App/main.c index ec76e8b..02058d4 100644 --- a/App/main.c +++ b/App/main.c @@ -164,13 +164,23 @@ void WS2812_Write24Bit(u8 g, u8 r, u8 b) SPCTL = 0xD0; // Enable SPI at SYSCLK/4 (6.0 MHz) SPSTAT = 0xC0; // Clear flags - for (i = 0; i < 15; i++) + SPDAT = buf[0]; // Goes to shift register immediately + // Wait at least 1 SPI clock cycle (8 system cycles) to avoid WCOL + _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); + SPDAT = buf[1]; // Goes to transmit buffer + + for (i = 2; i < 15; i++) { - SPDAT = buf[i]; - while (!(SPSTAT & 0x80)); + while (!(SPSTAT & 0x80)); // Wait for buf[i-2] to finish, buf[i-1] moves to shifter SPSTAT = 0xC0; + SPDAT = buf[i]; // Write buf[i] to transmit buffer (zero gap!) } + while (!(SPSTAT & 0x80)); // Wait for buf[13] to finish, buf[14] moves to shifter + SPSTAT = 0xC0; + while (!(SPSTAT & 0x80)); // Wait for buf[14] to finish + SPSTAT = 0xC0; + SPCTL = 0x90; // Disable SPI WS2812_DI = 0; MOTOR = 0; // Ensure motor is off