• AVR Freaks

Hot!DS18B20 reading problem with PIC18F4550 XC8

Author
jmxiqz
New Member
  • Total Posts : 13
  • Reward points : 0
  • Joined: 2020/10/02 13:04:17
  • Location: 0
  • Status: offline
2020/10/09 22:33:43 (permalink)
0

DS18B20 reading problem with PIC18F4550 XC8

Hello, I hope you can help me, I am trying to use the ds18b20 with the pic18f4550, I have been investigating a lot according to me my code should work but it does not work, according to me the problem is when starting the communication. If I declare adcon1 to configure the digital inputs the reset function returns 1, and the display show me "Error!", if I do not configure adcon1, the reset function returns 0 but the temperature reading is always 0
post edited by jmxiqz - 2020/10/09 22:52:47

Attached Image(s)

#1

9 Replies Related Threads

    du00000001
    Just Some Member
    • Total Posts : 3980
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: DS18B20 reading problem with PIC18F4550 XC8 2020/10/10 07:54:16 (permalink)
    +1 (1)
    I'd suggest to rename "Data_pin" "Data_In" and "Data_bus" "Data_Out".
    Thus it will become obvious that writing to Data_In is garbage. Remove these lines. All!
    (A single initialization of LATA2 to 0 is expected to suffice.)
     
    Then change TRISA = 0 to TRISA = 4 (main()) to initialize the data line to "H". - - - I somewhat assume the DS18... currently doesn't receive the reset signal correctly because the data line is already driven low prior your "init" function.
    The data line has to be a digital input, so setting RA2 as a digital input is ok.
     
    Following all this I'd suggest to use an oscilloscope or logic analyzer to monitor the activities on the data line and maybe debug some more issue(s).

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #2
    du00000001
    Just Some Member
    • Total Posts : 3980
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: DS18B20 reading problem with PIC18F4550 XC8 2020/10/10 08:13:05 (permalink)
    0
    P.S.: This thread is one more copy of   https://www.microchip.com/forums/m1154805.aspx

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #3
    jmxiqz
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2020/10/02 13:04:17
    • Location: 0
    • Status: offline
    Re: DS18B20 reading problem with PIC18F4550 XC8 2020/10/10 09:24:57 (permalink)
    0
    du00000001
    P.S.: This thread is one more copy of   https://www.microchip.com/forums/m1154805.aspx


    du00000001
    P.S.: This thread is one more copy of   https://www.microchip.com/forums/m1154805.aspx



    Hi, I'm sorry about the problem with the other user, but I would like to be able to solve my problem using PIC and not arduino, I have seen many tutorials in which the simulation works, I would like to be able to do it the same, that's why I post my problem, the same and there is something that I'm not considering software, by the way, how can I delete the repeated posts?
     
     
    #4
    du00000001
    Just Some Member
    • Total Posts : 3980
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: DS18B20 reading problem with PIC18F4550 XC8 2020/10/10 10:16:55 (permalink)
    +1 (1)
    You're running the software on a simulation? Which one?
    I do not trust any simulation - especially when it comes to simulate complex devices like the DS18B20.
     
    P.S.: AFAIK it's not possible to delete posts. So this ship has departed  :)

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #5
    jmxiqz
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2020/10/02 13:04:17
    • Location: 0
    • Status: offline
    Re: DS18B20 reading problem with PIC18F4550 XC8 2020/10/10 10:44:02 (permalink)
    0
    du00000001
    You're running the software on a simulation? Which one?
    I do not trust any simulation - especially when it comes to simulate complex devices like the DS18B20.
     
    P.S.: AFAIK it's not possible to delete posts. So this ship has departed  :)


     
    Well, I have tried it with PROTEUS 7, I always test my programs before doing them in physical and more or less wait for something, to date it has worked more or less well, I have been doing it and the same results that I obtain in the simulator I obtain in the physical circuit, at the moment I do not have access to a scope although if I could get one, maybe I can get a logical tip and try but then, as far as I have been able to observe the same results of the simulator are those that I obtain in the physical circuit, I couldn't get it to connect :( The circuit is the one that I put in the image, right now the only thing I'm looking for is to be able to make the connection, hehe
    #6
    du00000001
    Just Some Member
    • Total Posts : 3980
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: offline
    Re: DS18B20 reading problem with PIC18F4550 XC8 2020/10/10 13:56:32 (permalink)
    +1 (1)
    Might be you can check the correctness of your attempts on the DS18B20's data line, ... maybe not.
    If you haven't yet got the real hardware, you could give it a try. Check for the correct logic levels and timing. Just the same one would do with a scope/logic analyzer.

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #7
    jmxiqz
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2020/10/02 13:04:17
    • Location: 0
    • Status: offline
    Re: DS18B20 reading problem with PIC18F4550 XC8 2020/10/11 10:57:54 (permalink)
    0
    du00000001
    Might be you can check the correctness of your attempts on the DS18B20's data line, ... maybe not.
    If you haven't yet got the real hardware, you could give it a try. Check for the correct logic levels and timing. Just the same one would do with a scope/logic analyzer.




    Hello! Look, I change the code for an example that I found on the internet and I made the modifications that you told me, I still have not been able to get the oscilloscope but while I was thinking about measuring the signal in the simulation and it gives me a signal like the one in the image, really I don't know how the communication signal should be, could you explain what can be observed please? it may not mean anything hehehe At least as far as I can prove the physical
    post edited by jmxiqz - 2020/10/11 11:20:42

    Attached Image(s)

    #8
    jmxiqz
    New Member
    • Total Posts : 13
    • Reward points : 0
    • Joined: 2020/10/02 13:04:17
    • Location: 0
    • Status: offline
    Re: DS18B20 reading problem with PIC18F4550 XC8 2020/10/14 21:39:01 (permalink)
    0
    du00000001
    Might be you can check the correctness of your attempts on the DS18B20's data line, ... maybe not.
    If you haven't yet got the real hardware, you could give it a try. Check for the correct logic levels and timing. Just the same one would do with a scope/logic analyzer.




     
    Hello! I got a scope although it is analog but it can measure the signal from the sensor to the pic, and from what I can see it is very similar to the simulation but I don't know how to interpret it, could you help me?
    #9
    CiccioB
    Starting Member
    • Total Posts : 58
    • Reward points : 0
    • Joined: 2013/12/11 05:32:50
    • Location: 0
    • Status: offline
    Re: DS18B20 reading problem with PIC18F4550 XC8 2020/10/17 07:34:39 (permalink)
    +1 (1)
    It's a one-wire signal.
    You can look at its specification (also written is DS18B20 datasheet).
    In brief, zero are signaled with long low level periods and 1 are signaled with brief low level periods.
     
    On a higher level you have a command sent by your PIC and a answer (one byte or more) from the sensor.
    Just look at the DS18 datasheet, you should be able to identify the initial reset (mandatory), one of the sent ROM commands (mandatory) and its relative answer.
     
    You should however use a tool that can clearly show signals of 10us period.
     
     
    #10
    Jump to:
    © 2020 APG vNext Commercial Version 4.5