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

SPI slave question

Hi: I have write a spi slave, and write a spi master on STM32, It can receive data from STM32,But I have no time to prepare the response data.

as the code below, I can receive the command 0x01 from master, But the response data can only be response in next reqest, At the first request, m_rx_buf buffer have no data.

  • How can I parse the command and prepare the reply data at the same time?

void spis_event_handler(nrf_drv_spis_event_t event)
{
    NRF_LOG_INFO("spis_event_handler\r\n");
    if (event.evt_type == NRF_DRV_SPIS_XFER_DONE)
    {
        if(m_rx_buf[0] == 0x01)
        {
            NRF_LOG_INFO("receive read ID command\r\n");
            m_tx_buf[0] = 0xE1;
            m_tx_buf[1] = 0xE2;
        }
        ....
       
        memset(m_rx_buf, 0, BUFFER_LENGTH);
        nrf_drv_spis_buffers_set(&spis, m_tx_buf, BUFFER_LENGTH, m_rx_buf, BUFFER_LENGTH);
    }
}

Parents
  • Hi,

     

    But the response data can only be response in next reqest, At the first request, m_rx_buf buffer have no data.

    This is as I would expect based on the SPI protocol. The SPI protocol works as shifting register on both sides, thus you should clock out data as you receive data. You set the tx buffer first after you have received data and the transaction has been completed. How would you then expect it to be able to send the data in that very same transaction?

    Maybe I misunderstood you, in that case please elaborate on your question.

    best regards

    Jared 

  • I coun't set my tx buffer exactly, because I don't know which command will be receive,I need to know waht the master request .My english is not very good, can you understand?

Reply Children
Related