This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

SPI with chip select using GPIO in SDK V11.0 not working

Hi,

I am trying to use SPI to get data from a sensor. In nRF 5 SDK V11, I got it to work by setting the SS pin in the config struct of the initialization function.

image description

Now, instead of declaring the chip select in the config structure, I want to use a GPIO pin to achieve the same. I think I am configuring everything correctly but I am not reading the right values. I am getting some garbage values. Here's my main file

image description

SPI initialization function now looks like this

image description

The bmaInit() function involves writing data through SPI and so I pulled it low and back high.

Should be pretty straightforward but I can't seem to get it to work. I read different garbage values in every loop. Am I missing something? I feel there's a problem with timing or with reading the buffers. Appreciate any help! Thanks.

  • Which DK are you using, 51 or 52? Are you using non-blocking spi and do you wait for the transaction to finish before you pull the CS line high? You may want to connect an oscilloscope or logic analyzer to the lines to see what actually happens.

  • Hi Ole,

    I am using 52 dk. I tried both blocking and non-blocking modes and neither of them worked. Is there a flag to check if transaction is complete? Even otherwise I tried having a 10-20 ms delay before pulling the line high which should be enough time for data transfer. I am trying to get a logic analyzer but that's going to take some time and I needed to get this done soon.

    Have you made it work before? If yes, do you have a code that I could try?

  • Since it works with setting the SS pin in the config struct there have to be something wrong with when the chip select signal goes low/high. If you use blocking mode the transfer should be done when the function returns, if you use non-blocking mode the transfer is done when you enter the spi event handler.

    I have not tested with setting/clearing the CS pin manually, but it should be quite simple to test using the spi and spis (for testing the other end) examples in the SDK.

  • I figured out the problem. I was reading from multiple registers without toggling the chip select pin which was creating issues. It works when I toggle the chip select every time I read from a register.

Related