<?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>Confusing how to integrate SPI master and slave drivers/HAL in my C code</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/53090/confusing-how-to-integrate-spi-master-and-slave-drivers-hal-in-my-c-code</link><description>Ok so I am trying to integrate SPI master and slave initialization code. I am very confused about legacy and non-legacy drivers and HAL. I am getting strange compilation and linking errors. Please help me out on this. 
 I am compiling following SPI related</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 11 Oct 2019 05:31:34 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/53090/confusing-how-to-integrate-spi-master-and-slave-drivers-hal-in-my-c-code" /><item><title>RE: Confusing how to integrate SPI master and slave drivers/HAL in my C code</title><link>https://devzone.nordicsemi.com/thread/214491?ContentTypeID=1</link><pubDate>Fri, 11 Oct 2019 05:31:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:7d516ff9-43b5-45e9-a436-4913ac6ca63a</guid><dc:creator>nvj</dc:creator><description>&lt;p&gt;Ok so I fixed the issue.&amp;nbsp;Issue occurs if I associate same device id with both master and slave instances:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define SPI_DEV_ID_0 0


nrfx_spim_t const hSpiMasterDev0 = NRFX_SPIM_INSTANCE(SPI_DEV_ID_0);
nrfx_spis_t const hSpiSlaveDev0 = NRFX_SPIS_INSTANCE(SPI_DEV_ID_0);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;sdk_config.h:&lt;/strong&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// &amp;lt;e&amp;gt; NRFX_SPIM_ENABLED - nrfx_spim - SPIM peripheral driver
//==========================================================
#ifndef NRFX_SPIM_ENABLED
#define NRFX_SPIM_ENABLED 1
#endif
// &amp;lt;q&amp;gt; NRFX_SPIM0_ENABLED  - Enable SPIM0 instance
 

#ifndef NRFX_SPIM0_ENABLED
#define NRFX_SPIM0_ENABLED 1
#endif

// &amp;lt;q&amp;gt; NRFX_SPIM1_ENABLED  - Enable SPIM1 instance
 

#ifndef NRFX_SPIM1_ENABLED
#define NRFX_SPIM1_ENABLED 0
#endif


// &amp;lt;e&amp;gt; NRFX_SPIS_ENABLED - nrfx_spis - SPIS peripheral driver
//==========================================================
#ifndef NRFX_SPIS_ENABLED
#define NRFX_SPIS_ENABLED 1
#endif
// &amp;lt;q&amp;gt; NRFX_SPIS0_ENABLED - Enable SPIS0 instance

#ifndef NRFX_SPIS0_ENABLED
#define NRFX_SPIS0_ENABLED 1
#endif

// &amp;lt;q&amp;gt; NRFX_SPIS1_ENABLED - Enable SPIS1 instance

#ifndef NRFX_SPIS1_ENABLED
#define NRFX_SPIS1_ENABLED 0
#endif&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;However, if I change the device id&amp;nbsp;for master and slave instances then problem goes away and it compiles &amp;amp; links successfully:&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define SPI_DEV_ID_0 0
#define SPI_DEV_ID_1 1

nrfx_spim_t const hSpiMasterDev0 = NRFX_SPIM_INSTANCE(SPI_DEV_ID_0);
nrfx_spis_t const hSpiSlaveDev0 = NRFX_SPIS_INSTANCE(SPI_DEV_ID_1);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;sdk_config.h:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// &amp;lt;e&amp;gt; NRFX_SPIM_ENABLED - nrfx_spim - SPIM peripheral driver
//==========================================================
#ifndef NRFX_SPIM_ENABLED
#define NRFX_SPIM_ENABLED 1
#endif
// &amp;lt;q&amp;gt; NRFX_SPIM0_ENABLED  - Enable SPIM0 instance
 

#ifndef NRFX_SPIM0_ENABLED
#define NRFX_SPIM0_ENABLED 1
#endif

// &amp;lt;q&amp;gt; NRFX_SPIM1_ENABLED  - Enable SPIM1 instance
 

#ifndef NRFX_SPIM1_ENABLED
#define NRFX_SPIM1_ENABLED 0
#endif


// &amp;lt;e&amp;gt; NRFX_SPIS_ENABLED - nrfx_spis - SPIS peripheral driver
//==========================================================
#ifndef NRFX_SPIS_ENABLED
#define NRFX_SPIS_ENABLED 1
#endif
// &amp;lt;q&amp;gt; NRFX_SPIS0_ENABLED - Enable SPIS0 instance

#ifndef NRFX_SPIS0_ENABLED
#define NRFX_SPIS0_ENABLED 0
#endif

// &amp;lt;q&amp;gt; NRFX_SPIS1_ENABLED - Enable SPIS1 instance

#ifndef NRFX_SPIS1_ENABLED
#define NRFX_SPIS1_ENABLED 1
#endif&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Confusing how to integrate SPI master and slave drivers/HAL in my C code</title><link>https://devzone.nordicsemi.com/thread/214489?ContentTypeID=1</link><pubDate>Fri, 11 Oct 2019 04:58:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8b2a8061-14e1-42e8-8077-84aec8f179d9</guid><dc:creator>nvj</dc:creator><description>&lt;p&gt;Thanks &lt;a href="https://devzone.nordicsemi.com/members/hnhoan"&gt;Nguyen Hoan Hoang&lt;/a&gt; I will have a look.&lt;/p&gt;
&lt;p&gt;So what I did so far I am linking my project with only nrfx drivers and their headers, namely:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;modules\nrfx\drivers\src\nrfx_spis.c&amp;nbsp;&lt;/li&gt;
&lt;li&gt;modules\nrfx\drivers\src\nrfx_spim.c&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I changed my code to use only functions in the headers for above driver.&lt;/p&gt;
&lt;p&gt;From my sdk_config.h, I also removed&amp;nbsp;many SPI legacy macros which are irrelevant.&lt;/p&gt;
&lt;p&gt;sdk_config.h:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// &amp;lt;e&amp;gt; NRFX_SPIM_ENABLED - nrfx_spim - SPIM peripheral driver
//==========================================================
#ifndef NRFX_SPIM_ENABLED
#define NRFX_SPIM_ENABLED 1
#endif
// &amp;lt;q&amp;gt; NRFX_SPIM0_ENABLED  - Enable SPIM0 instance
 

#ifndef NRFX_SPIM0_ENABLED
#define NRFX_SPIM0_ENABLED 1
#endif

// &amp;lt;e&amp;gt; NRFX_SPIS_ENABLED - nrfx_spis - SPIS peripheral driver
//==========================================================
#ifndef NRFX_SPIS_ENABLED
#define NRFX_SPIS_ENABLED 1
#endif
// &amp;lt;q&amp;gt; NRFX_SPIS0_ENABLED  - Enable SPIS0 instance
 

#ifndef NRFX_SPIS0_ENABLED
#define NRFX_SPIS0_ENABLED 1
#endif


/* COMMENTED OUT SPI macros for unused spi driver or legacy drivers

// &amp;lt;e&amp;gt; NRFX_SPI_ENABLED - nrfx_spi - SPI peripheral driver
//==========================================================
#ifndef NRFX_SPI_ENABLED
#define NRFX_SPI_ENABLED 0
#endif
// &amp;lt;q&amp;gt; NRFX_SPI0_ENABLED  - Enable SPI0 instance
 

#ifndef NRFX_SPI0_ENABLED
#define NRFX_SPI0_ENABLED 0
#endif


// &amp;lt;e&amp;gt; SPIS_ENABLED - nrf_drv_spis - SPIS peripheral driver - legacy layer
//==========================================================
#ifndef SPIS_ENABLED
#define SPIS_ENABLED 1
#endif
// &amp;lt;o&amp;gt; SPIS_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority

// &amp;lt;q&amp;gt; SPIS0_ENABLED  - Enable SPIS0 instance
 

#ifndef SPIS0_ENABLED
#define SPIS0_ENABLED 1
#endif

// &amp;lt;e&amp;gt; SPI_ENABLED - nrf_drv_spi - SPI/SPIM peripheral driver - legacy layer
//==========================================================
#ifndef SPI_ENABLED
#define SPI_ENABLED 0
#endif
// &amp;lt;o&amp;gt; SPI_DEFAULT_CONFIG_IRQ_PRIORITY  - Interrupt priority

// &amp;lt;e&amp;gt; SPI0_ENABLED - Enable SPI0 instance
//==========================================================
#ifndef SPI0_ENABLED
#define SPI0_ENABLED 1
#endif

*/&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;However, astonishingly I am still getting the same error.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="bat"&gt;Error[Li006]: duplicate definitions for &amp;quot;SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler&amp;quot;; in &amp;quot;D:\nRF\sdk\nRF5_SDK_15.3.0_59ac345\examples\ble_peripheral\custom_project\pca10040\s132\iar\_build\nrfx_spim.o&amp;quot;, and 
&amp;quot;D:\nRF\sdk\nRF5_SDK_15.3.0_59ac345\examples\ble_peripheral\custom_projectbmn\pca10040\s132\iar\_build\nrfx_spis.o&amp;quot; &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I saw another related post: &amp;quot;&lt;a title="SPIM3 initialization issue" href="https://devzone.nordicsemi.com/f/nordic-q-a/52072/spim3-initialization-issue/209575#209575"&gt;SPIM3 initialization issue&lt;/a&gt;&amp;quot; ,&amp;nbsp;however SPI rleated macros still remain&amp;nbsp;confusing.&lt;/p&gt;
&lt;p&gt;Not able to proceed forward.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Confusing how to integrate SPI master and slave drivers/HAL in my C code</title><link>https://devzone.nordicsemi.com/thread/214251?ContentTypeID=1</link><pubDate>Thu, 10 Oct 2019 03:15:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b4424e35-c793-4921-bae0-dc53bdd04e11</guid><dc:creator>Nguyen Hoan Hoang</dc:creator><description>&lt;p&gt;Those drivers are very messy. &amp;nbsp;Try this one instead. It&amp;#39;s been used and tested with lots of devices, sensors, flash,...&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/IOsonata/IOsonata/blob/master/ARM/Nordic/src/spi_nrf5x.cpp"&gt;https://github.com/IOsonata/IOsonata/blob/master/ARM/Nordic/src/spi_nrf5x.cpp&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/IOsonata/IOsonata/blob/master/exemples/spi/spi_master_slave.cpp"&gt;https://github.com/IOsonata/IOsonata/blob/master/exemples/spi/spi_master_slave.cpp&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Confusing how to integrate SPI master and slave drivers/HAL in my C code</title><link>https://devzone.nordicsemi.com/thread/214250?ContentTypeID=1</link><pubDate>Thu, 10 Oct 2019 03:06:48 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c50de1f1-b14b-44ad-a6ec-db8e105de196</guid><dc:creator>nvj</dc:creator><description>&lt;p&gt;I am getting following error on compilation and linking:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;Error[Li006]: duplicate definitions for &amp;quot;SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler&amp;quot;; in &amp;quot;D:\nRF\sdk\nRF5_SDK_15.3.0_59ac345\examples\ble_peripheral\custom_project\pca10040\s132\iar\_build\nrfx_spim.o&amp;quot;, and 
&amp;quot;D:\nRF\sdk\nRF5_SDK_15.3.0_59ac345\examples\ble_peripheral\custom_project\pca10040\s132\iar\_build\nrfx_spis.o&amp;quot; &lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>