<?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>Struggling to use SPI with Zephyr</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/93484/struggling-to-use-spi-with-zephyr</link><description>Hi, 
 really new to the Zephyr stuff and Nordic micros. I&amp;#39;ve been through the dev academy training examples and get how to use GPIO and I2C by getting a pointer to a device structure from the dts file. 
 But I just cannot work out how to do the same for</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 15 Oct 2024 06:54:27 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/93484/struggling-to-use-spi-with-zephyr" /><item><title>RE: Struggling to use SPI with Zephyr</title><link>https://devzone.nordicsemi.com/thread/506229?ContentTypeID=1</link><pubDate>Tue, 15 Oct 2024 06:54:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:843c7334-c2ba-43b9-b448-7837c092ce39</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This thread is quite old, so if you run into any issues, I highly recommend that you open a new thread.&lt;/p&gt;
[quote user="s23"]but I have a question regarding your devicetree overlay for the NRF5340 DK, specifically the code below:[/quote]
&lt;p&gt;reg-my-spi-master is just a name given to a node under the &amp;quot;my_spi_master&amp;quot; device, which in this case is &amp;amp;spi4.&lt;/p&gt;
&lt;p&gt;This is referenced in main.c.&lt;/p&gt;
&lt;p&gt;If you look at parts of the nordic dev academy, especially this section on the i2c, you can see a similar approach when implementing a application specific sensor:&amp;nbsp;&lt;a href="https://academy.nordicsemi.com/courses/nrf-connect-sdk-fundamentals/lessons/lesson-6-serial-com-i2c/topic/i2c-driver/"&gt;https://academy.nordicsemi.com/courses/nrf-connect-sdk-fundamentals/lessons/lesson-6-serial-com-i2c/topic/i2c-driver/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Struggling to use SPI with Zephyr</title><link>https://devzone.nordicsemi.com/thread/505987?ContentTypeID=1</link><pubDate>Sun, 13 Oct 2024 07:07:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c4b8bdca-55c4-4448-b3ca-1c04fd055421</guid><dc:creator>s23</dc:creator><description>&lt;p&gt;Hi ovrebekk&lt;/p&gt;
&lt;p&gt;Apologies for chiming in on this years later, but I have a question regarding your devicetree overlay for the NRF5340 DK, specifically the code below:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;my_spi_master: &amp;amp;spi4 {
	compatible = &amp;quot;nordic,nrf-spim&amp;quot;;
	status = &amp;quot;okay&amp;quot;;
	pinctrl-0 = &amp;lt;&amp;amp;spi_master_default&amp;gt;;
	pinctrl-1 = &amp;lt;&amp;amp;spi_master_sleep&amp;gt;;
	pinctrl-names = &amp;quot;default&amp;quot;, &amp;quot;sleep&amp;quot;;
	cs-gpios = &amp;lt;&amp;amp;gpio0 7 GPIO_ACTIVE_LOW&amp;gt;;
	reg_my_spi_master:  spi-dev-a@0 {
		reg = &amp;lt;0&amp;gt;;
	};
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;What does the following code relate to? I cannot find any reference of&amp;nbsp;&lt;em&gt;&lt;strong&gt;reg_my_spi_master&lt;/strong&gt;&amp;nbsp;&lt;/em&gt;or&amp;nbsp;&lt;em&gt;&lt;em&gt;&lt;/em&gt;&lt;/em&gt;&lt;strong&gt;&lt;em&gt;spi-dev-a?&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/em&gt;Regards&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;em&gt;&lt;/em&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;&lt;em&gt;&amp;nbsp;&lt;/em&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Struggling to use SPI with Zephyr</title><link>https://devzone.nordicsemi.com/thread/394547?ContentTypeID=1</link><pubDate>Mon, 07 Nov 2022 20:28:05 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a9e15561-3d8c-4740-8515-c43c2517bbe8</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Duncan&lt;/p&gt;
&lt;p&gt;Glad I could help. A big thanks to you for pointing out the mistake in the example &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Struggling to use SPI with Zephyr</title><link>https://devzone.nordicsemi.com/thread/394440?ContentTypeID=1</link><pubDate>Mon, 07 Nov 2022 13:28:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:40ac4bc1-afbf-47bb-b2a7-1fe324ffd8a9</guid><dc:creator>DunKCubik</dc:creator><description>&lt;p&gt;Hi ovrebekk,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;thanks for your reply. I&amp;#39;ll check out the update later on. Many thanks for your help, I&amp;#39;m up to speed on SPI now!&lt;/p&gt;
&lt;p&gt;Duncan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Struggling to use SPI with Zephyr</title><link>https://devzone.nordicsemi.com/thread/394419?ContentTypeID=1</link><pubDate>Mon, 07 Nov 2022 12:49:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b695cba6-6e16-498b-ab77-b2a5bcc885b2</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Duncan&lt;/p&gt;
&lt;p&gt;Thanks for the update, it seems I was using the device_is_ready(..) function incorrectly. Most zephyr functions return an int, but this one returns a bool, so I had to change the example a little.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you check out my latest update I have corrected this.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The overlay warnings I can see here also, but they don&amp;#39;t seem to affect the example. I&amp;nbsp;will try to find some time later to look into this.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Struggling to use SPI with Zephyr</title><link>https://devzone.nordicsemi.com/thread/394142?ContentTypeID=1</link><pubDate>Fri, 04 Nov 2022 12:40:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:34cc5219-0ec4-4644-a759-bbf7de0143a5</guid><dc:creator>DunKCubik</dc:creator><description>&lt;p&gt;Hi, got your example to build Ok and I have connected the MISO and MOSI pins between master and slave. My build config is for the nrf52840dk and the overlay file is correctly loaded&lt;/p&gt;
&lt;p&gt;Getting the following from terminal output.&lt;/p&gt;
&lt;p&gt;*** Booting Zephyr OS build v3.1.99-ncs1 ***&lt;br /&gt;SPI master device not ready!&lt;br /&gt;SPI master chip select device not ready!&lt;br /&gt;SPI slave device not ready!&lt;br /&gt;SPI master/slave example started&lt;br /&gt;SPI SLAVE TX: 0x00, 0x00&lt;br /&gt;SPI TX: 0x00, 0x00&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;and this from the overlay file..&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;def-char&lt;/span&gt;&lt;span&gt; = &amp;lt;&lt;/span&gt;&lt;span&gt;0x00&lt;/span&gt;&lt;span&gt;&amp;gt;;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&amp;quot;Property not mentioned in \&amp;quot;nordic,nrf-spi\&amp;quot;&amp;quot;,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;reg_my_spi_master:&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;spi-dev-a&lt;/span&gt;&lt;span&gt;@&lt;/span&gt;&lt;span&gt;0&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&amp;nbsp;&amp;quot;Node spi-dev-a should have \&amp;quot;compatible\&amp;quot; property&amp;quot;,&lt;br /&gt;&amp;nbsp;&amp;quot;Node should only occur on the undefined bus.&amp;quot;,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Any ideas why it&amp;#39;s not working?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Cheers&lt;/p&gt;
&lt;p&gt;Duncan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Struggling to use SPI with Zephyr</title><link>https://devzone.nordicsemi.com/thread/394001?ContentTypeID=1</link><pubDate>Thu, 03 Nov 2022 17:08:59 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3f45bda8-db98-4521-91e5-6eb9913d0d9e</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Duncan&lt;/p&gt;
&lt;p&gt;So glad to hear the example was helpful.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The best of luck with your project &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Struggling to use SPI with Zephyr</title><link>https://devzone.nordicsemi.com/thread/393889?ContentTypeID=1</link><pubDate>Thu, 03 Nov 2022 13:12:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7dd2ccc0-5325-4ce0-8000-3b09c5e8416e</guid><dc:creator>DunKCubik</dc:creator><description>&lt;p&gt;That&amp;#39;s great! Thanks for the example, I have managed to get something working after realising that I needed an overlay file! Your example is really good and I understand it much better now. Thank you so much.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Struggling to use SPI with Zephyr</title><link>https://devzone.nordicsemi.com/thread/393880?ContentTypeID=1</link><pubDate>Thu, 03 Nov 2022 13:02:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:59c21f44-cf59-4c8a-accc-2783421402f8</guid><dc:creator>ovrebekk</dc:creator><description>&lt;p&gt;Hi Duncan&lt;/p&gt;
&lt;p&gt;You could have a look at an SPI master/slave example I made &lt;a href="https://github.com/too1/ncs-spi-master-slave-example"&gt;here&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I believe the issue in your case is&amp;nbsp;the nodelabel. spi0 is the name of the node from the board definition, you should not use this as the label.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Rather I would try something like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// Overlay
my_spi: spi0 {
  // Add properties here 
};

// Source code
struct device *spiDev;  /* SPI device pointer*/
void main(void)
{
    spiDev = DEVICE_DT_GET(DT_NODELABEL(my_spi));
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Best regards&lt;br /&gt;Torbjørn&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>