This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Initializing device for SPI Communication (nRF5340)

I'm using Segger Embedded Studio version 1.6.0 to try to do some testing with SPI for a future project. Currently I am adding SPI functionality to the "Blinky" example: 7206.blinky.zip   I got the basic form of the way I'm trying to do SPI from another post on this forum: nRF5340 - P0.10 not working as SPIM MISO on non-secure build - Nordic Q&A - Nordic DevZone - Nordic DevZone (nordicsemi.com)   The problem I am running into is that the "device_get_binding(spiName) line is returning NULL, and I cannot figure out why that is or what to do to fix it. 

I have been looking around, and have found some examples of using SPI, but I am somewhat new to this and therefore am having a hard time understanding them. So I'm wondering how exactly one initializes SPI communication on the nRF5340-DK. Thanks you.

Parents
  • Hi,

    You have a few mistakes in your files. It's not even building for me.
    Try with these instead:

    prj.conf:

    CONFIG_GPIO=y
    
    CONFIG_SERIAL=y
    CONFIG_UART_INTERRUPT_DRIVEN=y
    
    # SPI
    CONFIG_SPI=y
    CONFIG_SPI_NRFX=y
    CONFIG_MAIN_STACK_SIZE=4096
    CONFIG_SPI_1_NRF_ORC=0xff
    

    nrf5340dk_nrf5340_cpuapp.overlay (change the file name to the same as the board):

    &spi1 {
    	compatible = "nordic,nrf-spim";
    	status = "okay";
    	mosi-pin = <4>;
    	miso-pin = <5>;
    	sck-pin = <6>;
    };
    

    main.c (line 42-44):

    static void spi_init(void) {
         const char* const spiName = "SPI_1";
         spi_dev = device_get_binding(spiName);

Reply
  • Hi,

    You have a few mistakes in your files. It's not even building for me.
    Try with these instead:

    prj.conf:

    CONFIG_GPIO=y
    
    CONFIG_SERIAL=y
    CONFIG_UART_INTERRUPT_DRIVEN=y
    
    # SPI
    CONFIG_SPI=y
    CONFIG_SPI_NRFX=y
    CONFIG_MAIN_STACK_SIZE=4096
    CONFIG_SPI_1_NRF_ORC=0xff
    

    nrf5340dk_nrf5340_cpuapp.overlay (change the file name to the same as the board):

    &spi1 {
    	compatible = "nordic,nrf-spim";
    	status = "okay";
    	mosi-pin = <4>;
    	miso-pin = <5>;
    	sck-pin = <6>;
    };
    

    main.c (line 42-44):

    static void spi_init(void) {
         const char* const spiName = "SPI_1";
         spi_dev = device_get_binding(spiName);

Children
Related