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

Sending to SPI Master from nRF52832 SPI Slave

I have a BMD-300 Eval board with the nRF52832 programmed as SPI slave using the SPIS example program. It works, but I cannot figure out how to send a message back to the master. I am using an Atmel uC as the master.

  • Hi

    In the SPI example there should be a line like this:

    APP_ERROR_CHECK(nrf_drv_spis_buffers_set(&spis, m_tx_buf, m_length, m_rx_buf, m_length)); 
    

    This call sets up the buffers that will be used for the next transaction. Whatever data you put into the m_tx_buf buffer will be output on the MISO line, and sent to the SPI master. The m_rx_buf buffer will be used to store incoming data from the master.

    Best regards
    Torbjørn

  • Hi Torbjørn,

    I have the same setup as described in the initial message...

    Can you explaine how the data is send out ??  ... I can load a wanted value to the TX buffer and call the function you are mentioning in your reply. But will the data be send out automatically ?  or do I still have have to clock back the message to the MCU ??

    As EasyDMA is used it may the first option , right ?  .. or is this just used for RX data ?

  • Hi Jesper

    There is nothing the SPI slave can do but wait for the SPI master to start a transaction. As such all you can do on the code side is to prepare the next payload, and wait for the SPI master to initiate communication. 

    Once this happens the incoming and outgoing data will be automatically written to/read from RAM by the EasyDMA controller. 

    Some SPI devices have an interrupt line that allows the SPI slave device to notify the SPI master device that it has some pending data, and would like the SPI master to start a transaction, but this not a part of the SPI standard and can be different from device to device. 

    If you are controlling both the SPI master and slave device you can obviously set up a dedicated interrupt pin, and use it to initiate communication from the slave side. 

    Best regards
    Torbjørn

  • As long as the nrf52 spi slave device is actin as a normal SPI slave device its OK.

    My SPI handler looks like this :

    void spis_event_handler(nrf_drv_spis_event_t event)
    {
       if (event.evt_type == NRF_DRV_SPIS_XFER_DONE)
       {
          spi_cmd = m_rx_buf[0];
          //NRF_LOG_INFO("0x%x", spi_cmd);
          switch(spi_cmd)
         {
             case SPI_BLE_GET_STATUS:
                NRF_LOG_INFO("CMD: Get status");
                ble_status = 0x39;
                m_tx_buf[0] = ble_status;
                m_tx_buf[1] = ble_status;
                break;
             default:
                NRF_LOG_INFO("An error occured in SPI command.");

                //break;
          }
          memset(m_rx_buf, NULL, sizeof(m_rx_buf));
          APP_ERROR_CHECK(nrf_drv_spis_buffers_set(&spis, m_tx_buf, sizeof(m_tx_buf), m_rx_buf, sizeof(m_rx_buf)));
          //spis_xfer_done = false;
       }
    }

    Receiving data/cmd from SPI master is working as expected, but sending back data (reply) to master, thats where I have a struggle.  ( I try to load 0x39 to the first 2 bytes of m_tx_buf , just to have something to send ) , but it is unclear how the SPI slave is actually send the data. Do I need to set a trigger or something or call a function ? ( I call the nrf_drv_spis_buffers_set at the end of SPI handler is that enough ? )

    Rgds,

    Jesper

  • .. I found the problem, ID10T Error, :-D , data gets through as it was supposed, the error resides in the debug print out string/call.

Related