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

SPIM - RX buffer is empty but MISO line shows correct traffic on Logic Analyzer

Hi everyone,

I am stuck with an apparently simple problem which I am not able to fix.....

I have an SPI device connected to a custom NRF52840 board. I am using NRFX_SPIM from SDK 15 to communicate with my device.

What I am trying to do is to simply read a register value from the device and to save it in a variable. To check that I can do this, I am using NRF_LOG_INFO in debug mode.

Well, the problem is that I can see the communication working fine from the logic analyzer (see picture below, 0x41 on MOSI is the command + register to read and 0x02 is the expected and correct reply from the device on the MISO)

but I cannot retrieve this value in the SPI callback. I took it almost entirely from the provided example, but just to be sure, this is my code for the involved functions

void SPICallback(nrfx_spim_evt_t const * p_event,
                          void *                  p_context)
{
    spi_xfer_done = true;
    NRF_LOG_INFO("SPI Transfer completed.");
    NRF_LOG_FLUSH();
    if (spi_rx_buff[0] != 0)
    {
        NRF_LOG_INFO(" Received:");
        NRF_LOG_HEXDUMP_INFO(spi_rx_buff, strlen((const char *)spi_rx_buff));
    } 
}

and the variables are declared as follows

static uint8_t spi_tx_buff[2];
static uint8_t spi_rx_buff[2];

static const nrfx_spim_t m_spi = NRFX_SPIM_INSTANCE(SPI_INSTANCE);  /**< SPI instance. */

/**
  * @brief  Configuration of the SPI interface
  *
  */
const nrfx_spim_config_t spi_config = {
    .sck_pin        = WN_SPI_CK,                             \
    .mosi_pin       = WN_SPI_MOSI,                           \
    .miso_pin       = WN_SPI_MISO,                           \
    .ss_pin         = WN_SPI_NCS0,                           \
    .ss_active_high = false,                                 \
    .irq_priority   = NRFX_SPIM_DEFAULT_CONFIG_IRQ_PRIORITY, \
    .orc            = 0xFF,                                  \
    .frequency      = NRF_SPIM_FREQ_1M,                      \
    .mode           = NRF_SPIM_MODE_1,                       \
    .bit_order      = NRF_SPIM_BIT_ORDER_MSB_FIRST,          \
};


uint8_t spi_txrx( uint8_t to_send )
{
  ret_code_t err_code;
  spi_tx_buff[0] = to_send;
  nrfx_spim_xfer_desc_t xfer_desc = NRFX_SPIM_XFER_TRX(spi_tx_buff, 2, spi_rx_buff, 2);
  spi_xfer_done = false;
  nrf_delay_us(50);
  err_code = nrfx_spim_xfer(&m_spi, &xfer_desc, NULL);
  return spi_rx_buff[0];
  
}

As said, the spi_rx_buff[0] stays to 0 even after the communication on the SPI is over.....I can correctly see that the SPI_Callback is called, and the rest of the code continue to run correctly, so there is no issue with it being blocked somewhere....My only problem is that the value on the MISO is apparently not received by the NRF.....

Any idea? 
Thanks in advance!

Parents Reply Children
Related