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

What's the official way to implement a simple peripheral (SPI, I2C, etc) with NCS?

Hi there,

I'm struggling to find straight forward peripheral interface documentation for an NCS project.  I see there's something called nrfx (https://github.com/NordicSemiconductor/nrfx) and also Zephyr has peripheral APIs (https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/reference/peripherals/index.html).  Which is correct?  

For nrfx, I don't see any examples of usage of this.  For Zephyr APIs, how do I configure them?

Thanks

Parents Reply Children
  • I'm sorry for giving you a very general answer initially. I'll try to be more concrete now.

    The samples in ncs/zephyr/samples/drivers are samples that uses the API of the peripherals (SPI, I2C etc..) directly. They use the API ncs/zephyr/include/drivers/<peripheral>.h. Looking at theses samples may give you an understanding of how to use a peripheral.

    However, these are generic examples, and you also need to enable and configure the specific peripheral in the device tree, by adding an overlay file <board name>.overlay to the sample. I could probably give you a lot of more explanations but I think it's better to just provide you with some samples so you can see how it's done:

    I2C

    SPI

    • In this reply, you'll see an SPI loopback sample for NCS v1.4.1. Add an overlay file for your particular board and connect the mosi pin to the miso pin together, and the sample will communicate with itself
    • In this reply are two more SPI samples. One SPI slave (spis_thread_test.zip) and one SPI master (7585.spi_test.zip). Build and program these samples to two different boards and connect them together.

    If you are interested in using a specific sensor, you should take a look at the samples in  ncs/zephyr/samples/sensor and see if you can find your sensor there. It adds a layer on top of the peripheral API by using the API/drivers in ncs/zephyr/drivers/sensor. It will save you a lot of work, and datasheet-reading. Check out the guide 1.2 Walkthrough for BME280 for instructions how to use these samples for a particular board.

    Best regards,

    Simon

  • Hi Simon,

    This worked well.  Thanks for your help and apologies about my impatience, I now understand a bit better how the Zephyr framework works.

Related