<?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>SPI read and write single bytes with delays</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/36771/spi-read-and-write-single-bytes-with-delays</link><description>Hello. 
 Im in a stage where I need to transfer over our current old (ancient) libraries for SPI communications to a NRF52, where we use SPI to communicate to a certain slave as follows: 
 
 The functions SPIWriteByte and SPIReadByte are as follows: </description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 12 Feb 2019 08:38:08 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/36771/spi-read-and-write-single-bytes-with-delays" /><item><title>RE: SPI read and write single bytes with delays</title><link>https://devzone.nordicsemi.com/thread/170515?ContentTypeID=1</link><pubDate>Tue, 12 Feb 2019 08:38:08 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:13b78230-4488-4750-a0a4-98618d7be83a</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Please check if you are affected by &lt;a href="https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.Rev2.errata/dita/errata/nRF52832/Rev2/latest/anomaly_832_58.html?cp=2_1_1_0_1_8"&gt;errata 58&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI read and write single bytes with delays</title><link>https://devzone.nordicsemi.com/thread/170473?ContentTypeID=1</link><pubDate>Tue, 12 Feb 2019 00:43:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:997075e0-38a6-455e-9ba8-dbe1cf95c168</guid><dc:creator>Bernard Chan Lye Hock</dc:creator><description>&lt;p&gt;I tried this idea and it is working for me. However, I find from the scope that in the SPI_Read it would transfer 16 bits of data instead of 8 bit read data. Do you see this as well?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI read and write single bytes with delays</title><link>https://devzone.nordicsemi.com/thread/141561?ContentTypeID=1</link><pubDate>Thu, 26 Jul 2018 15:51:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:740eb4fe-8037-45be-9a10-17933840cea2</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;This is in line with the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/spim.html?cp=2_1_0_30_2#concept_lhv_fx2_wr"&gt;documentation&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The SPI master is a synchronous interface, and for every byte that is sent, a different byte will be received at the same time; this is illustrated in&amp;nbsp;&lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.nrf52832.ps.v1.1/spim.html#concept_lhv_fx2_wr__fig"&gt;Figure 3&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SPI read and write single bytes with delays</title><link>https://devzone.nordicsemi.com/thread/141182?ContentTypeID=1</link><pubDate>Tue, 24 Jul 2018 14:16:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a920ef1e-34cb-4822-a8d1-01f8c6c2a175</guid><dc:creator>mmmark84</dc:creator><description>&lt;p&gt;Seems calling nrf_drv_spi_transfer(&amp;amp;spi0, &amp;amp;tx, &lt;strong&gt;0&lt;/strong&gt;, &amp;amp;rx, 1); did the trick!&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;void SPI_Write(unsigned char spibus, unsigned char device, unsigned char byte)
{
	if (spibus == SPI0_BUS)
	{	
		#ifndef BLOCKING_MODE
			spi0_xfer_done   = false;
		#endif
		nrf_drv_spi_transfer(&amp;amp;spi0, &amp;amp;byte, 1, NULL, 0);
		#ifndef BLOCKING_MODE
			while(spi0_xfer_done == false) {}
		#endif
	}
}


unsigned char SPI_Read(unsigned char spibus, unsigned char device)
{
	char data;
	data = 0x00;
	if (spibus == SPI0_BUS)
	{	unsigned char tx = 0xFF;
		unsigned char rx = 0xFF;
		#ifndef BLOCKING_MODE
			spi0_xfer_done   = false;
		#endif
		nrf_drv_spi_transfer(&amp;amp;spi0, &amp;amp;tx, 0, &amp;amp;rx, 1); // 1 dummy byte sturen			
		#ifndef BLOCKING_MODE
			while(spi0_xfer_done == false) {}
		#endif
		return rx; 
	}
	return (data); 
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>