I am using SPI0 of nrf52.Following is the code:
I am using SPI0 of nrf52.Following is the code:
Can you please try to tidy up your code? Remove all the code that is not necessary and show us how exactly you are initiating the SPI and how you do read and write operations.
I don't see the write()
function you have in your code. Also in your read()
function you start a transfer with nrf_drv_spi_transfer()
and then already in the next line you try to read the rx buffer. At this point the SPI will not yet have completed the transfer and hence, you will not be able to read new data. You need to wait until the SPI interrupt handler is called with a message saying the transfer is complete. Or you can initiate the SPI driver in blocking mode. Then nrf_drv_spi_transfer()
will not return before the transfer is done and it is safe to read the data in the next line. You can use blocking mode by writing nrf_drv_spi_init(p_instance, &config, NULL);
I don't see the write()
function you have in your code. Also in your read()
function you start a transfer with nrf_drv_spi_transfer()
and then already in the next line you try to read the rx buffer. At this point the SPI will not yet have completed the transfer and hence, you will not be able to read new data. You need to wait until the SPI interrupt handler is called with a message saying the transfer is complete. Or you can initiate the SPI driver in blocking mode. Then nrf_drv_spi_transfer()
will not return before the transfer is done and it is safe to read the data in the next line. You can use blocking mode by writing nrf_drv_spi_init(p_instance, &config, NULL);