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
  • I'm still struggling with this.  I'm using the nRF52840dk and it seems to be "kind of" supported.  I find myself piecing together how to do this from forum posts and disparate documentation.  Honestly this is strange, why can't I just go to one set of documentation that describes the libraries needed and how to use them?  Why is so much of the NCS "documentation" actually just obfuscated examples that I need to reverse engineer?  I feel like I should just be able to #include a header file and do straight forward established I2C functions.

  • Do I look at NCS docs?  Zephyr docs?  nrfx, the old softdevices?  This is not clear.

  • 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

Reply
  • 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

Children
Related