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

Is there any spis event generated when the slave is selected?

Currently I am using the spis driver to send data through the SPI peripheral. On the event handler I want to capture the time in which the chip is selected, which in the case of my application, is when the 'slave select' signal goes low. Is there any way of doing this? or should I start using the SPIS HAL instead of the SPIS driver? Or maybe the solution would be to connect the chip select pin to a gpio pin and generate an gpioevent to get an interrupt as soon as the slave select signal goes down.

Thank you in advance for your attention,

Kind regards,

  • You mean that nRF52 is SPI slave, right? Have you tried GPIOTE interrupt on that PIN?

  • Yes, I tried putting the same spis_slave select pin on the GPIOTE interrupt configuration but on the initialization it gets restarted. When I change the interrupt pin to a different one, the GPIOTE interrupt works fine. I guess the same pin cannot be used to spi_slave select and also an GPIOTE interrupt.

  • Hello User1321

    I might have misinterpreted your question a bit, but I believe at least parts of my answer might still give you what you need.

    I have used a GPIOTE event on the CS pin, PPI and the Capture task of a timer. I have attached a project, it is based on the SPIS example in SDK 14. I have added timer and PPI defines to sdk_config as well as the necessary .h and .c files. Please note that it is not optimized in any way.

    For my test I used a nRF52832 DK as slave and nRF52840 DK as master. The CS pin generates a GPIOTE event on toggle which triggers the capture task with the timer. The capture values are stored in seperate variables in the CS GPIOTE interrupt, in the gp_evt_handler.

    The slave transmits the difference between timer values back to the master, which displays it in the log in putty.

    The difference value you get is dependent on SPI bit-rate and timer clock rate. In the example the timer is set to 4MHz. The difference variable is a 16 bit value which is transmitted Least significant byte first. The actual time spent with CS low is found by dividing the difference value on the timer clock frequency.

    There is a delay from the time the CS pin falls, until the GPIOTE event handler executes which is roughly 24 us.

    DO NOTE: The timer is simply running free in this example, it is never stopped or cleared in a controlled fashion. If the timer overflows and restarts from zero between CS falling edge and CS rising edge you will get an erronous value.

    Best regards

    Jørn Frøysa

    spis - w timer.zip

Related