<?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 read from accelerometer using SPI driver directly</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/90687/nrf-connect-read-from-accelerometer-using-spi-driver-directly</link><description>Hi, I&amp;#39;m trying to port my NRF SDK15.3 application to NRF Connect. I made a custom board for my PCB and I can control the LEDs with PWM etc. Now I&amp;#39;d like to read data from my SPI connected accelerometer. 
 It&amp;#39;s an LIS2DW12. In the Developer academy there</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 05 Aug 2022 11:13:43 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/90687/nrf-connect-read-from-accelerometer-using-spi-driver-directly" /><item><title>RE: NRF Connect read from accelerometer using SPI driver directly</title><link>https://devzone.nordicsemi.com/thread/380347?ContentTypeID=1</link><pubDate>Fri, 05 Aug 2022 11:13:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:32986038-9d93-4f4c-be77-dae05393e005</guid><dc:creator>Albrecht Markus Schellenberger</dc:creator><description>[quote user="JasonR"]I&amp;#39;ve changed my code to use the pinctrl THANKS again!&amp;nbsp;[/quote]
&lt;p&gt;&lt;span&gt;My pleasure, Jason! I’m glad to hear that you are making progress.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
[quote user="JasonR"]It&amp;#39;s a useful example but it needs updated to the latest NCS. There&amp;#39;s deprecation warnings for gpio_dev for example[/quote]
&lt;p&gt;&lt;span&gt;Please note that this is not an official NCS sample and as stated in its requirements, it currently only supports NCS v1.9.1 (-:&lt;/span&gt;&lt;span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;Requirements 

SDK: 

    nRF Connect SDK v1.9.1 

Supported boards: 

    nrf52dk_nrf52832 
    nrf52840dk_nrf52840 
    nrf5340dk_nrf5340_cpuapp &lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
[quote user="JasonR"]I&amp;#39;ve also noticed a discrepancy in the example overlay files which might be a bug.[/quote]
&lt;p&gt;&lt;span&gt;This actually is not a bug. Referring to the &amp;amp;spi1 devicetree of e.g. the nRF52840DK:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;spi1: spi@40004000 {
	compatible = &amp;quot;nordic,nrf-spi&amp;quot;;
	#address-cells = &amp;lt; 0x1 &amp;gt;;
	#size-cells = &amp;lt; 0x0 &amp;gt;;
	reg = &amp;lt; 0x40004000 0x1000 &amp;gt;;
	interrupts = &amp;lt; 0x4 0x1 &amp;gt;;
	status = &amp;quot;okay&amp;quot;;
	label = &amp;quot;SPI_1&amp;quot;;
	pinctrl-0 = &amp;lt; &amp;amp;spi1_default &amp;gt;;
	pinctrl-1 = &amp;lt; &amp;amp;spi1_sleep &amp;gt;;
	pinctrl-names = &amp;quot;default&amp;quot;, &amp;quot;sleep&amp;quot;;
};&lt;/pre&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The nRF53/nRF91 &amp;amp; nRF52 series are using different SPI drivers.&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Cheers,&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Markus&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF Connect read from accelerometer using SPI driver directly</title><link>https://devzone.nordicsemi.com/thread/380340?ContentTypeID=1</link><pubDate>Fri, 05 Aug 2022 10:54:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:26c676a1-7bc7-478b-a11a-5f92729dd944</guid><dc:creator>Jason</dc:creator><description>&lt;p&gt;Thanks Markus!&lt;/p&gt;
&lt;p&gt;I would never have spotted the SPI_OP_MODE_MASTER mistake!&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve changed my code to use the pinctrl THANKS again!&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I prefer not to use the sensor/lis2dw12 supplied with zephyr because I already wrote a driver that I&amp;#39;m familiar with.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve been able to read the WHO_AM_I registter by adapting the &amp;quot;NCS-SPI-Master-Slave-Example&amp;quot; that you linked. So that&amp;#39;s great. I&amp;#39;ll do the rest today I hope,&lt;/p&gt;
&lt;p&gt;It&amp;#39;s a useful example but it needs updated to the latest NCS. There&amp;#39;s deprecation warnings for gpio_dev for example&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;c:\Vigglab\Projects\Doodoody\BTSender_ClipPair\NCS_Firmware\ClipPair\src\LIS2DW12.c:170:3: warning: &amp;#39;gpio_dev&amp;#39; is deprecated [-Wdeprecated-declarations]
  170 |   spim_cs.gpio_dev = device_get_binding(MY_SPI_MASTER_CS_PORT);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve also noticed a discrepancy in the example overlay files which might be a bug.&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/ice_5F00_screenshot_5F00_20220805_2D00_101531.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/ice_5F00_screenshot_5F00_20220805_2D00_101654.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/ice_5F00_screenshot_5F00_20220805_2D00_101854.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Thanks again for your help&lt;/p&gt;
&lt;p&gt;-Jason&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: NRF Connect read from accelerometer using SPI driver directly</title><link>https://devzone.nordicsemi.com/thread/380142?ContentTypeID=1</link><pubDate>Thu, 04 Aug 2022 13:15:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:95401a3b-08c1-4c43-b568-04521c8d02c6</guid><dc:creator>Albrecht Markus Schellenberger</dc:creator><description>&lt;p&gt;&lt;span&gt;Hello Jason,&lt;/span&gt;&lt;span&gt; &lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define SPI0_NODE    DT_NODELABEL(lis2dw12)

void spi_init()
{
     static const struct spi_dt_spec dev_spi = SPI_DT_SPEC_GET(SPI0_NODE, SPI_MODE_MASTER, 0);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;SPI_MODE_MASTER is supposed to be &lt;a href="https://github.com/zephyrproject-rtos/zephyr/blob/zephyr-v3.1.0/include/zephyr/drivers/spi.h#L36"&gt;SPI_OP_MODE_MASTER&lt;/a&gt;.&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;// pinctrl-0 = &amp;lt;&amp;amp;spi1&amp;gt;					//do I need this?
// pinctrl-names = &amp;quot;default&amp;quot;;&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;As a matter of fact, from NCS v2.x.x you do. Referring to the &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.0.0/nrf/migration/migration_guide_1.x_to_2.x.html#pin-control-transition"&gt;Pin control transition&lt;/a&gt; chapter of the nRF Connect SDK v2.0.0 migration notes.&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;reg = &amp;lt;0&amp;gt;;							//what is this?&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Assuming you are configuring the peripheral as a master, this line represents the chip-select / numbering of the slaves, see also &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.0.0/zephyr/hardware/peripherals/spi.html#c.SPI_CS_GPIOS_DT_SPEC_GET"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;compatible = &amp;quot;spi-device&amp;quot;;&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This is not correct and should look like this instead:&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;compatible = &amp;quot;st,lis2dw12&amp;quot;;&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If of interest, you can have a look at this &lt;a href="https://github.com/too1/ncs-spi-master-slave-example"&gt;SPI sample&lt;/a&gt; for your reference.&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Cheers,&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Markus&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>