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

SPI CS not toggled during transfer

Hello,

I want to connect one board trough SPI to my nRF51-DK. Using SDK11 and SD130, the nRF51-DK is the SPI master, I call the function nrf_drv_spi_transfer() but the CS Pin is never toggled. To solve this I changed it manually before and after the transfer, but this is not a good solution. I dug into the functions and discovered that this should be done automatically by this part of the code (from what I understood):

    if (p_cb->ss_pin != NRF_DRV_SPI_PIN_NOT_USED)
    {
        nrf_gpio_pin_clear(p_cb->ss_pin);
    }

and after the transfer

    if (p_cb->ss_pin != NRF_DRV_SPI_PIN_NOT_USED)
    {
       nrf_gpio_pin_set(p_cb->ss_pin);
    }

The NRF_DRV_SPI_PIN_NOT_USEDis defined as 0xFF, do I need to change it? Is there any other way to do this?

Thank you for the help,

Jorge Costa

  • Do you need to change what? 0xFF is the correct define for an unused pin (unused pins in registers are usually 0xFFFFFFFF so this is just the last 8 bits). What do you have your ss_pin configured to, if it's not 0xFF then that piece of code will be executed and the pin will toggle low. What are you seeing different?

  • The pin selected now it's the pin 3, but I already tried others with same results. What happens is that the CS pin just goes low and goes back to high right after. So my slave can't send or receive anything because the CS is always high when the CLK is active. I can't debug on the nRF side because I need an external supply of 2 V to be able to connect to the other board. So I'm measuring the signals with an oscilloscope and there I can see that the behavior of the CS pin isn't correct. Can't understand why is not clearing the CS pin for the duration of the CLK.

  • Where is this code you're seeing, because I'm looking at the driver in my directory and it correctly clears the pin

    if (p_cb->ss_pin != NRF_DRV_SPI_PIN_NOT_USED)
    {
        nrf_gpio_pin_clear(p_cb->ss_pin);
    }
    

    I don't see a line like you have above, it looks to me like the clear, which is correct, was commented out and replaced with a set.

    So what exact line of what file are you looking at and you might want to redownload the SDK and check the code didn't get changed by mistake.

  • The code I putted is not as it is on the SDK, I have first the code you putted and after, on the end of the transfer, with the same code but with the set of the pin. the "/" represented that I have the two codes but with that difference. I will change on the question.

  • well that code looks fine - it clears the pin at the start of the transaction and sets it again at the end, which is what it ought to do. It's going to bounce pretty quickly between the two states because the transfers aren't very long.

Related