<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>What&amp;#39;s the official way to implement a simple peripheral (SPI, I2C, etc) with NCS?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/70627/what-s-the-official-way-to-implement-a-simple-peripheral-spi-i2c-etc-with-ncs</link><description>Hi there, 
 I&amp;#39;m struggling to find straight forward peripheral interface documentation for an NCS project. I see there&amp;#39;s something called nrfx ( https://github.com/NordicSemiconductor/nrfx) and also Zephyr has peripheral APIs ( https://developer.nordicsemi</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Sun, 24 Jan 2021 01:48:07 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/70627/what-s-the-official-way-to-implement-a-simple-peripheral-spi-i2c-etc-with-ncs" /><item><title>RE: What's the official way to implement a simple peripheral (SPI, I2C, etc) with NCS?</title><link>https://devzone.nordicsemi.com/thread/290864?ContentTypeID=1</link><pubDate>Sun, 24 Jan 2021 01:48:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:acabe7e9-6279-4083-9b32-59f2f6d37cfc</guid><dc:creator>crasspm</dc:creator><description>&lt;p&gt;Hi Simon,&lt;/p&gt;
&lt;p&gt;This worked well.&amp;nbsp; Thanks for your help and apologies about my impatience, I now understand a bit better how the Zephyr framework works.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What's the official way to implement a simple peripheral (SPI, I2C, etc) with NCS?</title><link>https://devzone.nordicsemi.com/thread/290629?ContentTypeID=1</link><pubDate>Fri, 22 Jan 2021 01:22:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a6fb6491-dd2a-4623-ba6f-8e39b97d17b3</guid><dc:creator>crasspm</dc:creator><description>&lt;p&gt;Thanks Simon, I&amp;#39;ll try this now.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What's the official way to implement a simple peripheral (SPI, I2C, etc) with NCS?</title><link>https://devzone.nordicsemi.com/thread/290615?ContentTypeID=1</link><pubDate>Thu, 21 Jan 2021 20:13:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:72e3fcdc-2cae-4c27-ba33-2d51a587ed94</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I&amp;#39;m sorry for giving you a very general answer initially. I&amp;#39;ll try to be more concrete now.&lt;/p&gt;
&lt;p&gt;The samples in &lt;a href="https://github.com/nrfconnect/sdk-zephyr/tree/v2.4.0-ncs1/samples/drivers"&gt;ncs/zephyr/samples/drivers&lt;/a&gt;&amp;nbsp;are samples that uses the API of the peripherals (SPI, I2C etc..) directly. They use the API ncs/zephyr/include/drivers/&amp;lt;peripheral&amp;gt;.h. Looking at theses samples may give you an understanding of how to use a peripheral.&lt;/p&gt;
&lt;p&gt;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&amp;nbsp;&amp;lt;board name&amp;gt;.overlay to the sample. I could probably give you a lot of more explanations but I think it&amp;#39;s better to just provide you with some samples so you can see how it&amp;#39;s done:&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;I2C&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/crfosse/ncs_projects/tree/main/peripheral_zephyr/i2c"&gt;https://github.com/crfosse/ncs_projects/tree/main/peripheral_zephyr/i2c&lt;/a&gt;&amp;nbsp;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;This is an I2C scanner sample for NCS v1.4.1. You can connect a sensor with I2C interface and it will find its address&lt;/li&gt;
&lt;li&gt;This sample supports both nrf5340pdk as well as nrf9160dk, since there are added overlay files for these boards&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;SPI&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/70104/spi-master-is-broken-in-sdk-v1-4-x/288074#288074"&gt;this reply&lt;/a&gt;, you&amp;#39;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&lt;/li&gt;
&lt;li&gt;In &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/70104/spi-master-is-broken-in-sdk-v1-4-x/288816#288816"&gt;this reply&lt;/a&gt;&amp;nbsp;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.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr /&gt;
&lt;p&gt;If you are interested in using a specific sensor, you should take a look at the samples in&amp;nbsp; &lt;a href="https://github.com/nrfconnect/sdk-zephyr/tree/master/samples/sensor"&gt;ncs/zephyr/samples/sensor&lt;/a&gt;&amp;nbsp;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&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/tree/master/drivers/sensor"&gt;ncs/zephyr/drivers/sensor&lt;/a&gt;. It will save you a lot of work, and datasheet-reading. Check out the guide&amp;nbsp;&lt;span&gt;&lt;a href="https://devzone.nordicsemi.com/nordic/nrf-connect-sdk-guides/b/getting-started/posts/nrf-connect-sdk-tutorial---part-3-ncs-v1-4-0#h79sk0f70607qwcyitkx2xn61bmh9mo"&gt;1.2 Walkthrough for BME280&lt;/a&gt;&amp;nbsp;for instructions how to use these samples for a particular board.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Simon&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What's the official way to implement a simple peripheral (SPI, I2C, etc) with NCS?</title><link>https://devzone.nordicsemi.com/thread/290604?ContentTypeID=1</link><pubDate>Thu, 21 Jan 2021 18:10:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a7c9fd3a-ede9-4c45-a839-c3719acfe329</guid><dc:creator>crasspm</dc:creator><description>&lt;p&gt;Do I look at NCS docs?&amp;nbsp; Zephyr docs?&amp;nbsp; nrfx, the old softdevices?&amp;nbsp; This is not clear.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What's the official way to implement a simple peripheral (SPI, I2C, etc) with NCS?</title><link>https://devzone.nordicsemi.com/thread/290603?ContentTypeID=1</link><pubDate>Thu, 21 Jan 2021 18:08:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a705e832-e98c-4363-aa36-6c3f60f767f9</guid><dc:creator>crasspm</dc:creator><description>&lt;p&gt;I&amp;#39;m still struggling with this.&amp;nbsp; I&amp;#39;m using the nRF52840dk and it seems to be &amp;quot;kind of&amp;quot; supported.&amp;nbsp; I find myself piecing together how to do this from forum posts and disparate documentation.&amp;nbsp; Honestly this is strange, why can&amp;#39;t I just go to one set of documentation that describes the libraries needed and how to use them?&amp;nbsp; Why is so much of the NCS &amp;quot;documentation&amp;quot; actually just obfuscated examples that I need to reverse engineer?&amp;nbsp; I feel like I should just be able to #include a header file and do straight forward established I2C functions.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What's the official way to implement a simple peripheral (SPI, I2C, etc) with NCS?</title><link>https://devzone.nordicsemi.com/thread/290247?ContentTypeID=1</link><pubDate>Wed, 20 Jan 2021 12:51:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3062025e-472b-499e-b804-ccb173ebae51</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;If you would like&amp;nbsp;to fully utilize all the advantages Zephyr brings with it, I would recommend you to use the Zephyr API. In Zephyr you use Kconfigs (through prj.conf) and&amp;nbsp;the device tree/dts (through overlay files)&lt;span&gt;&amp;nbsp;&lt;/span&gt;to set up a project,&lt;span&gt;&amp;nbsp;&lt;/span&gt;read more about this in&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a href="https://devzone.nordicsemi.com/nordic/nrf-connect-sdk-guides/b/getting-started/posts/nrf-connect-sdk-tutorial---part-2-ncs-v1-4-0#h8sjwm52udufgrtwj106y8lkrgs7n2"&gt;1.&amp;nbsp;Concepts in NCS&lt;/a&gt;. If you use the nrfx layer, the stuff you&amp;#39;ve set in prj.conf and overlay files (and all the other Kconfig and dts files) will not be seen. Using the Zephyr API makes it quicker and easier to set up a project (Given that everything works as expected and you have a good intuitive understanding of how the SDK&amp;nbsp;works). There might be more advantages of using the Zephyr API that I have missed, but this is what I though of right now.&lt;/p&gt;
&lt;p&gt;Some developers likes to have more control over what they&amp;#39;re doing, with less abstractions from the hardware, then the nrfx drivers might be a better option.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;From my point of view, I would recommend you to use the Zephyr API, as it will reduce the development time, make the application more&amp;nbsp;scalable/portable/cross-compatible&amp;nbsp;and reduce the amount of code you write (less chances of bugs). I don&amp;#39;t have a complete overview of this, so if anyone could prove me wrong on any of these points, I would be more than happy.&lt;/p&gt;
&lt;p&gt;Since NCS/Zephyr is still quite new, there are circumstances where the nrfx layer has to be used. E.g. if you want to use I2S with Zephyr, you have to use the nrfx drivers, since it&amp;#39;s not supported on the top layer (I think there is on-going work right on this right now).&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/shaney"&gt;Shaney&lt;/a&gt; is correct in that the Zephyr API uses the nrfx drivers. The figure below (from &lt;a href="https://devzone.nordicsemi.com/nordic/nrf-connect-sdk-guides/b/getting-started/posts/nrf-connect-sdk-tutorial---part-3-ncs-v1-4-0"&gt;NCS tutorial part 3&lt;/a&gt;) might give you an overview of how it works:&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/2084.pastedimage1598696054963v1.png" /&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What's the official way to implement a simple peripheral (SPI, I2C, etc) with NCS?</title><link>https://devzone.nordicsemi.com/thread/290096?ContentTypeID=1</link><pubDate>Wed, 20 Jan 2021 02:05:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ddb9a930-b524-48b4-9b42-376bce6ead02</guid><dc:creator>crasspm</dc:creator><description>&lt;p&gt;Thanks &lt;a href="https://devzone.nordicsemi.com/members/shaney"&gt;Shaney&lt;/a&gt;.&amp;nbsp; Hopefully we can get a Nordic engineer to see this and give us some guidance.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What's the official way to implement a simple peripheral (SPI, I2C, etc) with NCS?</title><link>https://devzone.nordicsemi.com/thread/289913?ContentTypeID=1</link><pubDate>Tue, 19 Jan 2021 06:33:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a88b39f7-7108-4257-852f-48b922bcac69</guid><dc:creator>Shaney</dc:creator><description>&lt;p&gt;As far as I know, the Zephyr API uses the the nrfx HAL as can be seen in &lt;a href="https://github.com/zephyrproject-rtos/zephyr/blob/master/drivers/spi/spi_nrfx_spim.c"&gt;https://github.com/zephyrproject-rtos/zephyr/blob/master/drivers/spi/spi_nrfx_spim.c&lt;/a&gt; for example. These functions (as well as other drivers) are the once that are called from the api-&amp;gt;dostuff() function calls in the Zephyr drivers.&lt;/p&gt;
&lt;p&gt;If I understood correctly, when you enable perihperals in the Kconfig you choose which underlying driver that gets called from the Zephyr API. I guess using Zephyr API makes your project more easy to port if you switch MCU in the future.&lt;br /&gt;&lt;br /&gt;I personally try to use the Zephyr API as much as possible to try to keep the code as coherent as possible. One drawback of this is that there is not 100% clear what is happening configuration wise with the perihperals and you need to manually check the drivers to see what Zephyr does when it sets up everything.&lt;/p&gt;
&lt;p&gt;However, I am wondering, same as you, which method is the &amp;quot;correct&amp;quot; one according to nordic since I&amp;#39;ve seen on Devzone that several people use the nrfx functions directly instead of the Zephyr one. I guess it is a convenice vs control issue.&lt;br /&gt;&lt;br /&gt;Would be nice to have an official answer from a Nordic rep about the subject. Will NCS diverge more from Zephyr in the future?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>