CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

DS18B20 help

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
BillT



Joined: 09 Feb 2006
Posts: 1

View user's profile Send private message

DS18B20 help
PostPosted: Thu Feb 09, 2006 6:20 pm     Reply with quote

Hi and help!

I stripped my code to barebones and even copied some of it to be sure: no matter what I do, I can't read the sensor - one single sensor! I swapped out the PIC, tried different pins, and changed timing. The 1-wire part is indeed found - it just doesn't send any data back. During read by the PIC, it just sits high, which gives the 0xFFFFF... response. Any advice?

Thanks very much,
BillT

My output is always:
Code:
Pulse detected!!!
ffffffffffffffffff
ffffffffffffffffff
ffffffffffffffffff
ffffffffffffffffff


except when I unplug the sensor, and then the DS18B02 is indeed not found as expected.

Code:
//
//  Dallas 18B20 I/O pin connected to PIC RB5 pin, pulled up by 5k ohm resistor
//  Data sent to PC via MAX232 on PIC RC6 pin
//
//
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP,DEBUG,NOBROWNOUT,
#use delay(clock=4000000)
#use rs232(baud=19200, xmit=PIN_C6, rcv=PIN_C7, PARITY=N, BITS=8, stream=PC)

int1 init_1_wire(void);
void send_byte(int8 data);
int8 read_byte(void);


void main() {

   int8 k;
   int1 test;
   int8 buff[9];

// For now, keep it simple wrt interrupts:
   disable_interrupts(GLOBAL);

// Default state: 1-wire pin is floating:
   output_float(PIN_B5);

// Find the device and report the results:
   test = init_1_wire();

if(test)
   fprintf(PC, "\r\nPulse detected!!!\r\n");
else
   fprintf(PC, "\r\nPulse NOT detected!!!\r\n");

// Here, perform temperature conversion and send scratchpad bytes to PC:
while(1){
  test = init_1_wire();
   send_byte(0xCC);  // Skip ROM
   send_byte(0x44);  // Perform temperature conversion
   delay_ms(800);    // Takes 750 msec for conversion

 test = init_1_wire();
   send_byte(0xCC);  // Skip ROM     
   send_byte(0xBE);  // Read scratchpad
   
   delay_us(60);
   
// Read and report what was found: 
for(k = 0; k < 9;++k){
      buff[k] = read_byte(); }

fprintf(PC, "%x%x%x%x%x%x%x%x%x\r\n", buff[8],buff[7],buff[6],buff[5],buff[4],buff[3],buff[2],buff[1],buff[0]);

   } // Close the while

 } // Close the main



int1 init_1_wire(void){
int8 n = 250;

// Pull pin low for 500 usec and check if device is there:
      output_low(PIN_B5);
      delay_us(500);
      output_float(PIN_B5);

while((--n) && input(PIN_B5));

   if(n)
      return(1);
   else
      return(0);

} // close init_1_wire


void send_byte(int8 data){
   int8 count;

   for(count = 0; count < 8; ++count) {
         output_low(PIN_B5);
         delay_us(2);
         output_bit(PIN_B5, shift_right(&data,1,0));  // Put bit on pin
         delay_us(60);                                // End of write slot
         output_float(PIN_B5);                        // 1-wire goes high
         delay_us(2);                                 // Must be high > 1 usec
   }
}  // Close send_byte


int8 read_byte(void){
   int8 count, data;

   for(count = 0; count < 8; ++count) {
         output_low(PIN_B5);
         delay_us(2);
         output_float(PIN_B5);
         delay_us(13);
         shift_right(&data,1,input(PIN_B5));
         delay_us(45);
         }

   return(data);
}  //Close read_byte
jds-pic



Joined: 17 Sep 2003
Posts: 205

View user's profile Send private message

PostPosted: Fri Feb 10, 2006 10:03 am     Reply with quote

BillT,
compare your code with my onewire lib routines,
http://www.ccsinfo.com/forum/viewtopic.php?t=19520

hope that helps,
jds-pic
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group