<?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>Handling multiple slaves on single spi master channel</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/84176/handling-multiple-slaves-on-single-spi-master-channel</link><description>Hi, 
 
 The spi_config structure zephyr provides is as below: Wherein cs is initialized to the chip select pin. In my project I have a requirement to handle 2 slaves which are exactly the same. Herein, how can I manage 2 instances of, same slaves And</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 18 Feb 2022 08:08:03 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/84176/handling-multiple-slaves-on-single-spi-master-channel" /><item><title>RE: Handling multiple slaves on single spi master channel</title><link>https://devzone.nordicsemi.com/thread/353770?ContentTypeID=1</link><pubDate>Fri, 18 Feb 2022 08:08:03 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5483fb6b-9054-4fbd-8f84-a4dc480c8281</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;The host controller limit is set in master side, and the &amp;quot;slave number&amp;quot; will get a number between 0 and what the master side has set to the limit, so the master knows what slave device it is communicating with. You need to set the slave limit to 2 or more on the master side and configure a second SPI setup with another instance, etc. The &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrfx/drivers/spim/index.html"&gt;SPIM API reference &lt;/a&gt;should be helpful here.&lt;/p&gt;
&lt;p&gt;Device binding and enabling SPI peripherals should be explained in &lt;a href="https://devzone.nordicsemi.com/nordic/b/archives/posts/nrf-connect-sdk-tutorial---part-3-temporary"&gt;this nRFConnect SDK tutorial&lt;/a&gt;&amp;nbsp;and should give you an idea of&amp;nbsp;how to set up peripherals on the master side.&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: Handling multiple slaves on single spi master channel</title><link>https://devzone.nordicsemi.com/thread/353505?ContentTypeID=1</link><pubDate>Thu, 17 Feb 2022 06:38:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:496682f0-9380-4d9d-b70e-db7d21efef0c</guid><dc:creator>Ubaid_M</dc:creator><description>&lt;p&gt;Hello&amp;nbsp;&lt;a class="internal-link view-user-profile" href="https://devzone.nordicsemi.com/members/simonr"&gt;Simonr&lt;/a&gt;,&lt;/p&gt;
[quote userid="75734" url="~/f/nordic-q-a/84176/handling-multiple-slaves-on-single-spi-master-channel/352674#352674"]checking out the SPI test and SPIS test[/quote]
&lt;p&gt;I referred to Sigurd&amp;#39;s upload and it does have slave code.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;But what I want to know is, in SPI config structure:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**
 * @brief SPI controller configuration structure
 *
 * @param frequency is the bus frequency in Hertz
 * @param operation is a bit field with the following parts:
 *
 *     operational mode    [ 0 ]       - master or slave.
 *     mode                [ 1 : 3 ]   - Polarity, phase and loop mode.
 *     transfer            [ 4 ]       - LSB or MSB first.
 *     word_size           [ 5 : 10 ]  - Size of a data frame in bits.
 *     lines               [ 11 : 12 ] - MISO lines: Single/Dual/Quad/Octal.
 *     cs_hold             [ 13 ]      - Hold on the CS line if possible.
 *     lock_on             [ 14 ]      - Keep resource locked for the caller.
 *     cs_active_high      [ 15 ]      - Active high CS logic.
 * @param slave is the slave number from 0 to host controller slave limit.
 * @param cs is a valid pointer on a struct spi_cs_control is CS line is
 *    emulated through a gpio line, or NULL otherwise.
 *
 * @note Only cs_hold and lock_on can be changed between consecutive
 * transceive call. Rest of the attributes are not meant to be tweaked.
 *
 * @warning Most drivers use pointer comparison to determine whether a
 * passed configuration is different from one used in a previous
 * transaction.  Changes to fields in the structure may not be
 * detected.
 */
struct spi_config {
	uint32_t		frequency;
	uint16_t		operation;
	uint16_t		slave;

	const struct spi_cs_control *cs;
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;What does &amp;quot;&lt;span&gt;@param&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;slave&lt;/span&gt;&lt;span&gt; is the slave number from 0 to host controller slave limit.&amp;quot; mean..?&lt;br /&gt;If i set slave as 2,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;&lt;em&gt;&lt;strong&gt;From code how do I operate master to work on 2 slaves..?&lt;/strong&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;&lt;em&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;/em&gt;In dts as in below:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;amp;spi3 {
	compatible = &amp;quot;nordic,nrf-spim&amp;quot;;
	status = &amp;quot;okay&amp;quot;;
	sck-pin = &amp;lt;3&amp;gt;;
	mosi-pin = &amp;lt;4&amp;gt;;
	miso-pin = &amp;lt;5&amp;gt;;
	cs-gpios = &amp;lt;&amp;amp;gpio0 8 GPIO_ACTIVE_LOW&amp;gt;, &amp;lt;&amp;amp;gpio0 7 GPIO_ACTIVE_LOW&amp;gt;;

	adxl362@0 {
		compatible = &amp;quot;adi,adxl362&amp;quot;;
		label = &amp;quot;ADXL362&amp;quot;;
		spi-max-frequency = &amp;lt;8000000&amp;gt;;
		reg = &amp;lt;0&amp;gt;;
		int1-gpios = &amp;lt;&amp;amp;gpio0 9 0&amp;gt;;
	};

	adxl372@1 {
		compatible = &amp;quot;adi,adxl372&amp;quot;;
		label = &amp;quot;ADXL372&amp;quot;;
		spi-max-frequency = &amp;lt;8000000&amp;gt;;
		reg = &amp;lt;1&amp;gt;;
		int1-gpios = &amp;lt;&amp;amp;gpio0 6 0&amp;gt;;
	}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;To send data to&amp;nbsp;&amp;lt;&amp;amp;gpio0 8 GPIO_ACTIVE_LOW&amp;gt;, how would my device_binding &amp;amp; spi_cfg look like before I call spi_transceive..?&lt;/p&gt;
&lt;p&gt;&lt;span&gt;To send data to&amp;nbsp;&lt;/span&gt;&amp;lt;&amp;amp;gpio0 7 GPIO_ACTIVE_LOW&amp;gt;&lt;span&gt;, how would my device_binding &amp;amp; spi_cfg look like before I call spi_transceive..?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Ubaid&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Handling multiple slaves on single spi master channel</title><link>https://devzone.nordicsemi.com/thread/352674?ContentTypeID=1</link><pubDate>Fri, 11 Feb 2022 14:26:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9bcae071-ea91-4a6b-a050-00da6de539d6</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I would suggest checking out the SPI test and SPIS test example projects my colleague Sigurd has uploaded to his &lt;a href="https://github.com/sigurdnev/ncs-playground/tree/master/samples/"&gt;GitHub here&lt;/a&gt;. You should get an idea on how to set up SPI slaves and masters correctly from those.&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: Handling multiple slaves on single spi master channel</title><link>https://devzone.nordicsemi.com/thread/352475?ContentTypeID=1</link><pubDate>Fri, 11 Feb 2022 06:55:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cf51f738-0ed7-4cb1-adae-04aa309b1d14</guid><dc:creator>Ubaid_M</dc:creator><description>&lt;p&gt;Hello&amp;nbsp;&lt;a class="internal-link view-user-profile" href="https://devzone.nordicsemi.com/members/simonr"&gt;Simonr&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you for the info,&lt;br /&gt;Noted on the dts syntax for multiple slaves.&lt;/p&gt;
&lt;p&gt;Kindly suggest how this can be handled in code, if i want to call &amp;quot;SPI_Write()&amp;quot; on:&lt;/p&gt;
&lt;p&gt;1. slave one&amp;nbsp;&amp;lt;&amp;amp;gpio0 8 GPIO_ACTIVE_LOW&amp;gt;&lt;/p&gt;
&lt;p&gt;2. slave two &amp;lt;&amp;amp;gpio0 7 GPIO_ACTIVE_LOW&amp;gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;What would the code syntax look like..?&lt;/p&gt;
&lt;p&gt;How would I configure &lt;strong&gt;spi_config&lt;/strong&gt;..?&lt;/p&gt;
&lt;p&gt;and how would I call&amp;nbsp;&lt;span&gt;&amp;nbsp;&amp;quot;SPI_Write()&amp;quot; on each slave.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks,&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Handling multiple slaves on single spi master channel</title><link>https://devzone.nordicsemi.com/thread/350467?ContentTypeID=1</link><pubDate>Mon, 31 Jan 2022 14:43:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a8d184fa-4d6d-4ee5-8b88-63b99315d709</guid><dc:creator>sipan112</dc:creator><description>&lt;p&gt;&lt;span&gt;The standard, most common, and obvious way to handle multiple SPI slaves is for&lt;/span&gt;&lt;strong&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;each to have its own slave select line&lt;/strong&gt;&lt;span&gt;. That&amp;#39;s precisely what they are for. You wire the MOSI, SCK, and MISO lines altogether, then each slave gets its own slave select line.&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Handling multiple slaves on single spi master channel</title><link>https://devzone.nordicsemi.com/thread/350453?ContentTypeID=1</link><pubDate>Mon, 31 Jan 2022 14:06:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c34f7cf3-a9d0-4d31-9b70-2406e99a730f</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;For SPI devices, &amp;quot;@0 or @1&amp;quot; refers to the position of the chip select pin in the cs-gpios configuration. As you can see in the config below from the Thingy91.dts file, the SPI devices are defined to use one CS pin each.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;amp;spi3 {
	compatible = &amp;quot;nordic,nrf-spim&amp;quot;;
	status = &amp;quot;okay&amp;quot;;
	sck-pin = &amp;lt;3&amp;gt;;
	mosi-pin = &amp;lt;4&amp;gt;;
	miso-pin = &amp;lt;5&amp;gt;;
	cs-gpios = &amp;lt;&amp;amp;gpio0 8 GPIO_ACTIVE_LOW&amp;gt;, &amp;lt;&amp;amp;gpio0 7 GPIO_ACTIVE_LOW&amp;gt;;

	adxl362@0 {
		compatible = &amp;quot;adi,adxl362&amp;quot;;
		label = &amp;quot;ADXL362&amp;quot;;
		spi-max-frequency = &amp;lt;8000000&amp;gt;;
		reg = &amp;lt;0&amp;gt;;
		int1-gpios = &amp;lt;&amp;amp;gpio0 9 0&amp;gt;;
	};

	adxl372@1 {
		compatible = &amp;quot;adi,adxl372&amp;quot;;
		label = &amp;quot;ADXL372&amp;quot;;
		spi-max-frequency = &amp;lt;8000000&amp;gt;;
		reg = &amp;lt;1&amp;gt;;
		int1-gpios = &amp;lt;&amp;amp;gpio0 6 0&amp;gt;;
	};
};&lt;/pre&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: Handling multiple slaves on single spi master channel</title><link>https://devzone.nordicsemi.com/thread/350326?ContentTypeID=1</link><pubDate>Sun, 30 Jan 2022 12:34:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0cb24107-185c-4242-bbab-6719a29dc9be</guid><dc:creator>Ubaid_M</dc:creator><description>&lt;p&gt;Hello&amp;nbsp;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;a class="internal-link view-user-profile" href="https://devzone.nordicsemi.com/members/simonr"&gt;Simonr&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks for the info,&amp;nbsp;&lt;/p&gt;
[quote userid="75734" url="~/f/nordic-q-a/84176/handling-multiple-slaves-on-single-spi-master-channel/350235#350235"] you should make multiple structs with different CS pin inits that can be called from the SPI write/read functions so you easily can switch between what devices you&amp;#39;d like to handle.[/quote]
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I am more interested in the dts/overlay file&amp;#39;s way of using multiple cs:&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;amp;spi1 {
	compatible = &amp;quot;nordic,nrf-spim&amp;quot;;
	status = &amp;quot;okay&amp;quot;;
	sck-pin = &amp;lt;41&amp;gt;;
	mosi-pin = &amp;lt;40&amp;gt;;
	miso-pin = &amp;lt;4&amp;gt;;
	cs-gpios = &amp;lt;&amp;amp;gpio0 22 0xff&amp;gt;,&amp;lt;&amp;amp;gpio0 23 0xff&amp;gt;;
};&lt;/pre&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As in this code snippet, &amp;quot;cs-gpios&amp;quot; node is assigned to multiple cs pins,&lt;br /&gt;I want to know how this is handled in the code to switch between slaves.&lt;/p&gt;
&lt;p&gt;Kindly suggest.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Handling multiple slaves on single spi master channel</title><link>https://devzone.nordicsemi.com/thread/350235?ContentTypeID=1</link><pubDate>Fri, 28 Jan 2022 14:17:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c3adca93-62ab-4f71-b9a4-410805321d22</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi Ubaid&lt;/p&gt;
&lt;p&gt;This should indeed be possible. In order to have one SPI(M) instance handle multiple slaves, you should make multiple structs with different CS pin inits that can be called from the SPI write/read functions so you easily can switch between what devices you&amp;#39;d like to handle.&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></channel></rss>