<?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>Connecting ds18b20 to nrf9160dk</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/85189/connecting-ds18b20-to-nrf9160dk</link><description>Hi, 
 I am looking to connect the ds18b20 sensor to the nrf9160dk. I followed this post, but when I tried running it, I was getting a &amp;quot;create_nordic_project.py failed (1)&amp;quot; saying &amp;quot;error: cmake failed&amp;quot;. 
 I am a complete beginner when using the development</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 19 Apr 2022 08:53:29 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/85189/connecting-ds18b20-to-nrf9160dk" /><item><title>RE: Connecting ds18b20 to nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/363487?ContentTypeID=1</link><pubDate>Tue, 19 Apr 2022 08:53:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:4910a09e-5b02-437b-a131-3519284991da</guid><dc:creator>nrffan18</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I tried your suggestions. Changing the CONFIG_SYS_CLOCK_TICKS_PER_SEC did reduce the delay, but the code would not run when I left debug mode. And since I needed this project to be portable, I couldn&amp;#39;t use that.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The timer suggestion works if you want to repeat something over the same interval, but my issue had a lot of delays and kind of made it difficult to incorporate this.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What ended up working for me was replacing all the k_usleep()/k_sleep with &lt;strong&gt;k_busy_wait()&lt;/strong&gt;. Its able to get down to 3 us accurately (when I do k_busy_wait(1), so there is a 2us delay) and that was enough for me to incorporate the ds18b20 sensor. If you need a 1us delay, I found not putting any delay seems to do the trick, though it might be a little inconsistent.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So it works now! thank you so much for all the help and helping me narrow down the issue. I really appreciate it.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ds18b20 to nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/360023?ContentTypeID=1</link><pubDate>Fri, 25 Mar 2022 13:41:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bdc30d3e-9076-4346-8a36-3194970764e2</guid><dc:creator>Albrecht Markus Schellenberger</dc:creator><description>&lt;p style="line-height:100%;margin-bottom:0;" lang="en-GB"&gt;Hello Nandini,&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
[quote user="nrffan18"]When doing the delay in ms, there is not much delay, but when doing in us, there is a delay of 50 us when going high, and 100 us when going low.&amp;nbsp;[/quote]
&lt;p style="line-height:100%;margin-bottom:0;" lang="en-GB"&gt;Are you using &lt;a href="https://github.com/zephyrproject-rtos/zephyr/blob/zephyr-v2.7.1/include/kernel.h#L456"&gt;k_usleep()&lt;/a&gt; for this? As documented, you should use the function with caution and probably adjust &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.1/kconfig/CONFIG_SYS_CLOCK_TICKS_PER_SEC.html#std-kconfig-CONFIG_SYS_CLOCK_TICKS_PER_SEC"&gt;CONFIG_SYS_CLOCK_TICKS_PER_SEC&lt;/a&gt; as well.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
[quote user="nrffan18"]I also noticed that the delay increases when I increase the clock speed to 25 kHz. Do you know why that is? And I also noticed that it briefly goes low when its high sometimes. (3rd screenshot below) Does anyone know why that is too?[/quote]
&lt;p style="line-height:100%;margin-bottom:0;" lang="en-GB"&gt;The default &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fps_nrf9160%2Fpmu_oscillators.html&amp;amp;cp=2_0_0_4_3_1&amp;amp;anchor=lfclk"&gt;low frequency clock&lt;/a&gt; should be 32 kHz. Which value did you increase it from?&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
[quote user="nrffan18"]I am approaching my deadline for my project really soon so any help would be really appreciated. Thank you![/quote]
&lt;p style="line-height:100%;margin-bottom:0;" lang="en-GB"&gt;Have you tried to define a &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.1/zephyr/reference/kernel/timing/timers.html#defining-a-timer"&gt;timer&lt;/a&gt; that indicates a toggle of the GPIO pin in its handler?&lt;br /&gt;&lt;br /&gt;Regards,&lt;/p&gt;
&lt;p style="line-height:100%;margin-bottom:0;" lang="en-GB"&gt;Markus&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ds18b20 to nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/359904?ContentTypeID=1</link><pubDate>Fri, 25 Mar 2022 04:30:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ce0b4a40-6d1f-4a28-8cd8-274875b64fe5</guid><dc:creator>nrffan18</dc:creator><description>&lt;p&gt;Hi &lt;a href="https://devzone.nordicsemi.com/members/markus-schellenberger"&gt;Albrecht Markus Schellenberger&lt;/a&gt;,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I tried running the blinky code that access info directly from the devicetree while placing a 2000us delay after setting on and a 1000 us delay after setting it off. When doing the delay in ms, there is not much delay, but when doing in us, there is a delay of 50 us when going high, and 100 us when going low.&amp;nbsp;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/700x500/__key/communityserver-discussions-components-files/4/logic-analyzer-4.JPG" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/700x700/__key/communityserver-discussions-components-files/4/logic-analyzer-5.JPG" /&gt;&lt;/p&gt;
&lt;p&gt;I also noticed that the delay increases when I increase the clock speed to 25 kHz. Do you know why that is? And I also noticed that it briefly goes low when its high sometimes. (3rd screenshot below) Does anyone know why that is too?&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/700x500/__key/communityserver-discussions-components-files/4/logic-analyzer-6.JPG" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/700x500/__key/communityserver-discussions-components-files/4/logic-analyzer-7.JPG" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/700x500/__key/communityserver-discussions-components-files/4/logic-analyzer-8.JPG" /&gt;&lt;/p&gt;
&lt;p&gt;I also didn&amp;#39;t notice anything weird when I debugged through the code.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I am approaching my deadline for my project really soon so any help would be really appreciated. Thank you!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ds18b20 to nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/359705?ContentTypeID=1</link><pubDate>Thu, 24 Mar 2022 06:37:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e1026e05-2e7d-4e80-a841-015a87d3290d</guid><dc:creator>Albrecht Markus Schellenberger</dc:creator><description>&lt;p style="line-height:100%;margin-bottom:0;" lang="en-GB"&gt;Hello Nandini,&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
[quote user="nrffan18"]&lt;p&gt;So now I know why it was sending me wrong values but I have no idea how to fix it. Can anyone please provide some guidance on what I can do to make the delays in my code execute more accurately without so much delay in switching between setting the pin High/Low?&lt;/p&gt;
&lt;p&gt;Is the issue that the clock is too slow? Or is there something else I should be doing?&lt;/p&gt;[/quote]
&lt;p style="line-height:100%;margin-bottom:0;" lang="en-GB"&gt;Here are my suggestions:&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li style="line-height:100%;margin-bottom:0;" lang="en-GB"&gt;Debug through the driver layer of your code and see if you can find something suspicious. For this, I recommend you to use &lt;a href="https://www.nordicsemi.com/Products/Development-tools/nRF-Connect-for-VS-Code"&gt;nRF Connect for VS Code&lt;/a&gt;.&lt;/li&gt;
&lt;li style="line-height:100%;margin-bottom:0;" lang="en-GB"&gt;Use the blinky sample as reference and connect the probe to the pin controlling the LED. Do you see the same delay there?&lt;/li&gt;
&lt;/ul&gt;
&lt;p style="line-height:100%;margin-bottom:0;" lang="en-GB"&gt;Regards,&lt;/p&gt;
&lt;p style="line-height:100%;margin-bottom:0;" lang="en-GB"&gt;Markus&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ds18b20 to nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/359484?ContentTypeID=1</link><pubDate>Wed, 23 Mar 2022 05:09:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:02ada403-d11b-4e83-a451-1bb3f42c14c9</guid><dc:creator>nrffan18</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/markus-schellenberger"&gt;Albrecht Markus Schellenberger&lt;/a&gt;,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I attempted to use the above function, but it is still not reading the values correctly, and the way it calculated the temperature is wrong. I managed to probe the data line with a logic analyzer and may have found the issue but I don&amp;#39;t know how to fix it. So it looks like there is a delay when setting the pin to low/high from the state it was in before.&lt;/p&gt;
&lt;p&gt;I tried only running the SetResolution function and this screenshot is the reset function that is called in the beginning of setResolution function. It should only be low for 480 us but is low for 558 us.&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/700x500/__key/communityserver-discussions-components-files/4/logic-analzer-1.JPG" /&gt;&lt;/p&gt;
&lt;p&gt;This delay is seen everywhere else, like this screenshot shows the first couple bits that are sent from the &amp;quot;sendbyte(SKIPROM)&amp;quot; command in SetResolution(). It is sending LSB first and should be sending 0,0,1,1,0,0,1,1. when sending 0&amp;#39;s, it should only be low for 65us but it is low for 157 us (1st screenshot). And when sending high, it should be low for only 10 us but it is low for 80 us (2nd screenshot). This causes an issue because in order to Write 1 to the DS18B20 sensor, it needs to switch to the high state within 15 us after being low (setting it low is what initializes the timeslot).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/700x500/__key/communityserver-discussions-components-files/4/logic-analyzer-2.JPG" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/700x500/__key/communityserver-discussions-components-files/4/logic-analyzer-3.JPG" /&gt;&lt;/p&gt;
&lt;p&gt;So now I know why it was sending me wrong values but I have no idea how to fix it. Can anyone please provide some guidance on what I can do to make the delays in my code execute more accurately without so much delay in switching between setting the pin High/Low?&lt;/p&gt;
&lt;p&gt;Is the issue that the clock is too slow? Or is there something else I should be doing?&lt;/p&gt;
&lt;p&gt;And here is my main.c, I changed the delays a little bit. Every other file is exactly the same. ( I apologize in advance for the large amounts of commented code.)&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;drivers/gpio.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;zephyr.h&amp;gt;
#include &amp;lt;device.h&amp;gt;
#include &amp;lt;devicetree.h&amp;gt;

#include &amp;quot;ds18b20.h&amp;quot;

#define GPIO0_LABEL DT_PROP(DT_NODELABEL(gpio0), label)
#define GPIO0_STATUS DT_PROP(DT_NODELABEL(gpio0), status)
#define DS_PIN 21

// Commands
#define STARTCONVO 0x44
#define READSCRATCH 0xBE
#define WRITESCRATCH 0x4E
#define SKIPROM 0xCC

// Scratchpad locations
#define TEMP_LSB        0
#define TEMP_MSB        1

// Device resolution
#define TEMP_9_BIT  0x1F //  9 bit
#define TEMP_10_BIT 0x3F // 10 bit
#define TEMP_11_BIT 0x5F // 11 bit
#define TEMP_12_BIT 0x7F // 12 bit

typedef uint8_t ScratchPad[9];

//Datasheet: https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf

static float temp = 0;
static const struct device *gpio_dev;


/**@brief Function for sending one bit to bus.
 */
void ds18b20_send(uint8_t bit)
{
    //nrf_gpio_cfg_output(DS_PIN);
    //nrf_gpio_pin_clear(DS_PIN);
    //nrf_delay_us(5);
    gpio_pin_set(gpio_dev, DS_PIN, 0);
    gpio_pin_configure(gpio_dev, DS_PIN, GPIO_OUTPUT);
    
    //k_usleep(10);

    if(bit==1)
    {   
        k_usleep(10);
        //nrf_gpio_pin_set(DS_PIN);
        gpio_pin_set(gpio_dev, DS_PIN, 1);
        k_usleep(55);

    }
    else
    {
        k_usleep(65);
        gpio_pin_set(gpio_dev, DS_PIN, 1);
        k_usleep(5);

    }
    //nrf_delay_us(80);
    //nrf_gpio_pin_set(DS_PIN);

    //k_usleep(60);
    //gpio_pin_set(gpio_dev, DS_PIN, 1);
    //k_usleep(2);
    
}


/**@brief Function for reading one bit from bus.
 */
unsigned char ds18b20_read(void)
{
    printf(&amp;quot;In ds18b20_read function&amp;quot;);
    unsigned char presence=0;
    
    //nrf_gpio_cfg_output(DS_PIN);
    //nrf_gpio_pin_clear(DS_PIN);
    //nrf_delay_us(2);

    //nrf_gpio_pin_set(DS_PIN);;
    //nrf_delay_us(15);

    //nrf_gpio_cfg_input(DS_PIN,NRF_GPIO_PIN_NOPULL);

    gpio_pin_configure(gpio_dev, DS_PIN, GPIO_OUTPUT_LOW);
    gpio_pin_set(gpio_dev, DS_PIN, 0);
    k_usleep(2);

    gpio_pin_set(gpio_dev, DS_PIN, 1);
    k_usleep(10);

    gpio_pin_configure(gpio_dev, DS_PIN, GPIO_INPUT);
    k_usleep(30);

    //if(nrf_gpio_pin_read(DS_PIN))
    if (gpio_pin_get_raw(gpio_dev, DS_PIN))
    {
        presence = 1;
    }
    else
    {
        presence = 0;
    }

    printf(&amp;quot;\npresence = %d\n&amp;quot;, presence);
    
    return presence;
}


/**@brief Function for sending one byte to bus.
 */
void ds18b20_send_byte(uint8_t data)
{
    printf(&amp;quot;In send_byte func, the byte of data in hex is %x\n and int %d\n&amp;quot;, data, data);
    uint8_t i;
    uint8_t x;
    for(i=0;i&amp;lt;8;i++)
    {
      x = data&amp;gt;&amp;gt;i;
      x &amp;amp;= 0x01;
      printf(&amp;quot;x=%d\n&amp;quot;,x);
      ds18b20_send(x);
    }
    //nrf_delay_us(100);
    //k_usleep(100);
}


/**@brief Function for reading one byte from bus.
 */
unsigned char ds18b20_read_byte(void)
{
    printf(&amp;quot;entering ds18b20_read_byte function\n&amp;quot;);
    unsigned char i;
    unsigned char data = 0;
    for (i=0;i&amp;lt;8;i++)
    {
        if(ds18b20_read()) data|=0x01&amp;lt;&amp;lt;i;
        //nrf_delay_us(15);
        k_usleep(15);
    }
    printf(&amp;quot;data = %c&amp;quot;, data);
    return(data);
}


/**@brief Function for sending reset pulse.
 */
unsigned char  ds18b20_reset(void)
{
  printf(&amp;quot;entering reset loop&amp;quot;);
  int presence=0;
  printf(&amp;quot;presence before = %d\n&amp;quot;, presence);

  //nrf_gpio_cfg_output(DS_PIN);
  //nrf_gpio_pin_clear(DS_PIN);

  //nrf_delay_us(500);
  //nrf_gpio_pin_set(DS_PIN);

  //nrf_gpio_cfg_input(DS_PIN,NRF_GPIO_PIN_NOPULL); // usikkert p? pull her. m? sjekkes
  //nrf_delay_us(30);

    gpio_pin_set(gpio_dev, DS_PIN, 0);
    gpio_pin_configure(gpio_dev, DS_PIN, GPIO_OUTPUT);
    

    k_usleep(480);
    gpio_pin_set(gpio_dev, DS_PIN, 1);
    gpio_pin_configure(gpio_dev, DS_PIN, GPIO_INPUT);
    k_usleep(30);

    if(gpio_pin_get_raw(gpio_dev, DS_PIN) == 0)
    {
        presence = 1;
    }
    else
    {
        presence = 0;
    }
    printf(&amp;quot;presence after 30 us = %d&amp;quot;, presence);

    //nrf_delay_us(470);
    k_usleep(470);

    if(gpio_pin_get_raw(gpio_dev, DS_PIN) == 1)
    {
        presence = 1;
    }
    else
    {
        presence = 0;
    }
  printf(&amp;quot;presence after 470 us is %d&amp;quot;, presence);
  return presence;

}


/**@brief Function for reading temperature.
 */
float ds18b20_get_temp(void)
{
    printf(&amp;quot;ENtering get_temp method\n&amp;quot;);

    unsigned int check;
    uint8_t temp1=0, temp2=0;

    check=ds18b20_reset();
    printf(&amp;quot;check from reset = %d\n&amp;quot;, check);
    if(check)
    {
        ds18b20_send_byte(SKIPROM); //Skip ROM.
        ds18b20_send_byte(0x44); //Start temp conversion.
        //nrf_delay_ms(600UL);
        k_msleep(600UL);
        check=ds18b20_reset();
        ds18b20_send_byte(SKIPROM); //Skip ROM.
        ds18b20_send_byte(0xBE); //Read temp from Scratchpad.
        temp1=ds18b20_read_byte();
        temp2=ds18b20_read_byte();
        check=ds18b20_reset();
        printf(&amp;quot;temp1=%d and temp2 = %d\n&amp;quot;, temp1, temp2);
        float temp=0;
        temp=(float)(temp1+(temp2*256))/16;
        printf(&amp;quot;temp = %6f\n&amp;quot;, temp);
        return temp;
    }
      return 0;
}


/**@brief Function for reading bit.
 */
uint8_t OneWire_read_bit(void)
{
    printf(&amp;quot;Inside OneWire_read_bit \n&amp;quot;);
    uint8_t r;

    //nrf_gpio_cfg_output(DS_PIN);
    //nrf_gpio_pin_clear(DS_PIN);
    //nrf_delay_us(3);
    //nrf_gpio_cfg_input(DS_PIN,NRF_GPIO_PIN_NOPULL);
    //nrf_delay_us(10);
    //r =nrf_gpio_pin_read(DS_PIN);
    //nrf_delay_us(53);
    gpio_pin_set(gpio_dev, DS_PIN, 0);
    gpio_pin_configure(gpio_dev, DS_PIN, GPIO_OUTPUT);
    k_usleep(3);
    //gpio_pin_set(gpio_dev, DS_PIN, 1);
    gpio_pin_configure(gpio_dev, DS_PIN, GPIO_INPUT);
    k_usleep(10);
    r = gpio_pin_get_raw(gpio_dev, DS_PIN);
    printk(&amp;quot;\nr = %d&amp;quot;, r); // COMMENTED THIS
    k_usleep(53);
    return r;
}


/**@brief Function for reading.
 */
uint8_t OneWire_read()
{
    printf(&amp;quot;inside OneWire_read function\n&amp;quot;);

    uint8_t bitMask;
    uint8_t r = 0;
    //bitMask = 0x00;
 
    /*for (int i=0; i&amp;lt;8; i++) {
      //bitMask = 0x01&amp;lt;&amp;lt;i;
      bitMask = 0x01 &amp;amp; OneWire_read_bit();
      bitMask = bitMask &amp;lt;&amp;lt; i;
      r |= bitMask;
    }*/

    for (bitMask = 0x01; bitMask; bitMask &amp;lt;&amp;lt;= 1) {
	if ( OneWire_read_bit()) r |= bitMask;
    }
    printf(&amp;quot;the byte in hex is %x\n&amp;quot;, r);
    return r;
}


/**@brief Function for reading scratchpad value
 */
void ds18b20_readScratchPad(uint8_t *scratchPad, uint8_t fields)
{
    printf(&amp;quot;Inside readScratcpad function\n&amp;quot;);
    ds18b20_reset();
    ds18b20_send_byte(SKIPROM);
    ds18b20_send_byte(READSCRATCH);

    for(uint8_t i=0; i &amp;lt; fields; i++)
    {
        scratchPad[i] = OneWire_read();
        printf(&amp;quot;Scratcpad[%d] = %x&amp;quot;, i, scratchPad[i]);

    }
    ds18b20_reset();
}


/**@brief Function for request temperature reading
 */
void ds18b20_requestTemperatures(void)
{
    printf(&amp;quot;inside Request Temperatures function\n&amp;quot;);
    ds18b20_reset();
    ds18b20_send_byte(SKIPROM);
    ds18b20_send_byte(STARTCONVO);
    k_msleep(750);
}


/**@brief Function for reading temperature method 2
 */
float ds18b20_get_temp_method_2(void)
{
    //printf(&amp;quot;entering get_temp_method_2&amp;quot;);
    //ds18b20_requestTemperatures();
    //unsigned char check;

    ScratchPad scratchPad;
    ds18b20_readScratchPad(scratchPad, 5);
    int16_t rawTemperature = (((int16_t)scratchPad[TEMP_MSB]) &amp;lt;&amp;lt; 8) | scratchPad[TEMP_LSB];
    //printf(&amp;quot;Raw temperature = %d\n&amp;quot;, rawTemperature);
    //float temp = 0.0625 * rawTemperature;
    //printf(&amp;quot;real temperature = %6f\n&amp;quot;, temp);

    return temp;
}


/**@brief Function for setting temperature resolution
 */
void ds18b20_setResolution(uint8_t resolution)
{
    ds18b20_reset();
    printf(&amp;quot;sending skip rom\n&amp;quot;);
    ds18b20_send_byte(SKIPROM);
    printf(&amp;quot;end of sending skip rom\n&amp;quot;);
    printf(&amp;quot;sending write scratch\n&amp;quot;);
    ds18b20_send_byte(WRITESCRATCH);
    printf(&amp;quot;end of sending write scratch\n&amp;quot;);
    printf(&amp;quot;sending T_H\n&amp;quot;);
    // two dummy values for LOW &amp;amp; HIGH ALARM
    ds18b20_send_byte(0x7D); // 125 C
    printf(&amp;quot;sending T_L\n&amp;quot;);
    ds18b20_send_byte(0xC9); // -55C
    printf(&amp;quot;sending conversion resolution\n&amp;quot;);
    switch (resolution)
    {
        case 12:
            ds18b20_send_byte(TEMP_12_BIT);
            break;

        case 11:
            ds18b20_send_byte(TEMP_11_BIT);
            break;

        case 10:
            ds18b20_send_byte(TEMP_10_BIT);
            break;

        case 9:
        default:
            ds18b20_send_byte(TEMP_9_BIT);
            break;
    }
    ds18b20_reset();
    printf(&amp;quot;exit set_Resolution() function&amp;quot;);
}

void main()
{
    gpio_dev = device_get_binding(GPIO0_LABEL);

    if (!gpio_dev) {
	    printk(&amp;quot;Error getting GPIO_0: failed.\n&amp;quot;);
    }
    
    
    //ds18b20_reset();
    
    
    ds18b20_setResolution(10);

    /*
    temp = ds18b20_get_temp_method_2();
    //temp = ds18b20_get_temp();
    printf(&amp;quot;Temperature: %.3f \r\n&amp;quot;, temp);

    
    while(1)
    {
        k_msleep(2000);
        temp = ds18b20_get_temp_method_2();
        //temp = ds18b20_get_temp();
        printf(&amp;quot;Temperature: %.3f \r\n&amp;quot;, temp);
    }*/
}


    


/** @} */
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ds18b20 to nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/359099?ContentTypeID=1</link><pubDate>Mon, 21 Mar 2022 11:53:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0fcfa4ac-a975-4ae8-9f53-d126c9f3e053</guid><dc:creator>Albrecht Markus Schellenberger</dc:creator><description>&lt;p style="line-height:100%;margin-bottom:0;" lang="en-GB"&gt;Hello Nandini,&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
[quote user="nrffan18"]&lt;p&gt;So in a situation, if I want to let the sensor know that it needs to go into a mode called &amp;quot;skip rom&amp;quot;, the master needs to send 0xCC to the sensor starting with the least significant bit (datasheet on page 11). What commands would I use to do this.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Additionally after this mode has been set, I would need to call a &amp;quot;Read Scratchpad&amp;quot; function (also on page 11 of the datasheet) by sending 0x44. Would I need to use the same command that I used to send the &amp;quot;Skip ROM&amp;quot; to do this function or is there a different procedure?&lt;/p&gt;[/quote]
&lt;p style="line-height:100%;margin-bottom:0;" lang="en-GB"&gt;Why are you not using the drivers to do this? The function below performs e.g. the steps you described.&lt;br /&gt;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**@brief Function for reading temperature.
 */
float ds18b20_get_temp(void)
{
    unsigned char check;
    char temp1=0, temp2=0;

    check=ds18b20_reset();
    if(check)
    {
        ds18b20_send_byte(0xCC); //Skip ROM.
        ds18b20_send_byte(0x44); //Start temp conversion.
        //nrf_delay_ms(600UL);
        k_sleep(K_MSEC(600UL));
        check=ds18b20_reset();
        ds18b20_send_byte(0xCC); //Skip ROM.
        ds18b20_send_byte(0xBE); //Read temp from Scratchpad.
        temp1=ds18b20_read_byte();
        temp2=ds18b20_read_byte();
        check=ds18b20_reset();
        float temp=0;
        temp=(float)(temp1+(temp2*256))/16;
        return temp;
    }
      return 0;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p style="line-height:100%;margin-bottom:0;" lang="en-GB"&gt;Regards,&lt;/p&gt;
&lt;p style="line-height:100%;margin-bottom:0;" lang="en-GB"&gt;Markus&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ds18b20 to nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/358947?ContentTypeID=1</link><pubDate>Sat, 19 Mar 2022 06:16:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:16b01e6e-3eae-453d-aa9b-ebabe25041ce</guid><dc:creator>nrffan18</dc:creator><description>&lt;p&gt;Hi &lt;a href="https://devzone.nordicsemi.com/members/markus-schellenberger"&gt;Albrecht Markus Schellenberger&lt;/a&gt;,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;thank you for the feedback. I am currently examining the logic for sending/receiving commands to the ds18b20 and I had a question.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So in a situation, if I want to let the sensor know that it needs to go into a mode called &amp;quot;skip rom&amp;quot;, the master needs to send 0xCC to the sensor starting with the least significant bit (datasheet on page 11). What commands would I use to do this.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Additionally after this mode has been set, I would need to call a &amp;quot;Read Scratchpad&amp;quot; function (also on page 11 of the datasheet) by sending 0x44. Would I need to use the same command that I used to send the &amp;quot;Skip ROM&amp;quot; to do this function or is there a different procedure?&lt;/p&gt;
&lt;p&gt;Thanks.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ds18b20 to nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/358889?ContentTypeID=1</link><pubDate>Fri, 18 Mar 2022 13:53:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b612f4da-5343-472b-9e0e-afbcb6d67dde</guid><dc:creator>Albrecht Markus Schellenberger</dc:creator><description>&lt;p style="line-height:100%;margin-bottom:0;" lang="en-GB"&gt;Hello Nandini,&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
[quote user="nrffan18"]Also for the temperature reading issue, I noticed this post for a nrf52832-&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/70069/interfacing-nrf52832-with-ds18b20"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/70069/interfacing-nrf52832-with-ds18b20&lt;/a&gt;&amp;nbsp;where they use an external crystal oscillator as the timer. Do you think this could solve my issue and if that is the case, what would be the equivalent for the nrf9160, I am unable to find it for some reason?[/quote]
&lt;p style="line-height:100%;margin-bottom:0;"&gt;&lt;span lang="en-GB"&gt;I’m not quite sure if this is necessary. When running the drivers, are you able to see any traffic on the GPIO pin connected to the sensor? If so, does the bit flow &lt;/span&gt;&lt;span lang="en-GB"&gt;pattern match&lt;/span&gt;&lt;span lang="en-GB"&gt; the sensor specification?&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
[quote user="nrffan18"]&lt;p&gt;Also I eventually will also be inculcating a SD card with the board. So in that case, what pin/pin range would you recommend using for my temperature sensor?&lt;/p&gt;
&lt;p&gt;And what pins should I use for the sd card?&lt;/p&gt;[/quote]
&lt;p style="line-height:100%;margin-bottom:0;"&gt;&lt;span lang="en-GB"&gt;You can freely decide that for yourself :-) I recommend you having a look at &lt;em&gt;../&amp;lt;your_build_folder&amp;gt;/zephyr/zephyr.dts&lt;/em&gt;. The content of this file gives you a nice devicetree overview of your board.&lt;br /&gt;&lt;br /&gt;Regards,&lt;/span&gt;&lt;/p&gt;
&lt;p style="line-height:100%;margin-bottom:0;"&gt;Markus&lt;span lang="en-GB"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ds18b20 to nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/358743?ContentTypeID=1</link><pubDate>Thu, 17 Mar 2022 20:29:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9cc1674c-4169-4789-98d0-48bd13f57f49</guid><dc:creator>nrffan18</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/members/markus-schellenberger"&gt;Albrecht Markus Schellenberger&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Is it ok to continue configuring the gpio the way I am currently doing? Because I have multiple sensors I don&amp;#39;t feel comfortable changing the overlay file like that.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Also I eventually will also be inculcating a SD card with the board. So in that case, what pin/pin range would you recommend using for my temperature sensor?&lt;/p&gt;
&lt;p&gt;And what pins should I use for the sd card?&lt;/p&gt;
&lt;p&gt;Also for the temperature reading issue, I noticed this post for a nrf52832-&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/70069/interfacing-nrf52832-with-ds18b20"&gt;https://devzone.nordicsemi.com/f/nordic-q-a/70069/interfacing-nrf52832-with-ds18b20&lt;/a&gt;&amp;nbsp;where they use an external crystal oscillator as the timer. Do you think this could solve my issue and if that is the case, what would be the equivalent for the nrf9160, I am unable to find it for some reason?&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: Connecting ds18b20 to nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/358666?ContentTypeID=1</link><pubDate>Thu, 17 Mar 2022 13:24:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:31d50c48-6c26-4ca5-bb19-6d37f311c85c</guid><dc:creator>Albrecht Markus Schellenberger</dc:creator><description>[quote user="nrffan18"]Just to take care of any preliminary reasons, is it alright for me to be using pin 1 to read the sensor.[/quote]
&lt;p style="line-height:100%;margin-bottom:0;" lang="en-GB"&gt;By default, pin 1 is &lt;a href="https://github.com/zephyrproject-rtos/zephyr/blob/zephyr-v2.7.1/boards/arm/nrf9160dk_nrf9160/nrf9160dk_nrf9160_common.dts#L171"&gt;assigned&lt;/a&gt; to the tx-line of UART1 on the nRF9160 DK, but since the peripheral is disabled by default you should be good to go.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
[quote user="nrffan18"]And I currently havent changed anything in the device tree either, is the way I am configuring the gpio pin correct?[/quote]
&lt;p style="line-height:100%;margin-bottom:0;" lang="en-GB"&gt;There are several ways to (re-)configure the device tree, but the “most correct” one is to use &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.1/zephyr/guides/dts/howtos.html#set-devicetree-overlays"&gt;overlay files&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p style="line-height:100%;margin-bottom:0;" lang="en-GB"&gt;Regards,&lt;/p&gt;
&lt;p style="line-height:100%;margin-bottom:0;" lang="en-GB"&gt;Markus&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ds18b20 to nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/358561?ContentTypeID=1</link><pubDate>Thu, 17 Mar 2022 09:01:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:55924042-8aa9-41fe-965f-d323ea49435a</guid><dc:creator>nrffan18</dc:creator><description>&lt;p&gt;Hi,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thank you for the feedback. Just to take care of any preliminary reasons, is it alright for me to be using pin 1 to read the sensor. And I currently havent changed anything in the device tree either, is the way I am configuring the gpio pin correct?&lt;/p&gt;
&lt;p&gt;Thank you for your help.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ds18b20 to nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/355431?ContentTypeID=1</link><pubDate>Tue, 01 Mar 2022 07:26:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2157a556-9115-4dfc-9ccf-600a54d6772d</guid><dc:creator>Albrecht Markus Schellenberger</dc:creator><description>&lt;p lang="en-GB"&gt;Hello Nandini,&lt;/p&gt;
[quote user="nrffan18"]What exactly would I be looking for when examining the dataflow with the logic analyzer/Oscilloscope?[/quote]
&lt;p lang="en-GB"&gt;I’m not familiar with the DS18B20 sensor myself, but if you look at the specification for the 1-wire bus (which you e.g. can do in this &lt;a href="https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf"&gt;data sheet&lt;/a&gt; on page 10), you can find its requirements there.&lt;/p&gt;
[quote user="nrffan18"]I can get access to an oscilloscope so that might be mostly what I use. I am already aware that it is currently sending all the bits as 1 right now so what would be the next step in checking the data flow?[/quote]
&lt;p&gt;What you have to verify is that your driver layer sends data/bits according to this specification and that the nRF9160 GPIO &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fps_nrf9160%2Fgpio.html&amp;amp;cp=2_0_0_5_3_1&amp;amp;anchor=unique_343024053"&gt;sense mechanism&lt;/a&gt; is configured correctly in order to be able to receive data/bits.&lt;/p&gt;
&lt;p lang="en-GB"&gt;Regards,&lt;/p&gt;
&lt;p lang="en-GB"&gt;Markus&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ds18b20 to nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/355428?ContentTypeID=1</link><pubDate>Tue, 01 Mar 2022 07:07:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0bd14e7e-a75d-42d7-ba13-6a14d8ca34fe</guid><dc:creator>nrffan18</dc:creator><description>&lt;p&gt;Hi Markus,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thank you for the response. I apologize if the questions are repetitive. What exactly would I be looking for when examining the dataflow with the logic analyzer/Oscilloscope? I can get access to an oscilloscope so that might be mostly what I use. I am already aware that it is currently sending all the bits as 1 right now so what would be the next step in checking the data flow?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ds18b20 to nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/355425?ContentTypeID=1</link><pubDate>Tue, 01 Mar 2022 06:57:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a51952e2-fca8-4a22-9022-911349cf2762</guid><dc:creator>Albrecht Markus Schellenberger</dc:creator><description>&lt;p lang="en-GB"&gt;Hello Nandini,&lt;/p&gt;
[quote user="nrffan18"]I&amp;#39;m assuming I should be adding it with the label &amp;quot;GPIO_0&amp;quot; since that was what was configured in the initial function in ds18b20.c file?[/quote]
&lt;p&gt;&lt;span lang="en-GB"&gt;My recommendation would be to connect the GPIO pin you would like to use to a LED on the nRF9160 DK first, as demonstrated in the Blinky sample. This way you can verify that the devicetree configuration of your application is correct. Afterwards, you can switch the pin direction and check if the sense mechanism works as expected.&lt;/span&gt;&lt;/p&gt;
[quote user="nrffan18"]Does anyone have any idea on how to fix this? I do not have access to a logic analyzer right now.[/quote]
&lt;p&gt;&lt;span lang="en-GB"&gt;Since you would like to implement a sensor driver which not directly is integrated into the Zephyr RTOS, I recommend you to verify the &lt;/span&gt;&lt;span lang="en-GB"&gt;dataflow on the configured pin with a logic analyser or oscilloscope.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span lang="en-GB"&gt;Regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span lang="en-GB"&gt;Markus&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ds18b20 to nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/355412?ContentTypeID=1</link><pubDate>Tue, 01 Mar 2022 03:19:28 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:da8a6358-dfb3-4209-842b-7c3c48d19e49</guid><dc:creator>nrffan18</dc:creator><description>&lt;p&gt;Update: I managed to get it printing values to the lte_modem. Ended up moving everything to the main.c folder, added the suggestion from &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/72618/extra-gpios-in-board-overlay-for-nrf9160dk"&gt;this&lt;/a&gt; post and added in &lt;span&gt;prj.conf::&lt;/span&gt;&lt;span&gt;CONFIG_NEWLIB_LIBC=y and CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y. But now I am getting the same error as the original post that did this (I am getting the temperature as -0.062 every time.)&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Does anyone have any idea on how to fix this? I do not have access to a logic analyzer right now.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;a href="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1646104587308v1.png"&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/500x500/__key/communityserver-discussions-components-files/4/pastedimage1646104587308v1.png" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ds18b20 to nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/355380?ContentTypeID=1</link><pubDate>Mon, 28 Feb 2022 20:35:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d513214d-3817-4b3f-a95b-cd19b2c0c9b2</guid><dc:creator>nrffan18</dc:creator><description>&lt;p&gt;Also looks like the voltage on the 5V pin is correct. Apologies for that&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ds18b20 to nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/355310?ContentTypeID=1</link><pubDate>Mon, 28 Feb 2022 14:13:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bf258228-d585-44bc-8178-529e043cd02e</guid><dc:creator>nrffan18</dc:creator><description>&lt;p&gt;&amp;nbsp;Hi Markus,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;What is the correct format for the GPIO device tree and how do I go about adding it correctly in a way that doesn&amp;#39;t mess with anything else?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m assuming I should be adding it with the label &amp;quot;GPIO_0&amp;quot; since that was what was configured in the initial function in ds18b20.c file?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ds18b20 to nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/355275?ContentTypeID=1</link><pubDate>Mon, 28 Feb 2022 13:01:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:79594bc9-cfb1-4c62-a321-ee9f63cefb38</guid><dc:creator>Albrecht Markus Schellenberger</dc:creator><description>&lt;p lang="en-GB"&gt;Hello Nandini,&lt;/p&gt;
[quote user="nrffan18"]I think you might have misunderstood.[/quote]
&lt;p lang="en-GB"&gt;My apologies for misunderstanding you.&lt;/p&gt;
[quote user="nrffan18"]Do you happen to know why this might be?[/quote]
&lt;p lang="en-GB"&gt;I assume that the devicetree configuration for the GPIO is not completely correct. In your &lt;em&gt;main.c&lt;/em&gt;, I for instance can’t see that the necessary device binding in the &lt;em&gt;Init_GPIO()&lt;/em&gt; function is called. This should at least trigger a warning during compilation, when using a not initialised device with the &lt;em&gt;gpio_pin_configure()&lt;/em&gt; function.&lt;/p&gt;
[quote user="nrffan18"]Additionally I was wondering if you knew how to print to the debug terminal.&amp;nbsp;[/quote]
&lt;p lang="en-GB"&gt;I recommend you to use the printk command, as illustrated in the &lt;a href="https://github.com/zephyrproject-rtos/zephyr/blob/zephyr-v2.7.1/samples/hello_world/src/main.c#L12"&gt;Hello World&lt;/a&gt; sample.&lt;/p&gt;
[quote user="nrffan18"]Additionally I noticed that I was not getting 5V output from the 5V pin on the nrf9160dk. Do I need to add a configuration in the prj.conf file to enable this?[/quote]
&lt;p lang="en-GB"&gt;What voltage do you measure on the 5V pin?&lt;/p&gt;
&lt;p lang="en-GB"&gt;&lt;/p&gt;
&lt;p lang="en-GB"&gt;Regards,&lt;/p&gt;
&lt;p lang="en-GB"&gt;Markus&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ds18b20 to nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/355172?ContentTypeID=1</link><pubDate>Mon, 28 Feb 2022 07:41:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:43b28644-8267-4164-a790-f0344bd458ca</guid><dc:creator>nrffan18</dc:creator><description>&lt;p&gt;Hi Markus,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I think you might have misunderstood. Essentially I am trying to read the input from a ds18b20 sensor (uses one-wire interface) using the nrf9160dk. I was using the code referred to in &lt;a href="https://devzone.nordicsemi.com/f/nordic-q-a/80909/ds18b20-with-nrf9160"&gt;this&lt;/a&gt; post to try and read values from the sensor. I used the blinky sample as a base but replaced all the code in the original main file with the code in the post and added the ds18b20.c and ds18b20. files. But I am not seeing any output and I don&amp;#39;t understand why.&lt;/p&gt;
&lt;p&gt;Do you happen to know why this might be? Additionally I was wondering if you knew how to print to the debug terminal.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I have added my files below (essentially the same as the one in the post)&lt;/p&gt;
&lt;p&gt;This is the main.c file&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;//THIS IS THE MAIN.C FILE

#include &amp;lt;drivers/gpio.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;

#include &amp;quot;ds18b20.h&amp;quot;

//Datasheet: https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf

static float temp = 0;

void main()
{
    ds18b20_setResolution(12);

    temp = ds18b20_get_temp_method_2();
    printf(&amp;quot;Temperature: %.3f \r\n&amp;quot;, temp);


    while(1)
    {
        k_sleep(K_MSEC(2000));
        temp = ds18b20_get_temp_method_2();
        printf(&amp;quot;Temperature: %.3f \r\n&amp;quot;, temp);
    }
}


/** @} */&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This is the ds18b20.h file&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#THIS IS ds18b20.h

float ds18b20_get_temp(void);
void ds18b20_setResolution(uint8_t resolution);
float ds18b20_get_temp_method_2(void);
/** @} */&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This is the ds18b20.c file&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;//THIS IS ds18b20.c

#include &amp;lt;drivers/gpio.h&amp;gt;

#include &amp;quot;ds18b20.h&amp;quot;

#define DS_PIN 1

// Commands
#define STARTCONVO      0x44
#define READSCRATCH     0xBE
#define WRITESCRATCH    0x4E

// Scratchpad locations
#define TEMP_LSB        0
#define TEMP_MSB        1

// Device resolution
#define TEMP_9_BIT  0x1F //  9 bit
#define TEMP_10_BIT 0x3F // 10 bit
#define TEMP_11_BIT 0x5F // 11 bit
#define TEMP_12_BIT 0x7F // 12 bit

typedef uint8_t ScratchPad[9];
static const struct device *gpio_dev;

/**@brief Function for sending one bit to bus.
 */
void ds18b20_send(char bit)
{
    //nrf_gpio_cfg_output(DS_PIN);
    //nrf_gpio_pin_clear(DS_PIN);
    //nrf_delay_us(5);

    gpio_pin_configure(gpio_dev, DS_PIN, GPIO_OUTPUT_LOW);
    gpio_pin_set(gpio_dev, DS_PIN, 0);
    k_sleep(K_USEC(5));

    if(bit==1)
    {
        //nrf_gpio_pin_set(DS_PIN);
        gpio_pin_set(gpio_dev, DS_PIN, 1);
    }
    //nrf_delay_us(80);
    //nrf_gpio_pin_set(DS_PIN);

    k_sleep(K_USEC(80));
    gpio_pin_set(gpio_dev, DS_PIN, 1);
    
}


/**@brief Function for reading one bit from bus.
 */
unsigned char ds18b20_read(void)
{
    unsigned char presence=0;
    
    //nrf_gpio_cfg_output(DS_PIN);
    //nrf_gpio_pin_clear(DS_PIN);
    //nrf_delay_us(2);

    //nrf_gpio_pin_set(DS_PIN);;
    //nrf_delay_us(15);

    //nrf_gpio_cfg_input(DS_PIN,NRF_GPIO_PIN_NOPULL);

    gpio_pin_configure(gpio_dev, DS_PIN, GPIO_OUTPUT_LOW);
    gpio_pin_set(gpio_dev, DS_PIN, 0);
    k_sleep(K_USEC(2));

    gpio_pin_set(gpio_dev, DS_PIN, 1);
    k_sleep(K_USEC(15));

    gpio_pin_configure(gpio_dev, DS_PIN, GPIO_INPUT);

    //if(nrf_gpio_pin_read(DS_PIN))
    if (gpio_pin_get_raw(gpio_dev, DS_PIN))
    {
        presence = 1;
    }
    else
    {
        presence = 0;
    }

    printk(&amp;quot;\npresence = %d&amp;quot;, presence);
    
    return presence;
}


/**@brief Function for sending one byte to bus.
 */
void ds18b20_send_byte(char data)
{
    unsigned char i;
    unsigned char x;
    for(i=0;i&amp;lt;8;i++)
    {
      x = data&amp;gt;&amp;gt;i;
      x &amp;amp;= 0x01;
      ds18b20_send(x);
    }
    //nrf_delay_us(100);
    k_sleep(K_USEC(100));
}


/**@brief Function for reading one byte from bus.
 */
unsigned char ds18b20_read_byte(void)
{
    unsigned char i;
    unsigned char data = 0;
    for (i=0;i&amp;lt;8;i++)
    {
        if(ds18b20_read()) data|=0x01&amp;lt;&amp;lt;i;
        //nrf_delay_us(15);
        k_sleep(K_USEC(15));
    }
    return(data);
}


/**@brief Function for sending reset pulse.
 */
unsigned char ds18b20_reset(void)
{
  unsigned char presence;

  //nrf_gpio_cfg_output(DS_PIN);
  //nrf_gpio_pin_clear(DS_PIN);

  //nrf_delay_us(500);
  //nrf_gpio_pin_set(DS_PIN);

  //nrf_gpio_cfg_input(DS_PIN,NRF_GPIO_PIN_NOPULL); // usikkert p? pull her. m? sjekkes
  //nrf_delay_us(30);

    gpio_pin_configure(gpio_dev, DS_PIN, GPIO_OUTPUT_LOW);
    gpio_pin_set(gpio_dev, DS_PIN, 0);

    k_sleep(K_USEC(500));
    gpio_pin_set(gpio_dev, DS_PIN, 1);

    gpio_pin_configure(gpio_dev, DS_PIN, GPIO_INPUT);
    k_sleep(K_USEC(30));

    if(gpio_pin_get_raw(gpio_dev, DS_PIN) == 0)
    {
        presence = 1;
    }
    else
    {
        presence = 0;
    }

    //nrf_delay_us(470);
    k_sleep(K_USEC(470));

    if(gpio_pin_get_raw(gpio_dev, DS_PIN) == 1)
    {
        presence = 1;
    }
    else
    {
        presence = 0;
    }

  return presence;
}


/**@brief Function for reading temperature.
 */
float ds18b20_get_temp(void)
{
    unsigned char check;
    char temp1=0, temp2=0;

    check=ds18b20_reset();
    if(check)
    {
        ds18b20_send_byte(0xCC); //Skip ROM.
        ds18b20_send_byte(0x44); //Start temp conversion.
        //nrf_delay_ms(600UL);
        k_sleep(K_MSEC(600UL));
        check=ds18b20_reset();
        ds18b20_send_byte(0xCC); //Skip ROM.
        ds18b20_send_byte(0xBE); //Read temp from Scratchpad.
        temp1=ds18b20_read_byte();
        temp2=ds18b20_read_byte();
        check=ds18b20_reset();
        float temp=0;
        temp=(float)(temp1+(temp2*256))/16;
        return temp;
    }
      return 0;
}


/**@brief Function for reading bit.
 */
uint8_t OneWire_read_bit(void)
{
    uint8_t r;

    //nrf_gpio_cfg_output(DS_PIN);
    //nrf_gpio_pin_clear(DS_PIN);
    //nrf_delay_us(3);
    //nrf_gpio_cfg_input(DS_PIN,NRF_GPIO_PIN_NOPULL);
    //nrf_delay_us(10);
    //r =nrf_gpio_pin_read(DS_PIN);
    //nrf_delay_us(53);

    gpio_pin_configure(gpio_dev, DS_PIN, GPIO_OUTPUT_LOW);
    gpio_pin_set(gpio_dev, DS_PIN, 0);
    k_sleep(K_USEC(3));
    gpio_pin_configure(gpio_dev, DS_PIN, GPIO_INPUT);
    k_sleep(K_USEC(10));
    r = gpio_pin_get_raw(gpio_dev, DS_PIN);
    printk(&amp;quot;\nr = %d&amp;quot;, r);
    k_sleep(K_USEC(53));
    return r;
}


/**@brief Function for reading.
 */
uint8_t OneWire_read()
{
    uint8_t bitMask;
    uint8_t r = 0;

    for (bitMask = 0x01; bitMask; bitMask &amp;lt;&amp;lt;= 1) {
	if ( OneWire_read_bit()) r |= bitMask;
    }
    return r;
}


/**@brief Function for reading scratchpad value
 */
void ds18b20_readScratchPad(uint8_t *scratchPad, uint8_t fields)
{
    ds18b20_reset();
    ds18b20_send_byte(0xCC);
    ds18b20_send_byte(READSCRATCH);

    for(uint8_t i=0; i &amp;lt; fields; i++)
    {
        scratchPad[i] = OneWire_read();

    }
    ds18b20_reset();
}


/**@brief Function for request temperature reading
 */
void ds18b20_requestTemperatures(void)
{
    ds18b20_reset();
    ds18b20_send_byte(0xCC);
    ds18b20_send_byte(STARTCONVO);
}


/**@brief Function for reading temperature method 2
 */
float ds18b20_get_temp_method_2(void)
{
    ds18b20_requestTemperatures();
    unsigned char check;

    ScratchPad scratchPad;
    ds18b20_readScratchPad(scratchPad, 2);
    int16_t rawTemperature = (((int16_t)scratchPad[TEMP_MSB]) &amp;lt;&amp;lt; 8) | scratchPad[TEMP_LSB];
    float temp = 0.0625 * rawTemperature;

    return temp;
}


/**@brief Function for setting temperature resolution
 */
void ds18b20_setResolution(uint8_t resolution)
{
    ds18b20_reset();
    ds18b20_send_byte(0xCC);
    ds18b20_send_byte(WRITESCRATCH);
    // two dummy values for LOW &amp;amp; HIGH ALARM
    ds18b20_send_byte(0);
    ds18b20_send_byte(100);
    switch (resolution)
    {
        case 12:
            ds18b20_send_byte(TEMP_12_BIT);
            break;

        case 11:
            ds18b20_send_byte(TEMP_11_BIT);
            break;

        case 10:
            ds18b20_send_byte(TEMP_10_BIT);
            break;

        case 9:
        default:
            ds18b20_send_byte(TEMP_9_BIT);
            break;
    }
    ds18b20_reset();
}

/*Funcion para inicializar GPIO*/

void Init_GPIO(){

    gpio_dev = device_get_binding(&amp;quot;GPIO_0&amp;quot;);
    if (!gpio_dev) {
	    printk(&amp;quot;Error getting GPIO_0: failed.\n&amp;quot;);
    }

}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This is the prj.conf file&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_GPIO=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Ultimately I want to read the sensor values at regular intervals and print the values to the debug terminal/lte link monitor. Is there something wrong with the code.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Additionally I noticed that I was not getting 5V output from the 5V pin on the nrf9160dk. Do I need to add a configuration in the prj.conf file to enable this?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Connecting ds18b20 to nrf9160dk</title><link>https://devzone.nordicsemi.com/thread/355169?ContentTypeID=1</link><pubDate>Mon, 28 Feb 2022 07:19:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:71db95fa-2122-4d6c-92b2-5608b5862d77</guid><dc:creator>Albrecht Markus Schellenberger</dc:creator><description>&lt;p lang="en-GB"&gt;Hello Nandini,&lt;/p&gt;
[quote user=""]My issue now is that it is not printing any values or anything to the Debug terminal on SES or the LTE Link Monitor. Does anyone know why this may be?[/quote]
&lt;p lang="en-GB"&gt;The blinky sample does not print anything to the terminal by default, more than the booting sequence. Have you added any “printk/printf” or “LOG_xxx” line to it that won’t show up in the application log?&lt;/p&gt;
[quote user=""]&lt;strong&gt;Update&amp;nbsp;&lt;/strong&gt;: The code is now running without any build errors but not printing any values. I had been using the hello_world sample to run it before which was giving the error, but then I tried switching to the blinky sample and running on that and it&amp;#39;s building and running without any errors. (Would anybody know why this is).[/quote]
&lt;p lang="en-GB"&gt;This is hard to say without a build log. Can you build the hello_world sample via the &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.0/nrf/gs_programming.html#building-on-the-command-line"&gt;command line&lt;/a&gt; and share the application log?&lt;/p&gt;
&lt;p lang="en-GB"&gt;&lt;/p&gt;
&lt;p lang="en-GB"&gt;Thanks &amp;amp; regards,&lt;/p&gt;
&lt;p lang="en-GB"&gt;Markus&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>