<?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>NRF52 - need library function equivalent to SHiftIn() and bitWrite() in Arduino.Pls Help.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/20129/nrf52---need-library-function-equivalent-to-shiftin-and-bitwrite-in-arduino-pls-help</link><description>hi
I&amp;#39;m porting Arduino code which has calls to ShiftIn() to read a byte from a GPIO Pin and bitWrite() to write a bit into a byte variable at a particular position.
Below is example arduino code: 
 data[2] = shiftIn(DOUT, PD_SCK, MSBFIRST);
data[1</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 03 Mar 2017 09:30:39 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/20129/nrf52---need-library-function-equivalent-to-shiftin-and-bitwrite-in-arduino-pls-help" /><item><title>RE: NRF52 - need library function equivalent to SHiftIn() and bitWrite() in Arduino.Pls Help.</title><link>https://devzone.nordicsemi.com/thread/78366?ContentTypeID=1</link><pubDate>Fri, 03 Mar 2017 09:30:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:560c00a8-3e72-4319-a807-9b6a41d384f7</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&lt;a href="https://www.arduino.cc/en/Reference/ShiftIn"&gt;&lt;code&gt;shiftIn()&lt;/code&gt;&lt;/a&gt; seems like a software implementation of SPI. You can read about the SPI driver from our SDK &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v12.2.0/hardware_driver_spi_master.html?cp=4_0_1_2_14"&gt;here&lt;/a&gt;. There is also an example &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v12.2.0/spi_master_example.html?cp=4_0_1_4_5_31"&gt;available here&lt;/a&gt;. On the nRF51 and nRF52 series, you can select any of the GPIOs as pins for the SPI interfaces.&lt;/p&gt;
&lt;p&gt;bitWrite is just basic &lt;a href="http://stackoverflow.com/a/47990"&gt;bit manipulation&lt;/a&gt;. You can make this into a function if you use it frequently (you should extend it for other types and add some error checking):&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;uint8_t bitWrite(uint8_t x, uint8_t n, uint8_t b)
{
	return (b ? (x | 1 &amp;lt;&amp;lt; n) : (x &amp;amp; ~(1 &amp;lt;&amp;lt; n)));
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>