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

SPI in non-blocking mode ?

Hello all,

I am actually implementing an SPI-master driver in non blocking mode, I write the following code, when I use a debeug led, the program enters well in the IRQ, but nothing happen in the MOSI when I visualize the signal using the logic analyzer. :

 #include "spi.h"
#include "boardConfig.hpp"
#include "nrf_drv_spi.h"

#define BSP_UART_SUPPORT
#include "bsp.h"

#define CS_PIN 6
#define DQ0 22
#define DQ1 19
#define DQ2 20
#define DQ3 24
#define CLK 23

static const uint8_t leds_list[2] = {17, 18};

#define SPI_INSTANCE  1
static const nrf_drv_spi_t spi1 = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE);

static nrf_drv_spi_xfer_desc_t p_xfer_desc;

void spi_event_handler(nrf_drv_spi_evt_t const *p_event)
{
}

void initSPI()
{
    nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG;

    spi_config.ss_pin   = MEMORY_CHIP_SELECT;
    spi_config.miso_pin = MEMORY_DQ1;
    spi_config.mosi_pin = MEMORY_DQ0 ;
    spi_config.sck_pin  = MEMORY_CLOCK;

    nrf_drv_spi_init(&spi1, &spi_config, spi_event_handler);
}

void spiWrite(uint8_t *tx_payload, uint8_t size_tx)
{
    p_xfer_desc.p_tx_buffer = (uint8_t const *)tx_payload;
    p_xfer_desc.tx_length   = size_tx;
    p_xfer_desc.p_rx_buffer = NULL;
    p_xfer_desc.rx_length   = 0;
    nrf_drv_spi_xfer(&spi1, &p_xfer_desc, 0);
}
Parents
  • yes, I did, but as described in the documentation, nrf_drv_spi_transfer function perfoms transfer in blocking mode :

    /**

    • @brief Function for starting the SPI data transfer.
    • If an event handler was provided in the @ref nrf_drv_spi_init call, this function
    • returns immediately and the handler is called when the transfer is done.
    • Otherwise, the transfer is performed in blocking mode, which means that this function
    • returns when the transfer is finished.

    However, nrf_drv_spi_xfer is non-blocking, that's what is mentioned in the documentation.

Reply
  • yes, I did, but as described in the documentation, nrf_drv_spi_transfer function perfoms transfer in blocking mode :

    /**

    • @brief Function for starting the SPI data transfer.
    • If an event handler was provided in the @ref nrf_drv_spi_init call, this function
    • returns immediately and the handler is called when the transfer is done.
    • Otherwise, the transfer is performed in blocking mode, which means that this function
    • returns when the transfer is finished.

    However, nrf_drv_spi_xfer is non-blocking, that's what is mentioned in the documentation.

Children
No Data
Related