Skip to main content
Associate
August 14, 2024
Question

DS18B20 not registering with internal pullup resistor

  • August 14, 2024
  • 2 replies
  • 1691 views

I am trying to use the DS18B20 temp sensor on a stm32h7 board to display the current temperature using putty, and if the temp is higher than 45 degrees celsius to display a heat warning, but for whatever reason the sensor is not beign registered. 

I have connected the vdd cable to the 5v pin and the data cable to the A2 pin, I have configured the A2 pin as Output Open Drain with pull-up and I think that the sensor is not being registered.
I have attached my code so far

I also get abnormal readings like these, no matter if the sensor is plugged in or not:
"""
Heat Warning! Current Temperature: 2693.75°C
Heat Warning! Current Temperature: 1515.38°C
Heat Warning! Current Temperature: 821.12°C
Heat Warning! Current Temperature: 3424.06°C
Heat Warning! Current Temperature: 1877.06°C
Heat Warning! Current Temperature: 2543.00°C
Heat Warning! Current Temperature: 2560.12°C
Heat Warning! Current Temperature: 1713.81°C
"""

I followed a lot with this tutorial: https://controllerstech.com/ds18b20-and-stm32/#google_vignette
So I think I got the delays correct but I am not entirely sure

Any help would be really appreciated

 

    2 replies

    Peter BENSCH
    Technical Moderator
    August 14, 2024

    Welcome @smakivic, to the community!

    you should check your main.c again. I've already found a few strange things when quickly looking over it:

    • in Set_Pin_Input() you use the parameters *GPIOx and GPIO_Pin, but then call DS18B20_PORT and DS18B20_PIN directly in the function. Why use parameters then for the function call?
    • In Set_Pin_Output() you set the GPIO to output push-pull. However, the DS18B20 uses a bidirectional line that should only float (and thus possibly supply the DS18B20 parasitically) or be pulled to GND (logical zero). You would therefore have to use OD = open drain here.

    Have you also verified the waveform on the bi-directional pin using a scope?

    Which compiler are you using?

    Which compiler optimisation have you set?

    Regards
    /Peter

    smakivicAuthor
    Associate
    August 15, 2024

    Im pretty sure that the compiler is arm-none-eabi-gcc and the optimisation is None (-O0)

    LCE
    Principal II
    August 15, 2024

    Tutorials aside, people should read datasheets.

    In the sensor's DS, I only see a 4k7 pull-up in each schematic.

    Compare that to the STM's pull-up, so no surprise here.