<?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>nRF Connect SDK SPI Device Setup And Use on nRF5340-dk</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/97748/nrf-connect-sdk-spi-device-setup-and-use-on-nrf5340-dk</link><description>I&amp;#39;ve went through the Nordic Academy and finished the course, am now trying to continue in learning by using the SPI peripheral. There don&amp;#39;t seem to be many examples that contain the the level of info I am looking for. I&amp;#39;m not trying anything fancy yet</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 16 Mar 2023 17:05:14 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/97748/nrf-connect-sdk-spi-device-setup-and-use-on-nrf5340-dk" /><item><title>RE: nRF Connect SDK SPI Device Setup And Use on nRF5340-dk</title><link>https://devzone.nordicsemi.com/thread/415806?ContentTypeID=1</link><pubDate>Thu, 16 Mar 2023 17:05:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a04edbe1-301e-4967-bce7-0293f7da4e6e</guid><dc:creator>nordicator_prim3</dc:creator><description>&lt;p&gt;Okay, I gotcha now. I would check out the sample for the ICM42605 sensor.&lt;/p&gt;
&lt;p&gt;You won&amp;#39;t have to worry at all about the bus itself outside of the driver. The driver finds the bus device with SPI_DT_SPEC_INST_GET&amp;nbsp; and attaches it to your sensor or what have you. For example, here&amp;#39;s code from the ICM42605 driver:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define ICM42605_DEFINE_CONFIG(index)					\
	static const struct icm42605_config icm42605_cfg_##index = {	\
		.spi = SPI_DT_SPEC_INST_GET(index,			\
					    SPI_OP_MODE_MASTER |	\
					    SPI_MODE_CPOL |		\
					    SPI_MODE_CPHA |		\
					    SPI_WORD_SET(8) |		\
					    SPI_TRANSFER_MSB,		\
					    0U),			\
		.gpio_int = GPIO_DT_SPEC_INST_GET(index, int_gpios),    \
		.accel_hz = DT_INST_PROP(index, accel_hz),		\
		.gyro_hz = DT_INST_PROP(index, gyro_hz),		\
		.accel_fs = DT_INST_ENUM_IDX(index, accel_fs),		\
		.gyro_fs = DT_INST_ENUM_IDX(index, gyro_fs),		\
	}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;So when you want to talk to that sensor, the driver says:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;result = inv_spi_read(&amp;amp;cfg-&amp;gt;spi, REG_FIFO_DATA, drv_data-&amp;gt;fifo_data, fifo_count);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;which you can see is using the &amp;quot;spi&amp;quot; value that was defined with SPI_DT_SPEC_INST_GET.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;All of this code should happen in the driver so you shouldn&amp;#39;t have to worry about it in your actual application code. So if you look at the sample for that sensor (no longer in the driver) you talk with the sensor through an API and don&amp;#39;t have to worry about the nitty gritty of spi communication:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;const char *const label = DT_LABEL(DT_INST(0, invensense_icm42605));
const struct device *icm42605 = device_get_binding(label);

struct sensor_value temperature;
struct sensor_value accel[3];
struct sensor_value gyro[3];
int rc = sensor_sample_fetch(icm42605);

if (rc == 0) {
	rc = sensor_channel_get(dev, SENSOR_CHAN_ACCEL_XYZ, accel);
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF Connect SDK SPI Device Setup And Use on nRF5340-dk</title><link>https://devzone.nordicsemi.com/thread/415803?ContentTypeID=1</link><pubDate>Thu, 16 Mar 2023 16:46:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7a098fd6-1cdd-4546-840a-88b41f1d3473</guid><dc:creator>tayspen72</dc:creator><description>&lt;p&gt;Thanks for the reply.&lt;/p&gt;
&lt;p&gt;I should clarify that this main.c is obviously incomplete. I&amp;#39;m basically looking to declare the SPI bus as a device that I could then use in the program. I have a handful of SPI modules, none are supported sensors in the zephyr database (and that&amp;#39;s ok, I plan on building the API and manually supporting them. That&amp;#39;s the ultimate goal of the project I&amp;#39;m working on, verifying and testing out each of the modules). So there is no compatible slave device, I just want raw access to the bus.&lt;/p&gt;
&lt;p&gt;From the examples I&amp;#39;ve looked over, I don&amp;#39;t see how the drivers are declaring the bus to be talked over. The best reference I have is from the academy course where it explained how to use the overlay file to define the bus.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I will keep looking through the examples for more SPI examples in the meantime.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF Connect SDK SPI Device Setup And Use on nRF5340-dk</title><link>https://devzone.nordicsemi.com/thread/415791?ContentTypeID=1</link><pubDate>Thu, 16 Mar 2023 16:10:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4ff726d0-73e7-439d-9b71-931b0a358432</guid><dc:creator>nordicator_prim3</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;1. I&amp;#39;m not sure I understand what the program is supposed to do. It looks like you&amp;#39;re wanting to use the spi bus as a master. If so, then what slave device are you using (what physical thing is &amp;quot;spi_module&amp;quot; representing)? I&amp;#39;m not sure that setting the compatible=&amp;quot;spi-device&amp;quot; will accomplish anything. Usually you would set the compatible to something more specific like a sensor (ex. compatible=&amp;quot;invensense,icm42605&amp;quot;). Then if you enabled that sensor through Kconfig, the driver for that sensor would be compiled and that driver would look for that compatible device in the device tree and initialize the device for use.&lt;/p&gt;
&lt;p&gt;2. It&amp;#39;s a bit tedious, but looking through the samples for anything that uses spi is a good way to learn how other people have used it.&lt;/p&gt;
&lt;p&gt;3. Declaring things in the overlay file is not technically necessary (it only is if the driver for that device depends on the information to be there). It gives you a good place to quickly change things and skirts around you having to hardcode those properties in a driver. However, for the use case you&amp;#39;re talking about (where a device had multiple addresses) the dts binding file (the file that defines which properties you can add to an overlay) does not have anywhere to put that extra information and if you didn&amp;#39;t write the driver to expect those extra properties then any extra information in the overlay wouldn&amp;#39;t be functional.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>