<?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>Source code to get DS18B20 temperature feedback in nrf51822</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/38019/source-code-to-get-ds18b20-temperature-feedback-in-nrf51822</link><description>Hi, 
 
 I am using nrf51822 to get DS18B20&amp;#39;s temperature data, but I am fail to do it. 
 Would you please give me an sample C source code which can get temperature data from DS18B20? 
 
 Thank you, 
 Chianglin</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 07 Jan 2019 11:50:20 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/38019/source-code-to-get-ds18b20-temperature-feedback-in-nrf51822" /><item><title>RE: Source code to get DS18B20 temperature feedback in nrf51822</title><link>https://devzone.nordicsemi.com/thread/164226?ContentTypeID=1</link><pubDate>Mon, 07 Jan 2019 11:50:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4b9fcb29-b382-4211-b878-6fbbdddaf8d6</guid><dc:creator>Gaurav</dc:creator><description>&lt;p&gt;Here we are not checking the CRC check calculated from the scratchpad and the one calculated from rom.&lt;/p&gt;
&lt;p&gt;Do we require to do so if yes then how&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Source code to get DS18B20 temperature feedback in nrf51822</title><link>https://devzone.nordicsemi.com/thread/147645?ContentTypeID=1</link><pubDate>Thu, 06 Sep 2018 14:57:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ef265ad2-31ba-4c5b-9989-19128bb3636e</guid><dc:creator>chianglin</dc:creator><description>&lt;p&gt;&lt;span&gt;Hi&amp;nbsp;&lt;/span&gt;&lt;span&gt;Martin,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;My DS18B20 hardware circuit is the same as you.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Let me check if there have any problem of hardware circuit, and then discuss with you.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thank you for your assistance.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Chianglin&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Source code to get DS18B20 temperature feedback in nrf51822</title><link>https://devzone.nordicsemi.com/thread/147480?ContentTypeID=1</link><pubDate>Thu, 06 Sep 2018 07:15:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aa71e1cd-5a9d-4bb6-8b2e-a3e7616d06cb</guid><dc:creator>Martin Lesund</dc:creator><description>&lt;p&gt;Hi Ives,&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Before adding new features&lt;/em&gt;, can you confirm that you are actually getting out the correct values from your temperature sensor?&lt;/li&gt;
&lt;li&gt;Could you also provide schematics on how your&amp;nbsp;DS18b20 circuit is as well? (do you use a pull-up&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;I got this when testing your application:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-2cfe787d739841bda293f1b9717c6a50/pastedimage1536217659805v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Make sure that your circuit is like:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-2cfe787d739841bda293f1b9717c6a50/pastedimage1536218144390v2.png" alt=" " /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Source code to get DS18B20 temperature feedback in nrf51822</title><link>https://devzone.nordicsemi.com/thread/147431?ContentTypeID=1</link><pubDate>Wed, 05 Sep 2018 15:59:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f481273b-a6f5-4192-9bf5-c52206e12d88</guid><dc:creator>chianglin</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;span&gt;Hi&amp;nbsp;&lt;/span&gt;&lt;span&gt;Martin,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Yes. you are right.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I had check my DS18b20 circuit again, and had connect to incorrect pin.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;After I connect DS18B20 data pin with P0.29, I had print out all the ROM data&amp;nbsp; into RTT, please find the following debug message&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/3005.Log.JPG" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;According to the display result of the One-Wire waveform, the data read should be 0x0118323C7DFF. However, the data I read is 0xFFFFFFFFFFFF..&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;span&gt;My source code is:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/DS18B20Test_5F00_03.7z"&gt;devzone.nordicsemi.com/.../DS18B20Test_5F00_03.7z&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Would you please tell me how can I modify my code?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thank you,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Chianglin&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Source code to get DS18B20 temperature feedback in nrf51822</title><link>https://devzone.nordicsemi.com/thread/147329?ContentTypeID=1</link><pubDate>Wed, 05 Sep 2018 09:31:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:606f0241-f9de-43ca-88d2-fa877cd36dc0</guid><dc:creator>Martin Lesund</dc:creator><description>&lt;p&gt;Hi Ives,&lt;/p&gt;
&lt;p&gt;I ran your exact application you posted.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;span style="text-decoration:underline;"&gt;&amp;nbsp;I did not have any&amp;nbsp;issues:&lt;/span&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-2cfe787d739841bda293f1b9717c6a50/pastedimage1536139436702v1.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;However, if i disconnect&amp;nbsp;VDD to the sensor or the one wire data line I get stuck:&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-2cfe787d739841bda293f1b9717c6a50/pastedimage1536139551776v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;Could you post how you have connected to the Sensor?&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-2cfe787d739841bda293f1b9717c6a50/Connections.jpg" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;(&lt;em&gt;RED- VDD, Yellow-onewire(p0.29), BLACK-GND)&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Source code to get DS18B20 temperature feedback in nrf51822</title><link>https://devzone.nordicsemi.com/thread/147325?ContentTypeID=1</link><pubDate>Wed, 05 Sep 2018 09:16:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:154862dc-cb9d-4993-9d6e-32da543bbd29</guid><dc:creator>chianglin</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;span&gt;Martin,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Sorry, I forgot to tell you:&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I had already change DS18B20 data pin to pin 29, so I can find follow message.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/0312.Capture.JPG" /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;But the program can not exit following loop.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;			while (! iBSPACMonewireReadBit_ni()) {
				NRF_LOG_INFO(&amp;quot;(R0004) \r\n&amp;quot;);
			}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thank you,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Chianglin&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Source code to get DS18B20 temperature feedback in nrf51822</title><link>https://devzone.nordicsemi.com/thread/147294?ContentTypeID=1</link><pubDate>Wed, 05 Sep 2018 07:55:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:dcdf7fc2-15b6-433b-8ab4-c7eb893db919</guid><dc:creator>Martin Lesund</dc:creator><description>&lt;p&gt;Hi Ives,&lt;/p&gt;
&lt;p&gt;Note that I have changed the GPIO pin for the one wire.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define ONEWIRE_PIN 29&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;If you have not connected to the pin correctly as well as powering the Temp. sensor you would get out that info message according to my observations.&lt;/p&gt;
&lt;p&gt;Please double check and verify the connection.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best Regards,&lt;/p&gt;
&lt;p&gt;Martin L.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Source code to get DS18B20 temperature feedback in nrf51822</title><link>https://devzone.nordicsemi.com/thread/147228?ContentTypeID=1</link><pubDate>Tue, 04 Sep 2018 15:57:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0f032a24-d36d-4d2a-a958-e4cb1912e354</guid><dc:creator>chianglin</dc:creator><description>&lt;p&gt;&lt;span&gt;Hi&amp;nbsp;Martin,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;After I will test directly with the code you provided.test directly with the code you provided, and it still have one problem.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/DS18B20Test_5F00_02.7z"&gt;devzone.nordicsemi.com/.../DS18B20Test_5F00_02.7z&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;It will always print &amp;quot;INFO: (R0004)&amp;quot; in RTT debug windows.&amp;nbsp; It means the program always stay in following loop\&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="text"&gt;			while (! iBSPACMonewireReadBit_ni()) {
				NRF_LOG_INFO(&amp;quot;(R0004) \r\n&amp;quot;);
			}
&lt;/pre&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Does I miss something?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thank you&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Chianglin&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Source code to get DS18B20 temperature feedback in nrf51822</title><link>https://devzone.nordicsemi.com/thread/147221?ContentTypeID=1</link><pubDate>Tue, 04 Sep 2018 15:01:35 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cfe55a59-498b-4d49-8ceb-5cf750cde16e</guid><dc:creator>Martin Lesund</dc:creator><description>&lt;p&gt;Hi Ives.&lt;/p&gt;
&lt;p&gt;I added the full project which I have modified so it now writes out the correct values.&lt;br /&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-2cfe787d739841bda293f1b9717c6a50/DS18B20TEST.7z"&gt;devzone.nordicsemi.com/.../DS18B20TEST.7z&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I stripped down main.c and added some stuff in the DS18B20.c so it only takes the measurements of the one-wire sensor. (I used RTT for logging)&lt;/p&gt;
&lt;p&gt;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-2cfe787d739841bda293f1b9717c6a50/pastedimage1536073097911v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;(&lt;em&gt;note: 190 = 19.0 C and 662 = 66.2 F)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;which is correct:&amp;nbsp;&lt;img src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/support-attachments/beef5d1b77644c448dabff31668f3a47-2cfe787d739841bda293f1b9717c6a50/pastedimage1536073212632v3.png" alt=" " /&gt;&lt;/em&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Source code to get DS18B20 temperature feedback in nrf51822</title><link>https://devzone.nordicsemi.com/thread/147017?ContentTypeID=1</link><pubDate>Mon, 03 Sep 2018 14:55:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d4195516-8511-4b9c-8320-e17eba06305d</guid><dc:creator>chianglin</dc:creator><description>&lt;p&gt;&lt;span&gt;Hi&amp;nbsp;Martin,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;My SDK is&amp;nbsp;nRF5_SDK_12.3.0_d7731ad and I am use nrf51822 MCU.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;`Please find the attach file for my full project.&amp;nbsp; Please un-compress the 7z file into ./example/peripheral directory.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/DS18B20Test.7z"&gt;devzone.nordicsemi.com/.../DS18B20Test.7z&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thank you,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Chianglin&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Source code to get DS18B20 temperature feedback in nrf51822</title><link>https://devzone.nordicsemi.com/thread/146993?ContentTypeID=1</link><pubDate>Mon, 03 Sep 2018 13:23:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1a17111f-9322-454d-a3ac-21f618bf6a84</guid><dc:creator>Martin Lesund</dc:creator><description>&lt;p&gt;Hi Ives,&lt;/p&gt;
&lt;p&gt;What SDK version are you running on?&lt;br /&gt;could you send over the whole project so I could recreate it on my desk?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Source code to get DS18B20 temperature feedback in nrf51822</title><link>https://devzone.nordicsemi.com/thread/146843?ContentTypeID=1</link><pubDate>Sat, 01 Sep 2018 10:06:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:68c5c396-b424-4e63-be90-d211f59a8404</guid><dc:creator>chianglin</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;Martin,&lt;/p&gt;
&lt;p&gt;Thank you for your answer.&lt;/p&gt;
&lt;p&gt;I had modify the demo code, and the debug output is:&lt;/p&gt;
&lt;p&gt;Power supply: external&lt;br /&gt;Serial got -1:&lt;br /&gt;Got 40959 dCel, 74046 d[Fahr]&lt;br /&gt;Got 40959 dCel, 74046 d[Fahr]&lt;br /&gt;Got 40959 dCel, 74046 d[Fahr]&lt;br /&gt;Got 40959 dCel, 74046 d[Fahr]&lt;/p&gt;
&lt;p&gt;About my source code, please find following code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;quot;nrf_gpio.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;lt;stdio.h&amp;gt;

/** Structure holding a 1-wire serial number. */
typedef struct sBSPACMonewireSerialNumber
{
	/** The serial number in order MSB to LSB */
	uint8_t id[6];
} sBSPACMonewireSerialNumber;

enum
{
	BSPACM_ONEWIRE_CMD_READ_ROM = 0x33,						/** Read 64-bit ROM code without using search procedure */
	BSPACM_ONEWIRE_CMD_SKIP_ROM = 0xcc,						/** Skip ROM sends the following command to all bus devices */
	BSPACM_ONEWIRE_CMD_READ_POWER_SUPPLY = 0xb4,			// Determine whether device is parasite-powered or external-powered */
	BSPACM_ONEWIRE_CMD_RECALL_EE = 0xb8,					/** Store data from EEPROM into RAM */
	BSPACM_ONEWIRE_CMD_READ_SCRATCHPAD = 0xbe,				/** Read the RAM area. */

	BSPACM_ONEWIRE_CMD_CONVERT_T = 0x44,					// Initiate a temperature conversion.
															/* * Be aware that temperature conversion can take up to 750ms at the
	 														* default 12-bit resolution.
	 														*
	 														* For an externally (non-parasite) powered sensor, the caller may
	 														* use #iBSPACMonewireReadBit_ni to determine whether the conversion
	 														* has completed.	Completion is indicated when the device responds
	 														* with a 1. */
};

/** Define protocol state times in microseconds.
 *
 * @note Since all these times are far less than any sane watchdog
 * interval, and the timing can be important, BSPACM_CORE_DELAY_CYCLES
 * is not used in this module. */
enum
{
	OWT_RSTL_us = 480,						/** Minimum time to hold bus low to ensure reset */
	OWT_RSTH_us = 480,						/** Time to wait for presence detection after reset to quiesce */
	OWT_PDHIGH_us = 60,						/** Delay before presence pulse is known to be valid (15us..60us) */
	OWT_LOW0_us = 60,						/** Minimum time to hold bus low when writing a zero */
	OWT_LOW1_us = 1,						/** Minimum time to hold bus low when writing a one */
	OWT_REC_us = 1,							/** Recovery delay between write/read transaction cycles */
	OWT_INT_us = 1,							/** Time to hold bus low when initiating a read slot */
	OWT_RDV_us = 15 - OWT_INT_us,			/** Point at which read value should be sampled */
	OWT_SLOT_us = 60,						/** Minimum duration of a read or write slot */
};

#ifndef ONEWIRE_PIN
#define ONEWIRE_PIN 26
#endif /* ONEWIRE_PIN */
#define ONEWIRE_BIT (1ULL &amp;lt;&amp;lt; ONEWIRE_PIN)

void dirset (void)
{
	NRF_GPIO-&amp;gt;DIRSET = ONEWIRE_BIT;
}

void dirclr (void)
{
	NRF_GPIO-&amp;gt;PIN_CNF[ONEWIRE_PIN] = 0
		| (GPIO_PIN_CNF_SENSE_Disabled &amp;lt;&amp;lt; GPIO_PIN_CNF_SENSE_Pos)
		| (GPIO_PIN_CNF_DRIVE_S0S1 &amp;lt;&amp;lt; GPIO_PIN_CNF_DRIVE_Pos)
		| (GPIO_PIN_CNF_PULL_Disabled &amp;lt;&amp;lt; GPIO_PIN_CNF_PULL_Pos)
		| (GPIO_PIN_CNF_INPUT_Connect &amp;lt;&amp;lt; GPIO_PIN_CNF_INPUT_Pos)
		| (GPIO_PIN_CNF_DIR_Input &amp;lt;&amp;lt; GPIO_PIN_CNF_DIR_Pos);
}

int iBSPACMonewireReset_ni (void)
{
	int present;

#if 1
	/* Non-standard: Hold bus high for OWT_RESET_us.	This provides
	 * enough parasitic power for the device to signal presence.
	 * Without this, effective RSTL duration may exceed the maximum
	 * 960us before device reset. */
	dirset();
	NRF_GPIO-&amp;gt;OUTSET = ONEWIRE_BIT;
	nrf_delay_us(OWT_RSTH_us);

	/* Hold bus low for OWT_RESET_us */
	NRF_GPIO-&amp;gt;OUTCLR = ONEWIRE_BIT;
	nrf_delay_us(OWT_RSTL_us);

	/* Release bus and switch to input until presence pulse should be
	 * visible. */
	dirclr();
	nrf_delay_us(OWT_PDHIGH_us);

	/* Record presence if bus is low (DS182x is holding it there) */
	present = !(NRF_GPIO-&amp;gt;IN &amp;amp; ONEWIRE_BIT);

	/* Wait for reset cycle to complete */
	nrf_delay_us(OWT_RSTH_us - OWT_PDHIGH_us);
#else
	/* Non-standard: Hold bus high for OWT_RESET_us.	This provides
	 * enough parasitic power for the device to signal presence.
	 * Without this, effective RSTL duration may exceed the maximum
	 * 960us before device reset. */
	nrf_gpio_cfg_output(ONEWIRE_PIN);
	nrf_gpio_pin_set(ONEWIRE_PIN);
	nrf_delay_us(OWT_RSTH_us);

	/* Hold bus low for OWT_RESET_us */
	nrf_gpio_pin_clear(ONEWIRE_PIN);
	nrf_delay_us(OWT_RSTL_us);

	nrf_gpio_cfg_input(ONEWIRE_PIN, NRF_GPIO_PIN_NOPULL);			// Release bus and switch to input until presence pulse should be visible.
	nrf_delay_us(OWT_PDHIGH_us);

	/* Record presence if bus is low (DS182x is holding it there) */
	present = !(nrf_gpio_pin_read(ONEWIRE_PIN));
#endif
	/* Wait for reset cycle to complete */
	nrf_delay_us(OWT_RSTH_us - OWT_PDHIGH_us);

	return present;
}

void vBSPACMonewireShutdown_ni (void)
{
	NRF_GPIO-&amp;gt;OUTCLR = ONEWIRE_BIT;
	dirclr();
}

void vBSPACMonewireWriteByte_ni (int byte)
{
	int bp;

	for (bp = 0; bp &amp;lt; 8; ++bp)
	{
		NRF_GPIO-&amp;gt;OUTCLR = ONEWIRE_BIT;
		dirset();
		if (byte &amp;amp; 0x01) {
			nrf_delay_us(OWT_LOW1_us);
			dirclr();
			nrf_delay_us(OWT_SLOT_us - OWT_LOW1_us + OWT_REC_us);
		} else {
			nrf_delay_us(OWT_LOW0_us);
			dirclr();
			nrf_delay_us(OWT_SLOT_us - OWT_LOW0_us + OWT_REC_us);
		}
		byte &amp;gt;&amp;gt;= 1;
	}
}

int iBSPACMonewireReadBit_ni (void)
{
	int rv;

	NRF_GPIO-&amp;gt;OUTCLR = ONEWIRE_BIT;
	dirset();
	nrf_delay_us(OWT_INT_us);
	dirclr();
	nrf_delay_us(OWT_RDV_us);
	//abc	vBSPACMledSet(0, 1);
	rv = !!(NRF_GPIO-&amp;gt;IN &amp;amp; ONEWIRE_BIT);
	//abc	vBSPACMledSet(0, 0);
	nrf_delay_us(OWT_SLOT_us - OWT_RDV_us - OWT_INT_us + OWT_REC_us);
	return rv;
}

int iBSPACMonewireReadByte_ni (void)
{
	int byte = 0;
	int bit = 1;

	do {
		if (iBSPACMonewireReadBit_ni()) {
			byte |= bit;
		}
		bit &amp;lt;&amp;lt;= 1;
	} while (0x100 != bit);
	return byte;
}

int iBSPACMonewireComputeCRC(const unsigned char * romp, int len)
{
	static const unsigned char OW_CRC_POLY = 0x8c;
	unsigned char crc = 0;

	while (0 &amp;lt; len--) {
		int bi;

		crc ^= *romp++;
		for (bi = 0; bi &amp;lt; 8; ++bi) {
			if (crc &amp;amp; 1) {
				crc = (crc &amp;gt;&amp;gt; 1) ^ OW_CRC_POLY;
			} else {
				crc &amp;gt;&amp;gt;= 1;
			}
		}
	}
	return crc;
}

int iBSPACMonewireReadSerialNumber (sBSPACMonewireSerialNumber * snp)
{
	uint8_t rom[8];
	int i;
	int rv = -1;

	do {
		if (! iBSPACMonewireReset_ni()) {
			break;
		}
		vBSPACMonewireWriteByte_ni(BSPACM_ONEWIRE_CMD_READ_ROM);
		for (i = 0; i &amp;lt; sizeof(rom); ++i) {
			rom[i] = iBSPACMonewireReadByte_ni();
		}
		rv = 0;
	} while (0);

	if (0 == rv) {
		if (0 != iBSPACMonewireComputeCRC(rom, sizeof(rom))) {
			rv = -1;
		} else {
			for (i = 0; i &amp;lt; sizeof(snp-&amp;gt;id); ++i) {
				snp-&amp;gt;id[i] = rom[sizeof(rom) - 2 - i];
			}
		}
	}
	return rv;
}

int iBSPACMonewireRequestTemperature_ni (void)
{
	if (! iBSPACMonewireReset_ni()) {
		return -1;
	}
	vBSPACMonewireWriteByte_ni(BSPACM_ONEWIRE_CMD_SKIP_ROM);
	vBSPACMonewireWriteByte_ni(BSPACM_ONEWIRE_CMD_CONVERT_T);
	return 0;
}

int iBSPACMonewireReadPowerSupply (void)
{
	int rv = -1;

	if (iBSPACMonewireReset_ni())
	{
		vBSPACMonewireWriteByte_ni(BSPACM_ONEWIRE_CMD_SKIP_ROM);
		vBSPACMonewireWriteByte_ni(BSPACM_ONEWIRE_CMD_READ_POWER_SUPPLY);
		rv = iBSPACMonewireReadBit_ni();
	}
	return rv;
}

int iBSPACMonewireReadTemperature_ni (int * temp_xCel)
{
	int t;

	if (! iBSPACMonewireReset_ni()) {
		return -1;
	}
	vBSPACMonewireWriteByte_ni(BSPACM_ONEWIRE_CMD_SKIP_ROM);
	vBSPACMonewireWriteByte_ni(BSPACM_ONEWIRE_CMD_READ_SCRATCHPAD);
	t = iBSPACMonewireReadByte_ni();
	t |= (iBSPACMonewireReadByte_ni() &amp;lt;&amp;lt; 8);
	*temp_xCel = t;
	return 0;
}

void DS18B20_Run(void)
{
	do
	{
		if (! iBSPACMonewireReset_ni()) {
			printf(&amp;quot;ERR: No DS18B20 present on P0.%u\n&amp;quot;, ONEWIRE_PIN);
			break;
		}

		static const char * const supply_type[] = { &amp;quot;parasitic&amp;quot;, &amp;quot;external&amp;quot; };

		int external_power = iBSPACMonewireReadPowerSupply();
		printf(&amp;quot;Power supply: %s\r\n&amp;quot;, supply_type[external_power]);
		if (0 &amp;gt; external_power) {
			printf(&amp;quot;ERROR: Device not present?\r\n&amp;quot;);
			break;
		}

		sBSPACMonewireSerialNumber serial;
		int rc = iBSPACMonewireReadSerialNumber(&amp;amp;serial);
		printf(&amp;quot;Serial got %d: \r\n&amp;quot;, rc);
		//abc	vBSPACMconsoleDisplayOctets(serial.id, sizeof(serial.id));
		//abc	putchar(&amp;#39;\n&amp;#39;);
#if 1
		while (0 == iBSPACMonewireRequestTemperature_ni())
		{
			int t_raw;
			nrf_delay_ms(600UL);
			while (! iBSPACMonewireReadBit_ni()) {
			}
			rc = iBSPACMonewireReadTemperature_ni(&amp;amp;t_raw);
			int t_dCel = (10 * t_raw) / 16;
			int t_dFahr = 320 + (9 * t_dCel) / 5;
			printf(&amp;quot;Got %d dCel, %d d[Fahr]\r\n&amp;quot;, t_dCel, t_dFahr);
		}
#endif
	} while (0);
	dirset();
	NRF_GPIO-&amp;gt;OUTCLR = ONEWIRE_BIT;

}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Would you please tell me how can I modify my code?&lt;/p&gt;
&lt;p&gt;Thank you&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Source code to get DS18B20 temperature feedback in nrf51822</title><link>https://devzone.nordicsemi.com/thread/146788?ContentTypeID=1</link><pubDate>Fri, 31 Aug 2018 13:01:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cd850193-690c-4328-8cca-745ac617c051</guid><dc:creator>Martin Lesund</dc:creator><description>&lt;p&gt;Hi Ives,&lt;/p&gt;
&lt;p&gt;Please check out &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/29003/nrf51822-and-one-wire"&gt;this thread.&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>