DS18B20 read correct only in debug, not production mode

A place to hang out and chat with other like minded tinkerers

Moderator: phalanx

Post Reply
Drugo
Posts: 6
Joined: Mon Mar 07, 2011 11:25 am

DS18B20 read correct only in debug, not production mode

Post by Drugo » Thu Jan 15, 2015 7:44 pm

Hello, I am experiencing a weird behavior with temperature readings from a DS18B20 Dallas temperature sensor. I am using a dsPIC33, ICD3 for debugging/downloading the firmware, XC16 compiler and I display the temperature on the console through serial port.
The problem is that I perfectly read the temperature in debug mode, while, in production mode, I read Temperature LSB and Temperature MSB of the scratchpad always equal to zero.

I am in big trouble because I have to deliver the firmware for the production next Tuesday. Could anyone please help me to fix this issue?

Thanks a lot in advance

Mee_n_Mac
Support Volunteer
Posts: 5628
Joined: Thu Apr 28, 2011 4:10 pm

Re: DS18B20 read correct only in debug, not production mode

Post by Mee_n_Mac » Thu Jan 15, 2015 9:14 pm

I believe you'll find your answer on line 42.

Drugo
Posts: 6
Joined: Mon Mar 07, 2011 11:25 am

Re: DS18B20 read correct only in debug, not production mode

Post by Drugo » Fri Jan 16, 2015 12:01 pm

Thanks for your reply Mee_n_Mac. But sorry, what do you mean with line 42?

jremington
Support Volunteer
Posts: 2342
Joined: Fri Jun 15, 2007 9:41 pm
Location: Eugene, Or

Re: DS18B20 read correct only in debug, not production mode

Post by jremington » Fri Jan 16, 2015 12:50 pm

Mee_n_Mac suspects that line 42 of your code is where the problem is to be found.

Drugo
Posts: 6
Joined: Mon Mar 07, 2011 11:25 am

Re: DS18B20 read correct only in debug, not production mode

Post by Drugo » Fri Jan 16, 2015 1:50 pm

Sorry but I don't get it very well. In the sense that, since I didn't post any code, how can Mee_n_Mac say that is line 42? I didn't post the code because I didn't do anything different from the other things I'm doing. In the sense that the instructions of this issue are the following:

printf("\n\r");
printf("DS18B20 tempL = %u\n\r", tempL);
printf("DS18B20 tempH = %u\n\r", tempH);
printf("DS18B20 temperature = %f\n\r", temperature);
printf("\n\r

And, among these instructions, I tried to insert:
printf("DEBUG = %u\n\r", i);
and it works perfectly (i is a variable counter that I use in a for loop).

Any guess? Thanks so much for your help folks, I really appreciate

jremington
Support Volunteer
Posts: 2342
Joined: Fri Jun 15, 2007 9:41 pm
Location: Eugene, Or

Re: DS18B20 read correct only in debug, not production mode

Post by jremington » Fri Jan 16, 2015 2:04 pm

On this forum we tend in the direction of humor, if possible.

My guess is that this is a question for the Microchip forum, since the problem likely deals with a compiler issue rather than the code.

Edit: I now see that you've already posted on the Microchip forum http://www.microchip.com/forums/m841681.aspx

Drugo
Posts: 6
Joined: Mon Mar 07, 2011 11:25 am

Re: DS18B20 read correct only in debug, not production mode

Post by Drugo » Fri Jan 16, 2015 2:56 pm

Oh, I'm sorry that I didn't get the joke!! It's actually funny :D
Yes, I posted the same question on multiple forums because I'm really desperate and must to deliver the firmware... :doh:

Drugo
Posts: 6
Joined: Mon Mar 07, 2011 11:25 am

Re: DS18B20 read correct only in debug, not production mode

Post by Drugo » Fri Jan 16, 2015 3:38 pm

I got the final answer from the Microchip forum and want to post it for completeness. I am using AN5/IC8/CN7/RB5 pin to receive the digital data from the Dallas DS18B20 temperature sensor. In the inherited code I'm working on this pin was used as an analog one because the previous temperature sensor was analog. So, when it was analog, I found this initialization:

AD1PCFGLbits.PCFG5 = 1;

that I changed as digital in this way:

AD1PCFGLbits.PCFG5 = 0;

The mistake was that the initialization of this pin (as digital, in my current case) has to be:

AD2PCFGLbits.PCFG5 = 1;

In debug mode, as reported at page 20 of dsPIC33FJ128GP706A datasheet, all AN pins are configured by default as digital. So that's the reason why it worked in debug mode and not in production one.

Post Reply