<?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>nRF52832 SPI function</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/33277/nrf52832-spi-function</link><description>Hi, 
 I am trying to make a simple function for writing via SPI. I am using the SPI example and it works fine. Now I would just like to make two SPI functions that I can use in my project: 
 
 - initSPI() 
 - ReadWriteSPI() 
 
 I have made the following</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 01 Oct 2018 09:04:19 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/33277/nrf52832-spi-function" /><item><title>RE: nRF52832 SPI function</title><link>https://devzone.nordicsemi.com/thread/150910?ContentTypeID=1</link><pubDate>Mon, 01 Oct 2018 09:04:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:090aa35a-294e-49e5-84a0-4405495a10b9</guid><dc:creator>rohit</dc:creator><description>&lt;p&gt;Hello Jan,&lt;/p&gt;
&lt;p&gt;I am also trying same&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Is it working &lt;strong&gt;Reg_read and&amp;nbsp; Reg_write&lt;/strong&gt; function for SPI Communication?&lt;/p&gt;
&lt;p&gt;please let me know&lt;/p&gt;
&lt;p&gt;thanks and regards,&lt;/p&gt;
&lt;p&gt;rohit&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52832 SPI function</title><link>https://devzone.nordicsemi.com/thread/127898?ContentTypeID=1</link><pubDate>Wed, 11 Apr 2018 18:35:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:51307ebb-745c-4599-b287-9794ca52ecfb</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Technically you would write &lt;em&gt;&amp;amp;mTxBuf[0]&lt;/em&gt; to correctly form the exact same pointer as &lt;em&gt;mTxBuf&lt;/em&gt;; often something like &lt;em&gt;&amp;amp;mTxBuf[strlen(mTxBuf)]&lt;/em&gt; is used to obtain a pointer to the location where one would append text to a string, assuming an ascii string of course as that has the &lt;em&gt;\0&lt;/em&gt; terminator which &lt;em&gt;strlen()&lt;/em&gt; requires to identify the end-of-string. Note &lt;em&gt;&amp;amp;mTxSomething&lt;/em&gt;&amp;nbsp;where&amp;nbsp;&lt;em&gt;mTxSomething&lt;/em&gt; is a single character cannot be used as a string pointer, just a pointer to a single character. If that is passed to a function which requires a pointer to data the system would die a horrible death unless the length was set to 1.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52832 SPI function</title><link>https://devzone.nordicsemi.com/thread/127889?ContentTypeID=1</link><pubDate>Wed, 11 Apr 2018 16:40:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6638f70a-3253-4845-8ae6-99453f424178</guid><dc:creator>Jan Lundskov</dc:creator><description>&lt;p&gt;Thanks for your reply. It works now when I change the&amp;nbsp;m_tx_buf and m_rx_buf&amp;nbsp;arguments to pointers. So just to make sure that I understand it correctly...&lt;/p&gt;
&lt;p&gt;Since mTxBuf[] and mRxBuf[] in your example above are both defined as arrays, then simply writing &amp;#39;mTxBuf&amp;#39; and &amp;#39;mRxBuf&amp;#39; is the same as writing &amp;amp;mTxBuf and &amp;amp;mRxBuf if they were only defined as simple uint8_t (not an array of uint8_t). Is that correctly understood?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52832 SPI function</title><link>https://devzone.nordicsemi.com/thread/127880?ContentTypeID=1</link><pubDate>Wed, 11 Apr 2018 15:37:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bd79e1e8-ac65-42b4-9387-d177c34a7f78</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;There is a bug in the code you list above, but due to the way the c compiler works you can fool the code into working. Look at the definition of &lt;em&gt;nrf_drv_spi_transfer()&lt;/em&gt;, it requires pointers to the buffers&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;ret_code_t nrf_drv_spi_transfer(nrf_drv_spi_t const * const p_instance,
                                uint8_t const * p_tx_buffer,
                                uint8_t         tx_buffer_length,
                                uint8_t       * p_rx_buffer,
                                uint8_t         rx_buffer_length)
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The buffers &lt;em&gt;mTxBuf[]&lt;/em&gt; and &lt;em&gt;mRxBuf[]&lt;/em&gt; are pointers as they are defined as arrays, and are used as pointers by &lt;em&gt;nrf_drv_spi_transfer()&lt;/em&gt;:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;uint8_t mTxBuf[] = {ADS_CMND_RREG, NUMBER_OF_ADS_REGISTERS-1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
uint8_t mRxBuf[sizeof(mTxBuf)];

APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;mAfeSpiInstance, mTxBuf, mRxTxBufLength, mRxBuf, mRxTxBufLength));
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Your&amp;nbsp;function definition omits the pointer definition, and so expects uint8_t values, which in practice&amp;nbsp; probably passes as 32-bit values which you have been able to force to pointers (also 32-bit values)&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void ReadWriteSPI(nrf_drv_spi_t spi, uint8_t m_tx_buf, uint8_t m_rx_buf, uint8_t m_length)
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Change function definition to use pointers to correct this issue:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void ReadWriteSPI(nrf_drv_spi_t spi, uint8_t *m_tx_buf, uint8_t *m_rx_buf, uint8_t m_length)
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF52832 SPI function</title><link>https://devzone.nordicsemi.com/thread/127791?ContentTypeID=1</link><pubDate>Wed, 11 Apr 2018 10:44:07 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:516a89c1-3baa-410a-b73e-06bfa6183423</guid><dc:creator>Jan Lundskov</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I have just found that if I add the pointer operator &amp;#39;&amp;amp;&amp;#39; in front of m_tx_buf and m_rx_buf, then it seems to work. But why is that not necessary in the sample code..?&lt;/p&gt;
&lt;p&gt;So this seems to work&lt;/p&gt;
&lt;p&gt;&lt;span&gt;APP_ERROR_CHECK(nrf_drv_spi_transfer(&amp;amp;spi, &lt;strong&gt;&amp;amp;m_tx_buf&lt;/strong&gt;, m_length, &lt;strong&gt;&amp;amp;m_rx_buf&lt;/strong&gt;, m_length));&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Jan&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>