Zephyr or NRF SPI Driver

Hello,

The NRF world is still totally new to me and I'm currently working my way into it for a project.

I use the nRF Connect SDK. I use the SPI interface on an nRF52 to receive BiSS from an encoder. In the first step, I used the Zephyr SPI API after an example. This one causes me several problems, especially when debugging. I guess the Zephyr SPI uses bitbang. Do I see it right that I can also use a NRFX_SPIM driver instead? Does this offer more features than the Zephyr driver? How I can change?

  • Hi,

    How did you configure your project?

    Zephyr does have a bitbang SPI driver, but the default should be the "normal" SPI driver which is based on our nrfx driver.

    We have an old guide that amongst other things explains how the Zephyr drivers are built up:  nRF Connect SDK Tutorial series - Part 0 | NCS v1.5.0 (part 3 is the one talking about the drivers)

    The guide is written for a quite old version of the nRF Connect SDK, so not everything will work in the newer versions, but the concepts should still be the same.

    A more recent sample on how to use Zephyr's SPI driver, from another of my colleagues, can be found here: https://github.com/too1/ncs-spi-master-slave-example

    Do I see it right that I can also use a NRFX_SPIM driver instead?

    Yes, you can use the nrfx driver directly. See zephyr\samples\boards\nrf\nrfx for a sample on how to use the nrfx drivers directly. For a sample showing how to use the nrfx SPIM driver, you can look at modules\hal\nordic\nrfx\samples\src\nrfx_spim.

    Does this offer more features than the Zephyr driver?

    Using the nrfx drivers can give you a bit more low level control, and will let you use DMA and PPI more properly.

    Best regards,

    Didrik

  • Hi,

    thank you very much for your reply. I have now indeed got the nrfx driver running via Zephyr SPI API. But this raises a new question for me: the API of Zephyr's SPI drivers allows to specify an arbitrary clock rate. But when I study the documentation of NRFX SPIM, I find there only a lot of predefined fixed clock rates. But this means that I can only specify these clock rates when configuring the Zephyr SPI API for error-free operation?

    Best regards,
    Torsten

  • The driver will round down to the nearest supported clock frequency.

    So the peripheral should work no matter what frequency you write, though it might use a different frequency.

  • Many thanks for this information.It would be good to include this info in the nRF Connect SDK documentation. For example, I have to control a device that has a minimum speed and for this reason had not worked with the set clock because it was rounded down.

Related