Connecting ds18b20 to nrf9160dk

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 "create_nordic_project.py failed (1)" saying "error: cmake failed". 

I am a complete beginner when using the development kit so please bear with my questions. 

I have added "CONFIG_GPIO" in the prj.conf file, is there anything else I should be adding. 

Additionally, should I be making changes to the cmake file? The link above only mentioned the .c and .h file so I wasn't sure what else should be changed. 

If anyone could help me with this or could point me to resources that will help me solve this, I would really appreciate it. 

Update : 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's building and running without any errors. (Would anybody know why this is).

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?

Parents
  • Hello Nandini,

    nrffan18 said:
    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. 

    Are you using k_usleep() for this? As documented, you should use the function with caution and probably adjust CONFIG_SYS_CLOCK_TICKS_PER_SEC as well.

    nrffan18 said:
    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?

    The default low frequency clock should be 32 kHz. Which value did you increase it from?

    nrffan18 said:
    I am approaching my deadline for my project really soon so any help would be really appreciated. Thank you!

    Have you tried to define a timer that indicates a toggle of the GPIO pin in its handler?

    Regards,

    Markus

Reply
  • Hello Nandini,

    nrffan18 said:
    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. 

    Are you using k_usleep() for this? As documented, you should use the function with caution and probably adjust CONFIG_SYS_CLOCK_TICKS_PER_SEC as well.

    nrffan18 said:
    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?

    The default low frequency clock should be 32 kHz. Which value did you increase it from?

    nrffan18 said:
    I am approaching my deadline for my project really soon so any help would be really appreciated. Thank you!

    Have you tried to define a timer that indicates a toggle of the GPIO pin in its handler?

    Regards,

    Markus

Children
  • Hi, 

    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't use that. 

    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. 

    What ended up working for me was replacing all the k_usleep()/k_sleep with k_busy_wait(). 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. 

    So it works now! thank you so much for all the help and helping me narrow down the issue. I really appreciate it. 

Related