DS18B20 read correct only in debug, not production mode

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

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

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

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

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

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

Oh, I’m sorry that I didn’t get the joke!! It’s actually funny :smiley:

Yes, I posted the same question on multiple forums because I’m really desperate and must to deliver the firmware… :doh:

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.