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

SPIM transfer crashing on nRF5340

Hi,

I'm developing a program using SPIM instance 1 on nRF5340 PDK, with nRF Connect SDK 1.4.0. 

The problem I met is exactly the same as this post. If I want to use a handler, the SPI transfer will crash.

However, it seems I can not solve this problem on nRF5340 like the post above, as there is no nrfx_irqs header file for nRF5340 in the nrfx library. 

So, is there any workaround to solve this?

Parents
  • Hi,

    How did you add SPI(M) to your application? Are you using the NRFX APIs directly, or do you use the Zephyr SPI API?

    Can you post your prj.conf file, and any devicetree overlay files that you are using?

    Best regards,
    Jørgen

  • The address of the SPI START task is static and can be found in the product specifications, you do not need to use any API to get this.

    Can you post the code you used for configuring/initializing the SPIM driver? Then I can try to reproduce this behavior.

  • Thanks, Jørgen.

    Here's my codes for initializing SPIM driver.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    #include <string.h>
    #include <nrfx.h>
    #include <nrfx_spim.h>
    #include <nrfx_gpiote.h>
    #include <nrfx_dppi.h>
    #define SPI_INSTANCE 1
    #define SPI_CS_PIN 4
    #define SPI_SCK_PIN 5
    #define SPI_MOSI_PIN 6
    #define SPI_MISO_PIN 7
    nrfx_spim_t spi = NRFX_SPIM_INSTANCE(SPI_INSTANCE);
    static void spi_event_handler(nrfx_spim_evt_t const * p_event, void * p_context)
    {
    printk("spi event!\n");
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    In the nrfx sample I mentioned above, there's additional codes to init the GPIOTE interrupt handler: 

    Fullscreen
    1
    2
    3
    IRQ_CONNECT(DT_IRQN(DT_NODELABEL(gpiote)),
    DT_IRQ(DT_NODELABEL(gpiote), priority),
    nrfx_isr, nrfx_gpiote_irq_handler, 0);
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    I think this may be what I'm missing. Is there any documentation about how to init a SPI interrupt handler?

  • Hi, Jørgen.

    I'm still stucking on this problem (though I can avoid this by not using any SPI handler). Do you have any other thoughts on this? Or could you provide with a SPIM sample project for nRF5340?

    Best Regards,

    Jason Lei

Reply
  • Hi, Jørgen.

    I'm still stucking on this problem (though I can avoid this by not using any SPI handler). Do you have any other thoughts on this? Or could you provide with a SPIM sample project for nRF5340?

    Best Regards,

    Jason Lei

Children
  • Hi,

    Sorry for not getting back to you sooner on this issue.

    You can find a working nrfx SPIM example with handler in this post. I tested the example by building it for nrf5340dk_nrf5340_cpuapp target, but I had to modify one function in main.c to the following:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    static void manual_isr_setup()
    {
    #if defined(NRF9160_XXAA)
    IRQ_DIRECT_CONNECT(UARTE1_SPIM1_SPIS1_TWIM1_TWIS1_IRQn, 0,
    nrfx_spim_1_irq_handler, 0);
    irq_enable(UARTE1_SPIM1_SPIS1_TWIM1_TWIS1_IRQn);
    #elif defined(NRF5340_XXAA)
    IRQ_DIRECT_CONNECT(SPIM1_SPIS1_TWIM1_TWIS1_UARTE1_IRQn, 0,
    nrfx_spim_1_irq_handler, 0);
    irq_enable(SPIM1_SPIS1_TWIM1_TWIS1_UARTE1_IRQn);
    #else
    IRQ_DIRECT_CONNECT(SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn, 0,
    nrfx_spim_1_irq_handler, 0);
    irq_enable(SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn);
    #endif
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Can you check if you are able to use this example?

    Best regards,
    Jørgen

  • Thanks, Jørgen. With your code above, now I can get into a SPI handler successfully.