Xiao BLE - WS2812 with Zephyr

!!!Update!!!

The overlay file is working now. SPI2 needs to be used, with the MISO and SCK pin defined (even though they are unused). 

Hi,

After successfully setting up zephyr and running the blinky example on the Seeed XIAO BLE nRF52840 Sense, I tried to test a connected Adafruit NeoPixel Jewel Ring. Unfortunately nothing seems to be happening, I am pretty sure that I forgot about something or my overlay file is faulty. The LED Ring is connected to the SPI MOSI pin. If someone could guide me in the right direction or give specific advice, I would be very grateful.

Zephyr documentation: https://docs.zephyrproject.org/latest/samples/drivers/led_ws2812/README.html

The overlay function for the xiao_ble_sense board

#include <zephyr/dt-bindings/led/led.h>
#include "../nrf52-bindings.h"


&spi2 {
	compatible = "nordic,nrf-spim";
	status = "okay";
	pinctrl-0 = <&spi2_default>;
	pinctrl-1 = <&spi2_sleep>;
	cs-gpios = <&gpio1 15 GPIO_ACTIVE_LOW>; // D10
    pinctrl-names = "default", "sleep";

	led_strip: ws2812@0 {
		compatible = "worldsemi,ws2812-spi";

		/* SPI */
		reg = <0>; /* ignored, but necessary for SPI bindings */
		spi-max-frequency = <SPI_FREQ>;

		/* WS2812 */
		chain-length = <12>; /* arbitrary; change at will */
		color-mapping = <LED_COLOR_ID_GREEN
				         LED_COLOR_ID_RED
				         LED_COLOR_ID_BLUE>;
		spi-one-frame = <ONE_FRAME>;
		spi-zero-frame = <ZERO_FRAME>;
	};
};

&pinctrl {
    spi2_default: spi2_default {
		group1 {
			psels = <NRF_PSEL(SPIM_SCK, 1, 13)>,
				<NRF_PSEL(SPIM_MOSI, 1, 15)>,
				<NRF_PSEL(SPIM_MISO, 1, 14)>;
		};
	};

	spi2_sleep: spi2_sleep {
		group1 {
			psels = <NRF_PSEL(SPIM_SCK, 1, 13)>,
				<NRF_PSEL(SPIM_MOSI, 1, 15)>,
				<NRF_PSEL(SPIM_MISO, 1, 14)>;
			low-power-enable;
		};
	};
};

/ {
	aliases {
		led-strip = &led_strip;
	};
};

.conf file:

CONFIG_WS2812_STRIP_SPI=y
CONFIG_SPI=y

XIAO BLE pinout:

Parents
  • Hi,

    Unfortunately nothing seems to be happening

    If you measure on the SPI lines, do you see any clock signal on SCLK? Does the board have an external low frequency crystal?

    regards

    Jared 

  • Hi Jared,

    In the zephyr/boards subfolder I found the right SPI3 configuration, I just updated this in the above code. There is nothing on SCK, only on MOSI. If the board is attached to the power source and the ws2812 disconnected and reconnected to the MOSI pin, one of 12 LEDs is turned on and stays on. The colour depends on the timing of the reconnect, for example white or green, once turned on the colour does not change. If the power source is disconnected and reconnected, the LED remains off.

    If I am not mistaken, this seeed xiao nrf52840 has a 32 kHz crystal and a 32 MHz crystal.

    Regards, Scott

  • Hi,

    If you open up the project and build in the vs code and open up the Devicetree GUI, is the SPI pins mapped as you expected?

    wm2 said:
    If I am not mistaken, this seeed xiao nrf52840 has a 32 kHz crystal and a 32 MHz crystal.

    Could you do a quick test and try to flash a BLE sample such as the beacon example and see if you can see the device advertising? That would at least indicate whether the board has the onboard crystal or not,

    regards

    Jared 

Reply
  • Hi,

    If you open up the project and build in the vs code and open up the Devicetree GUI, is the SPI pins mapped as you expected?

    wm2 said:
    If I am not mistaken, this seeed xiao nrf52840 has a 32 kHz crystal and a 32 MHz crystal.

    Could you do a quick test and try to flash a BLE sample such as the beacon example and see if you can see the device advertising? That would at least indicate whether the board has the onboard crystal or not,

    regards

    Jared 

Children
Related