Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf_drv_spi_transfer takes too long time

Good morning, 

I am working on nRF52840 DK, using nRF5 SDK.

I am trying to communicate using SPI.

However, I found out that the function nrf_drv_spi_transfer took 10µs, I need to work at high sampling rate to get a good result of my system, therefore, I would need 2µs to get the response.

These 10µs therefore limit my sampling rate.

Here is my test to measure the duration of the function nrf_drv_spi_transfer : 

I visualize the signal of LED0 on my oscilloscope.

Here is the result of the test :

   

Yellow : LED0

Blue : MISO

Pink : SCK

We can see that within 2.33µs, I have already gotten the response from the slave. However LED0 is still at high level indicating that I am still inside the function nrf_drv_spi_transfer for another 7µs, I would like to know what is the function nrf_drv_spi_transfer waiting for ? Can I reduce this duration ?

By the way, the frequency of SPI is at 8MHz(maximum), however it doesn't help me to reduce this mysterious duration of 10µs.

Another thing is about my ss/cs signal: 

   

Yellow : LED0

Blue : CC/SS

Pink : SCK

We can see from the clock signal, SCK that  I need only around 2µs to get the response from the slave, However, my CS/SS signal is around 7µs, therefore preventing me to go faster for my sampling rate, is there any way to reduce this duration too ?

I have tried to use a Timer to reduce this duration, my timer is set at 2µs, every 2µs, I enter the timer_handler to send my sixteen-bit words to my slave by using nrf_drv_spi_transfer , hoping that this can reduce the duration of the function nrf_drv_spi_transfer. However the timer doesn't help, on my oscilloscope, I have always the duration of high state of my LED0 signal (which indicates the duration of nrf_drv_spi_transfer) at 10µs.

Thank you in advance for your reply.

Kah Hou

  • Hi,

    Can you also give me some info on how much time it takes for your spi event handler to complete? I see that you rely on a rhd_spi_transfer_done flag to be set in the callback function. What other processing is done in that callback handler?

     

    We can see that within 2.33µs, I have already gotten the response from the slave. However LED0 is still at high level indicating that I am still inside the function nrf_drv_spi_transfer for another 7µs, I would like to know what is the function nrf_drv_spi_transfer waiting for ? Can I reduce this duration ?

    If my math is correct, one CPU instruction on a 64MHz clocked system takes about 15.625 nano second to execute. So in 7 us it can execute 448 instruction. This is not such a big number for the post processing after nrf_spim_task_trigger is called. Maybe you want to fine tune the driver and optimize it even more for your need?

Related