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

nRF51 SPIM transfer

Hi,

I wanted to know how the SPI rx_buffer is filled? Is it automatically filled when something is pushed to him by the SPI-slave and then goes to the spi_event_handler? Or is just filled when I do a nrf_drv_spi_transfer and don't set the rx_buffer to NULL?

My project consists on: I need to transfer the data received via BLE through the SPI to SPI-slave, and when I receive something through SPI from the SPI-slave I send it via BLE. Triggering the SPI tx is done by calling the nrf_drv_spi_transfer with the rx_buffer set to NULL. But I have no idea how to get a flag or something when the rx_buffer has something.

EDIT: From what I read about this rx_buffer can't be triggered. So I think the best way is to use a pin as a flag, to signal that the SPI-slave wants to send something, is this correct?

Thanks for the help,

Jorge

using this versions SDK11, S130, nRF51

Parents
  • From my experience, the buffer is filled when you call nrf_drv_spi_transfer. On the application side you can make two fixed size buffers for both tx and rx.

    When you call nrf_drv_spi_transfer(&m_spi_m, tx_buffer, tx_bytes, rx_buffer, rx_bytes), specify value for tx_bytes, it is the number of bytes you want to put on the SPI master-out pin; rx_bytes refers to the number of bytes you want to fill for the rx_buffer, beginning at the start of your transaction.

    For example, a register read on a SPI peripheral requires first writing the address of register you want to read, SPI peripheral will return the value of that register as soon as you finish writing the address. In this case tx_bytes is 1, rx_bytes is 2. When the call completes with call back, you will get the read from rx_buffer[1].

    In general, if you want to tx x bytes, and receive y bytes after x bytes has been transferred, rx_buffer needs to be the size of (x + y). A valid read back value will start at rx_buffer[x] for the length of y.

    Back to your question, I think you can make a rx_buffer large enough to contain the read back from SPI peripheral; write a call back function after the transaction is done and examine the value of rx_buffer. Write a callback in the form of typedef void (*nrf_drv_spi_handler_t)(nrf_drv_spi_evt_t const * p_event); and provide it when you call nrf_drv_spi_init(&m_spi_m, &spi_config, spi_event_handler); to deal with the information you have received.

    Hope this helps!

Reply
  • From my experience, the buffer is filled when you call nrf_drv_spi_transfer. On the application side you can make two fixed size buffers for both tx and rx.

    When you call nrf_drv_spi_transfer(&m_spi_m, tx_buffer, tx_bytes, rx_buffer, rx_bytes), specify value for tx_bytes, it is the number of bytes you want to put on the SPI master-out pin; rx_bytes refers to the number of bytes you want to fill for the rx_buffer, beginning at the start of your transaction.

    For example, a register read on a SPI peripheral requires first writing the address of register you want to read, SPI peripheral will return the value of that register as soon as you finish writing the address. In this case tx_bytes is 1, rx_bytes is 2. When the call completes with call back, you will get the read from rx_buffer[1].

    In general, if you want to tx x bytes, and receive y bytes after x bytes has been transferred, rx_buffer needs to be the size of (x + y). A valid read back value will start at rx_buffer[x] for the length of y.

    Back to your question, I think you can make a rx_buffer large enough to contain the read back from SPI peripheral; write a call back function after the transaction is done and examine the value of rx_buffer. Write a callback in the form of typedef void (*nrf_drv_spi_handler_t)(nrf_drv_spi_evt_t const * p_event); and provide it when you call nrf_drv_spi_init(&m_spi_m, &spi_config, spi_event_handler); to deal with the information you have received.

    Hope this helps!

Children
No Data
Related