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

nRF5340 SPI example code

Hi,

could you provide me an example codes for SPI (serial peripheral communication), SPIM(serial peripheral communication master) and SPIS(serial peripheral communication slave) for nRF5340 SoC.

Thanks & Regards,

Srinivas.

  • Hi,

    Thanks for the response. 

    My problem is resolved. I am confused in pin connection. After change the pin connections it's working fine.

    Regards,

    Srinivas Rao

  • Hi! I'm trying to build the example (SPI Master) but I was not able to compile without errors.

    My environment is SDK 2.2.0, the board choosed is the Nordic 5340dk (I have an Ublox NORA EVK 106-B that is pretty similar & I have also the device tree). The output is:

    Building spi_master
    C:\Windows\system32\cmd.exe /d /s /c "west build --build-dir c:/Users/cirincione/nordic/spi_master/build c:/Users/cirincione/nordic/spi_master --pristine --board nrf5340dk_nrf5340_cpuapp -- -DNCS_TOOLCHAIN_VERSION:STRING="NONE" -DCONF_FILE:STRING="c:/Users/cirincione/nordic/spi_master/prj.conf" -DBOARD_ROOT:STRING="c:/users/cirincione/nordic/peripheral_lbs;c:/users/cirincione/nordic/peripheral_lbsx;c:/users/cirincione/nordic/peripheral_lbs_int;c:/users/cirincione/nordic/testselcom""

    -- west build: generating a build system
    CMake Warning at C:/ncs/v2.2.0/zephyr/cmake/app/boilerplate.cmake:20 (message):
    Loading of Zephyr boilerplate.cmake directly is deprecated, please use
    'find_package(Zephyr)'
    Call Stack (most recent call first):
    CMakeLists.txt:9 (include)


    Loading Zephyr default modules (Zephyr base).
    -- Application: C:/Users/cirincione/nordic/spi_master
    -- Found Python3: C:/ncs/toolchains/v2.2.0/opt/bin/python.exe (found suitable exact version "3.8.2") found components: Interpreter
    -- Cache files will be written to: C:/ncs/v2.2.0/zephyr/.cache
    -- Zephyr version: 3.2.99 (C:/ncs/v2.2.0/zephyr)
    -- Found west (found suitable version "0.14.0", minimum required is "0.7.1")
    -- Board: nrf5340dk_nrf5340_cpuapp
    -- Found host-tools: zephyr 0.15.1 (C:/ncs/toolchains/v2.2.0/opt/zephyr-sdk)
    -- Found toolchain: zephyr 0.15.1 (C:/ncs/toolchains/v2.2.0/opt/zephyr-sdk)
    -- Found Dtc: C:/ncs/toolchains/v2.2.0/opt/bin/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6")
    -- Found BOARD.dts: C:/ncs/v2.2.0/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp.dts
    -- Generated zephyr.dts: C:/Users/cirincione/nordic/spi_master/build/zephyr/zephyr.dts
    -- Generated devicetree_generated.h: C:/Users/cirincione/nordic/spi_master/build/zephyr/include/generated/devicetree_generated.h
    -- Including generated dts.cmake file: C:/Users/cirincione/nordic/spi_master/build/zephyr/dts.cmake
    Parsing C:/ncs/v2.2.0/zephyr/Kconfig
    Loaded configuration 'C:/ncs/v2.2.0/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp_defconfig'
    Merged configuration 'c:/Users/cirincione/nordic/spi_master/prj.conf'

    error: NRFX_SPIM (defined at C:/ncs/v2.2.0/zephyr/modules/hal_nordic\nrfx/Kconfig:190,
    modules\hal_nordic\nrfx/Kconfig:190) is assigned in a configuration file, but is not directly user-
    configurable (has no prompt). It gets its value indirectly from other symbols. See
    docs.zephyrproject.org/.../kconfig.html and/or look up NRFX_SPIM in the
    menuconfig/guiconfig interface. The Application Development Primer, Setting Configuration Values,
    and Kconfig - Tips and Best Practices sections of the manual might be helpful too.

    CMake Error at C:/ncs/v2.2.0/zephyr/cmake/modules/kconfig.cmake:328 (message):
    command failed with return code: 1
    Call Stack (most recent call first):
    C:/ncs/v2.2.0/nrf/cmake/modules/kconfig.cmake:29 (include)
    C:/ncs/v2.2.0/zephyr/cmake/modules/zephyr_default.cmake:108 (include)
    C:/ncs/v2.2.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:66 (include)
    C:/ncs/v2.2.0/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:92 (include_boilerplate)
    C:/ncs/v2.2.0/zephyr/cmake/app/boilerplate.cmake:25 (find_package)
    CMakeLists.txt:9 (include)


    -- Configuring incomplete, errors occurred!
    FATAL ERROR: command exited with status 1: 'C:\ncs\toolchains\v2.2.0\opt\bin\cmake.EXE' '-DWEST_PYTHON=C:\ncs\toolchains\v2.2.0\opt\bin\python.exe' '-Bc:\Users\cirincione\nordic\spi_master\build' -GNinja -DBOARD=nrf5340dk_nrf5340_cpuapp -DNCS_TOOLCHAIN_VERSION:STRING=NONE -DCONF_FILE:STRING=c:/Users/cirincione/nordic/spi_master/prj.conf '-DBOARD_ROOT:STRING=c:/users/cirincione/nordic/peripheral_lbs;c:/users/cirincione/nordic/peripheral_lbsx;c:/users/cirincione/nordic/peripheral_lbs_int;c:/users/cirincione/nordic/testselcom' '-Sc:\Users\cirincione\nordic\spi_master'

    * The terminal process terminated with exit code: 1.
    * Terminal will be reused by tasks, press any key to close it.

    The same output if I try with the Ublox Board.

    I didn't understand the modifications that I need to do in the project to make it buildable.

    The target is to build a working example for the Ublox EVK & SPI4 in order to test the SPIM API.

    Could anyone support me?

    Many Thanks & Best Regards

  • Other info:

    I noticed that several inclusion files like as zephyr.h or nrf.h, for example, introduced fatal errrors.

    I can include <nrfx.h>, <nrfx_spim.h> and <nrfx_gpiote.h> instead of.

    Seems that the 2.2.0 SDK does not permit that.

    ------------------------------------------------------------------------

    Update 2023/07/13 - 12:06 AM:

    - I try to port one piece at time into my project in wich I have a DT che define the SPI4.

    - The inclusions are: #include <nrfx.h>, #include <nrfx_spim.h>, #include <nrfx_gpiote.h>

    - I tested a declaration of a spi's type
     
    static nrfx_spim_config_t spim_config = NRFX_SPIM_DEFAULT_CONFIG(APP_SPIM_SCK_PIN, APP_SPIM_MOSI_PIN, APP_SPIM_MISO_PIN, APP_SPIM_CS_PIN); . And it coimpile with success.

    - If I insert the ISR:  

    static void manual_isr_setup(){
    #ifdef NRF9160_XXAA
        IRQ_DIRECT_CONNECT(UARTE3_SPIM3_SPIS3_TWIM3_TWIS3_IRQn, 0,
                   nrfx_spim_3_irq_handler, 0);
        irq_enable(UARTE3_SPIM3_SPIS3_TWIM3_TWIS3_IRQn);

    #else  
        IRQ_DIRECT_CONNECT(SPIM3_SPIS3_TWIM3_TWIS3_SPI3_TWI3_IRQn, 0,
                   nrfx_spim_3_irq_handler, 0);
        irq_enable(SPIM3_SPIS3_TWIM3_TWIS3_SPI3_TWI3_IRQn);
    #endif
    }

    The building failed because the SPIM3_SPIS3_TWIM3_TWIS3_SPI3_TWI3_IRQn is not declarated.

    ------------------------------------------------------------------------

    Thanks Again

  • Please post your issue in a new thread, instead of this closed ticket. We will then help you look into it.

Related