2020/10/08 12:01:33
jmxiqz
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 0, if I do not configure adcon1, the reset function returns 0 but the temperature reading is always 0


2020/10/09 15:14:47
ric
If you're using XC8, why did you put this post in the C18 forum?

If I declare adcon1 to configure the digital inputs the reset function returns 0, if I do not configure adcon1, the reset function returns 0 but the temperature reading is always 0

Your code simply will not work if you leave pin RA2 in analog mode, so don't waste time trying it without configuring ADCON1.
Does any of your LCD code access other pins on PORTA?
If it makes the same mistake, of writing to the PORTA register (e.g. using RA2) rather than the LATA register (LATA2), then it will lose the low setting on LATA2, stopping your one-wire logic working at all.
 
I can't check as you have not shown that code or mentioned how the other pins on your PIC are wired up.
 
 
 
2020/10/09 17:48:38
jmxiqz
ric
If you're using XC8, why did you put this post in the C18 forum?

If I declare adcon1 to configure the digital inputs the reset function returns 0, if I do not configure adcon1, the reset function returns 0 but the temperature reading is always 0

Your code simply will not work if you leave pin RA2 in analog mode, so don't waste time trying it without configuring ADCON1.
Does any of your LCD code access other pins on PORTA?
If it makes the same mistake, of writing to the PORTA register (e.g. using RA2) rather than the LATA register (LATA2), then it will lose the low setting on LATA2, stopping your one-wire logic working at all.
 
I can't check as you have not shown that code or mentioned how the other pins on your PIC are wired up.
 
 
 




Hello sorry, I realized too late, my post had already been approved, in fact it is the first time I ask in this microchip forum, whatever, yeah! I know the pin needs to be set digital, I tried but it's when the reset function returns 1 and the sensor never connects, it's actually part of a larger system so almost all other pins are busy, the LCD is connected to port D, RA0 and RA1 are push buttons and the other pins of port A are free and are only configured as inputs with TRISA, from port b only RB2, RB3 are free, because I use RB0 and RB1 to read an RTC and from RB4 to RB7 I use them as external interrupts, almost all port C is free and the three pins of port E, I have tried with each one and I have not been able to make the sensor connect, I have tested it with LATA, with PORTA, configured ADCON1 and nothing :( In that example, for example, if I configure adcon1 and I don't use anything else, there's no reason why it doesn't work, or at least that's what my logic tells me hehehe
2020/10/09 18:43:41
ric
Forget about the other pooirts, it's only PORTA that matters in this case.
I can't help with all the other things you have tried if you don't actually show them.
Are you able to examine what the pin is actually doing with a scope?
 
2020/10/09 18:59:41
jmxiqz
PORTA_Config.c
ric
Forget about the other pooirts, it's only PORTA that matters in this case.
I can't help with all the other things you have tried if you don't actually show them.
Are you able to examine what the pin is actually doing with a scope?
 




Hi, no, unfortunately I don't have access to an oscilloscope, but if I can pass you some of the code I use, pins 0, 1, 4 and 5 are for push buttons that I use to navigate the LCD, I configure PORT A with TRISA as input And it doesn't really matter which pin of port A it is, I can't get it to work with either :( In that code, the ADC is configured because I ended up using the LM35 as I could not use the DS 18B20 but is how it is currently



2020/10/09 19:34:02
ric
If you want to keep your sanity, get all of that code OUT of your interrupt service.
Do not put any slow code inside an ISR.
That means delay loops, LCD access code, while (xxx) loops.
A good ISR should do the minimum possible to clear the interrupt condition, and exit ASAP.
All your complicated code should be kept out in the non ISR portion.
 
 
It's pointless trying to get anything to work while you have that ISR there.
 
 
2020/10/09 19:44:15
jmxiqz
ric
If you want to keep your sanity, get all of that code OUT of your interrupt service.
Do not put any slow code inside an ISR.
That means delay loops, LCD access code, while (xxx) loops.
A good ISR should do the minimum possible to clear the interrupt condition, and exit ASAP.
All your complicated code should be kept out in the non ISR portion.
 
 
It's pointless trying to get anything to work while you have that ISR there.
 



Well I really don't know, I know things but I don't know many others, I keep learning as you say, I could put all these cycles in functions other than interrupt, but how can I read the sensor of a cable anyway? By setting ADCON1 = 0b1111, you should be able to use RA2 without issue, right? but the reset function for the initial connection always returns 1, and does not connect, the first code I posted is that, just an LCD screen showing the sensor reading, setting the ADCON1, that code should work, right? maybe it shows the wrong temperature but it should at least connect :(


2020/10/09 19:56:31
ric
jmxiqz
Well, I don't really know, I know things but I don't know many you touch, how do you say I could put all these cycles in functions other than interruption,

What makes you think you have to do all that in the interrupt?
Set a flag in the interrupt, and do the work in your main loop when you see the flag set.
If you don't want to learn how to program, find another hobby.
 

but anyway, how can I read the sensor of a wire? When setting ADCON1 = 0b1111, I should be able to use RA2 without problems right?

Only if you have all your hardware connected up correctly.

but the reset function for the initial connection always returns 1, and it doesn't connect,

 
There could be many reasons for that. You really need an oscolloscope or a logic analyser to watch what the pin is really doing, not just assume your code is perfect.
 
2020/10/09 20:08:58
jmxiqz
ric
jmxiqz
Well, I don't really know, I know things but I don't know many you touch, how do you say I could put all these cycles in functions other than interruption,

What makes you think you have to do all that in the interrupt?
Set a flag in the interrupt, and do the work in your main loop when you see the flag set.
If you don't want to learn how to program, find another hobby.
 

but anyway, how can I read the sensor of a wire? When setting ADCON1 = 0b1111, I should be able to use RA2 without problems right?

Only if you have all your hardware connected up correctly.

but the reset function for the initial connection always returns 1, and it doesn't connect,

 
There could be many reasons for that. You really need an oscolloscope or a logic analyser to watch what the pin is really doing, not just assume your code is perfect.
 




 
what the hell is wrong with you? The only thing I told you is that I do not know everything, which is true, I accept that I have bad practices, that does not imply that I cannot practice the hobby that I want even if I do it wrong, especially if you don't It affects you in nothing, I already told you I do not have access to a scope, only to a simulator, if you are not going to help and criticize because you do not think how other people do things, maybe you should refrain from answering, thanks

Attached Image(s)

2020/10/10 08:11:00
du00000001
@jmxiqz
I'd suggest to stop ranting as ric really tried to help.
 
As you seem to have neither a scope nor a logic analyzer, this project may be way beyond your current skills.
Why not "convert" to a neat Arduino Uno where you even might be able to find a completed project that fulfills most of your needs?
 
P.S.: Posting multiple copies of your thread doesn't help - we find them anyway.
copy #1: https://www.microchip.com/forums/m1154802.aspx
copy #2: https://www.microchip.com/forums/m1154965.aspx
12
© 2021 APG vNext Commercial Version 4.5

Use My Existing Forum Account