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

HOW TO READ DATA FROM A REGISTER USING SPI

Hello, i have been unable to read data from my sensor. 

uint8_t SPI_ReadByte(uint8_t RegAddress)
{
ret_code_t retCode = NRF_SUCCESS;
//start reading sequence
m_tx_buf[0]=RegAddress|0x80;
m_tx_buf[1]=0x00;
retCode = nrf_drv_spi_transfer(&spi_master,
m_tx_buf, 3,
m_rx_buf, 3);
APP_ERROR_CHECK(retCode); // NRF_ERROR_BUSY

NRF_LOG_HEXDUMP_INFO(m_tx_buf,2);


return m_rx_buf[3];
}

Parents
  • Hi,

     

    Are you setting up the nrf_drv_spi in non-blocking mode? If yes, then it is expected to see NRF_ERROR_BUSY if you do not wait until the former SPI transaction is done.

    Please see the nRF5 SDK example "peripheral/spi/" and look at how it handles variable "spi_xfer_done".

     

    Kind regards,

    Håkon

  • Hello, I am actually using that same code, its just an additional function in it. I am not getting anything. How to set it up in non-blocking mode?

  • Hi,

     

    If you set the spi event handler to "NULL" when initing nrf_drv_spi, then you're setting the driver in blocking mode. If you init with an event handler, then its in non-blocking mode.

    In your case, you can either set it in blocking mode (set event handler to NULL) or handle the _BUSY return in your SPI function.

     

    Kind regards,

    Håkon

Reply
  • Hi,

     

    If you set the spi event handler to "NULL" when initing nrf_drv_spi, then you're setting the driver in blocking mode. If you init with an event handler, then its in non-blocking mode.

    In your case, you can either set it in blocking mode (set event handler to NULL) or handle the _BUSY return in your SPI function.

     

    Kind regards,

    Håkon

Children
No Data