Jump to content

Recommended Posts

Hello I can´t get correct readings from DS18S20. This is the result I get.


Temperature conversion timed outTemperature: FFFF -- 255.5 degrees C.


here is some part of the code. I am using a PIC16F648A.


#include <system.h>

#include "serial.h"

#include "oo.h"




#define OO_PIN 6


volatile bit oo_bus @ OO_PORT . OO_PIN;

volatile bit oo_bus_tris @ OO_TRIS . OO_PIN;


#pragma DATA 0x2007, 0x3F50

#pragma CLOCK_FREQ 4000000




trisa = 11000000b; // 1=input

trisb = 11000010b; // 1=input


vrcon = 0x00; // turn off voltage reference module

cmcon = 0x07; // turn off comparator

set_bit(pie1, RCIE); //enable USART receive interrupt bit

intcon = 11000000b; //set interrupts on set_bit(intcon, PEIE); set_bit(intcon, GIE);




while( 1 )



// Allow wakeup



// Reset the one wire bus



// Start the temparature conversion (non-blocking function)



// Wait for completion, you could do other stuff here

// But make sure that this function returns zero before

// reading the scratchpad

if (oo_wait_for_completion() == 1){

serial_printf("Temperature conversion timed out");



// Read the scratchpad

if (oo_read_scratchpad()){

serial_printf("OO read scratchpad failed");




// And extract the temperature information

short temp = oo_get_data();


// The temperature is

serial_printf("Temperature: ");


serial_printf(" -- ");


// And for positive temps you can simply convert this to

char tmp_work = (char)(temp >> 1);


if (temp & 0x0001){


} else {



serial_printf(" degrees C.\r\n");


// A more accurate conversion is described in the DS1820 datasheet.



Link to post
Share on other sites
I have tryed diffrent ports and all things I can think of any ides?


Regards /Jörgen


Are you using the one wire lib functions or the one wire c and h files from the sample programs ?


I have just started doing a lot of programming for a number of one wire device types (ibutton,temperature, GPI) and ran into timing problems with both the lib and c+h files.

Not much to do concerning the lib but at least you can modify the c file to adjust.


If you look in the sample file you will find a lot of "nop" to adjust both read and write timing on the one wire bus. If it is correct for a 20Mhz clock it will not be for a 4Mz.


Best thing to try is to have a look at the data sheets from Dallas concerning one wire timing and try adjusting the number of "nop" to make sure that you are reading the "catching" the bus on time.



Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...