Unable to change the default SPIM_MOSI pin in led_strip example

I was trying out the led_strip example in the zephyr samples on my nrf52dk/nrf52832 board with a single external WS2812B neopixel led connected at P0.23, using the  WS2812B-SPI driver which is working perfectly fine.

But then as a part of learning exercise, I connected the WS2812B neopixel led to P0.07 and added pin control node to the existing boards/nrf52dk_nrf52832.overlay file. Although the program is compiling, but the the neopixel is not turning on at P0.07.

I have attached the overlay file code here for reference. Kindly please let me know, what I maybe doing wrong, as I am just a beginner.

/*
 * Copyright (c) 2019, Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */

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

#include "../nrf52-bindings.h"




&arduino_spi { /* MOSI on D11 / P0.23 */
	

	compatible = "nordic,nrf-spim";
	pinctrl-0 = <&spi2_default_alt>;
	pinctrl-1 = <&spi2_default_alt>;
	pinctrl-names = "default","sleep";
	status = "okay";

	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 = <1>; /* 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_alt:spi2_default_alt{
		group1 {
			psels = <NRF_PSEL(SPIM_MOSI, 0, 07)>;
		};
	};
	spi2_sleep_alt:spi2_sleep_alt{
		group1 {
			psels = <NRF_PSEL(SPIM_MOSI, 0, 07)>;
			low-power-enable;
		};
	};
};

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

  • On your end? It should be added to the devicetree .dts file. Are you working on an nRF52832 DK or a custom board?

    I am currently testing it on a DK with a nrf52832 chip, but I plan to continue on a custom board after I have the code working. I placed the "&uicr" in the back of the nrf25dk_nrf52832.overlay file, I will share it below.

    /*
     * Copyright (c) 2019, Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    #include <zephyr/dt-bindings/led/led.h>
    #include "../nrf52-bindings.h"
    
    &arduino_spi { // MOSI on D11 / P0.23 
    	compatible = "nordic,nrf-spim";
    	pinctrl-0 = <&spi2_default_alt>;
    	pinctrl-1 = <&spi2_sleep_alt>;
    	pinctrl-names = "default","sleep";
    	status = "okay";
    
    	led_strip: ws2812@0 {
    		compatible = "worldsemi,ws2812-spi";
    
    		// SPI 
    		reg = <0>; // ignored, but necessary for SPI bindings 
    		spi-max-frequency = <4000000>;
    
    		// WS2812
    		chain-length = <10>; // arbitrary; change at will 
    		color-mapping = <LED_COLOR_ID_GREEN LED_COLOR_ID_RED LED_COLOR_ID_BLUE>;
    		spi-one-frame = <0x70>;
    		spi-zero-frame = <0x40>;
    	};
    };
    
    &pinctrl {
    	spi2_default_alt: spi2_default_alt {
    		group1 {
    			psels = <NRF_PSEL_DISCONNECTED(SPIM_SCK)>,
    			        <NRF_PSEL(SPIM_MOSI, 0, 10)>,
    			        <NRF_PSEL_DISCONNECTED(SPIM_MISO)>;
    		};
    	};
    
    	spi2_sleep_alt: spi2_sleep_alt {
    		group1 {
    			psels = <NRF_PSEL_DISCONNECTED(SPIM_SCK)>,
    			        <NRF_PSEL(SPIM_MOSI, 0, 10)>,
    			        <NRF_PSEL_DISCONNECTED(SPIM_MISO)>;
    			low-power-enable;
    		};
    	};
    };
    
    / {
    	aliases {
    		led-strip = &led_strip;
    	};
    };
    
    &uicr {
        nfct-pins-as-gpios;
    };

    If you're on a DK you also need to change the R25 and R26 to be not connected (NC) and R27 and R28 to be shorted with an OR resistor.

    So if i understand correctly the resistors on the board might influence the data from p0.10. This might be the issue as I haven't considered the existing resistors on the DK board. But it doesn't explain why it doesn't work if i select pin p0.23 in the "spi2_default_alt"

  • Mr Sunshine said:
    So if i understand correctly the resistors on the board might influence the data from p0.10.

    Yes, by default the pin P0.10 goes directly to the NFC antenna by default, and you need to make these changes to the nRF52832 DK to output the data of these pins to the pin headers.

    In this .overlay file you seem to have set the pins as P0.10, but also what are the other SPIM_MISO and _SCK pins set as here?

    Best regards,

    Simon

  • Yes, by default the pin P0.10 goes directly to the NFC antenna by default, and you need to make these changes to the nRF52832 DK to output the data of these pins to the pin headers.

    OK, I'll test it with my custom board and see if it works.

    In this .overlay file you seem to have set the pins as P0.10, but also what are the other SPIM_MISO and _SCK pins set as here?

    I have searched the web for solutions to my problem, and I found an example that excluded the other pins with the "<NRF_PSEL_DISCONNECTED(SPIM_MISO)>" and "<NRF_PSEL_DISCONNECTED(SPIM_SCK)>" lines. I only use MOSI of the the spi2 for the ws2812, so I wanted to exclude the other pins to have more space on the board. Am I making an mistake here?

  • I have tried to flash the code on a custom board. But I still get no result even if I alter the pin on the nrf52dk_nrf52832-pinctrl.dtsi file. All I see on the logic reader is a high pulse of around 240 ms every 1.4 second.

  • Just to make sure. The overlay file will overwrite the settings in your .dts file, so if you still have set P0.10 in your .overlay file while trying to make changes in the .dtsi file, that won't help I'm afraid.

    Best regards,

    Simon

Related