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 support@ccsinfo.com

Trouble getting a DS18B20 to work in parasite power mode...
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








Trouble getting a DS18B20 to work in parasite power mode...
PostPosted: Fri Sep 04, 2009 9:15 am     Reply with quote

Hi All,

I'm working on a project that will use the DS18B20 as a temperature sensor. I'm using only one sensor on a dedicated pin of my PIC. I can only run two wires to the sensor, so I am planning to operate the DS18B20 in parasite power mode. I haven't been able to get this to work, so on the bench I've connected the Vdd terminal of the sensor to +5V, and it is now responding as expected. From this, I conclude that my hardware and software are OK, and that the problem is that I'm not handling the parasite power requirements of the DS18B20 correctly.

I've actually done a similar project in the past using code from Peter Anderson. He has a one wire routine called '_1w_strong_pull_up' that is called after the temp. conversion command is issued to the DS18B20 in order to supply the necessary current to the device during temperature conversion.

Code:

void _1w_strong_pull_up(int sensor)   // bring DQ to strong +5VDC
{
   PORTB = 0x01 << sensor;
   TRISB = 0xff & (~(0x01 << sensor));
   delay_ms(1000);
   TRISB = 0xff;
}


I am using the following as a replacement code for my single sensor, and I believe it does the same thing:

Code:

output_high(DQ);
delay_ms(1000);


In parasite power mode, sensor pins Gnd and Vdd are connected to Gnd, and pin DQ is connected to my PIC pin. The PIC pin also has a 4.7K pullup.

Again, the problem appears to be that I'm not powering the DS18B20 properly in parasite power mode during the temperature conversion. Is the code I've shown the equivalent to the Peter Anderson code that does this, but for a single sensor?

Thanks,

Joe
Guest








PostPosted: Tue Sep 08, 2009 12:31 pm     Reply with quote

Hi,

OK, can I assume that no one has ever used the DS18B20 in parasite power mode with CCS C?

I've been studying the DS18B20 datasheet, and the key part seems to be that I need to pull the data line high within 10 uS of issuing the convert temperature command so that the DS18B20 can "steal" power from the data line to run during the temp. conversion. In concept this appears to be do-able, as the DS18B20 only needs 1.5mA, and a digital output pin can source more than that. The problem then must be the 10 uS requirement??

I have looked at the .lst file for my program, and it looks like there are only 4 instructions that are executed to set the digital output high. With a 4 MHz clock, isn't that only 4 microseconds? The command to convert temperature is sent in a subroutine, and I don't know what the overhead is of coming back from the sub. How many instructions are chewed up in that process? Obviously, I'm wondering if it's possible to send a byte of data on the data line, and then turn around and set the data line to a high level all within 10 uS with a 4 MHz clock??

Comments?

Joe
PCM programmer



Joined: 06 Sep 2003
Posts: 20337

View user's profile Send private message

PostPosted: Tue Sep 08, 2009 1:26 pm     Reply with quote

1. Post a link to the software driver that you're using for the ds18B20.
Are you using this one from the CCS code library forum ?
http://www.ccsinfo.com/forum/viewtopic.php?t=28425&start=18

2. Post a link to your schematic that shows all connections to the
ds18b20-par chip. (Or describe it in detail).

3. Post if this is being done in real hardware or in a simulator such
as Proteus.

4. Post your PIC.

5. Post your compiler version.
Guest








PostPosted: Fri Sep 11, 2009 12:39 pm     Reply with quote

Hi PCM,

Here is the code I am using:

Code:

//-----< Include Files, setup fuses >-----

#include <16f648a.h>

#fuses HS, NOWDT, NOPROTECT, NOLVP, BROWNOUT

//-----< Compiler use statements >-----

// Tell compiler clock speed is 4.00 MHZ Crystal
#use delay(clock=4000000)

//-----< General Program Defines >-----
#define Rx_In PIN_B1            // serial data receive pin from PC
#define Tx_Out PIN_B2            // serial data transmit pin to PC
#define DQ PIN_A0                  // One Wire Bus pin assignment

//-----< Serial Port Definition >-----
#use rs232(baud=9600, xmit=Tx_Out, rcv=Rx_In, ERRORS, stream = PC)


void ow_reset(void)
{
   output_low(DQ);
   delay_us(500);          // Min. 480uS
   output_float(DQ);
   delay_us(500);          // Wait for end of timeslot
}

//******************************************************************************
// Read bit on one wire bus
int8 read_bit(void)
{
   output_low(DQ);
   delay_us(1);         
   output_float(DQ);
   delay_us(12);        // Read within 15uS from start of time slot
   return(input(DQ));   
}                       

//******************************************************************************
void write_bit(int8 bitval, int8 i)
{
   output_low(DQ);

   if(bitval == 1) {
      delay_us(1);      // 1uS min. Code relied on 8051 being slow.
      output_float(DQ);
   }
   delay_us(105);       // Wait for end of timeslot
   output_float(DQ);
}

//******************************************************************************
int8 read_byte(void)
{
   int8 i;
   int8 val = 0;

   for(i=0 ; i<8 ; i++)
   {
      if(read_bit()) val |= (0x01 << i);
      delay_us(120);  // To finish time slot
   }

   return val;
}

//******************************************************************************
void write_byte(int8 val)
{
   int8 i;
   int8 temp;

   for (i=0;i<8;i++)
   {
      temp = val >> i;
      temp &= 0x01;
      write_bit(temp, i);
   }

   //delay_us(105);
}

void main(void)
{
   int8 i;
   signed int16 temperature;
   int8 scratch[9];       
   
   // Here we clear the Hyperterminal display, and write to the RS-232 port
   fprintf(PC, "\x1B[2J");

   output_float(DQ);     
   
   while(1)
   {
      ow_reset();
      write_byte(0xCC); // Skip Rom command
      write_byte(0x44); // Temperature Convert command

      output_high(DQ);   // Strong Pull-up on DQ to power the DS18B20 during the temp conversion.
      delay_ms(750);    // Max. time for conversion is 750mS
   
      ow_reset();
      write_byte(0xCC); // Skip Rom command
      write_byte(0xBE); // Read scratch pad command
   
      // Get the data bytes
      for (i=0 ; i<8 ; i++)
      {
          scratch[i] = read_byte(); 
      }
   
      ow_reset();
     
      // If the received crc is same as calculated then data is valid.
      // Scale and round to nearest degree C.
      // Scaling is 0.0625 (1/16) deg.C/bit with default 12 bit resolution.
      // Round by adding half denominator for positive temperatures and
      // subtracting half denominator for negative temperatures.

     temperature = (signed int16) make16(scratch[1],scratch[0]);
         
         if (temperature >= 0)
            temperature = (temperature + 8)/16;
       
         else
            temperature = (temperature - 8)/16;
           
         fprintf(PC, "Temp: %4Ld C \n\r",temperature);
   }
}


This code works well when I power the DS18B20 with an external +5V supply, but it does not function when I attempt to power the device in 'parasite' power mode.

My circuit is quite simple. I'm using a single pin, A0, for my 1 wire interface. This pin has a pull-up of 4K7 to +5V. The sensor is the DS18B20 which has 3 pins, V+, DQ, and Gnd. I have V+ and Gnd tied together at the sensor and connected to my circuit Gnd, and DQ is connected to Pin A0. I am not using the -PAR sensor, but that unit only differs in its packaging; electrically, it is identical to the DS18B20. Again, if I separate the V+ pin at the sensor and connect it to +5V, the circuit works!

The DS18B20 datasheet shows a MOSFET that drives the 1 wire bus to a high level during temperature conversions. I am NOT using this method. Rather, I am using the 1 wire interface pin itself for this purpose. The MOSFET is required if there are multiple sensors on the bus, and the current source requirements exceed those of a PIC pin. I don't see any electrical reason I can't do it this way, and in fact, Peter Andersen does this. In my first post, I show the code he uses to drive the 1 wire bus high during temp. conversions. One difference is that he is using Fast I/O, but I don't know if that makes any difference??

When I run this code in parasite power mode, the temperature that is returned is 85C, which is the power-up value of the sensor. This clearly means that the temperature conversion is not taking place successfully.

I am doing this in real hardware - it is NOT a simulation.

My compiler version is v4.050.

Thanks,

Joe
PCM programmer



Joined: 06 Sep 2003
Posts: 20337

View user's profile Send private message

PostPosted: Fri Sep 11, 2009 2:10 pm     Reply with quote

I can wire up my ds18B20 in parasite mode and test it with your code
on Sunday.
Guest








PostPosted: Fri Sep 11, 2009 2:51 pm     Reply with quote

PCM,

That would be great if you could take a look! Much appreciated!

Joe
Kenny



Joined: 07 Sep 2003
Posts: 173
Location: Australia

View user's profile Send private message

PostPosted: Fri Sep 11, 2009 7:02 pm     Reply with quote

Joe

Only thing I spotted was that the fuse should be XT instead of HS
for 4MHz.

It worked with the code 'as is' here
http://www.ccsinfo.com/forum/viewtopic.php?t=19255
Just added output_high(DQ) before the conversion delay and
connected Vcc to GND on device.

Your code worked (I changed the fuse) with a 16F88 @ 4MHz and
version 4.091. Also tried different pins, all OK. Tried it with a
16F876 and 18F2520 OK. Also with version 3.249,OK. I dont have a
16F648A or version 4.057 though.

If anything is found to be incorrect or marginal I will update the code. Back Wednesday.
PCM programmer



Joined: 06 Sep 2003
Posts: 20337

View user's profile Send private message

PostPosted: Sun Sep 13, 2009 3:16 pm     Reply with quote

Is Kenny's post sufficient ? Do I still need to test your code ?
Guest








PostPosted: Sun Sep 13, 2009 7:04 pm     Reply with quote

Hi PCM,

Sorry, I can't tell until Monday morning. It looks like the only thing that he changed was the oscillator fuse. It doesn't seem like that would be enough to cause the problem I'm seeing, but I have to test it.

I'll report my findings in the morning.

Thanks,

Joe
Guest








PostPosted: Mon Sep 14, 2009 8:14 am     Reply with quote

Hi all,

I changed the fuse in my code from 'HS' to 'XT', but that did not solve my problem. When I run in parasite power mode, the DS18B20 returns 85C, and when I run in external power mode, the DS18B20 returns 21C or so, which is my room temperature.

I see two possibilities:

1. Hardware issue: not likely as DS18B20 runs fine in external power mode
2. Compiler issue: could someone (Kenny or PCM) compile my code with a later compiler version, and email the hex file to me? If it works, I'll upgrade my compiler and carry on with my project.

Thanks,

Joe
bkamen



Joined: 07 Jan 2004
Posts: 1530
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Sep 14, 2009 11:05 am     Reply with quote

I've used the 1820's in parasitic mode. They work fine.

Make sure you are following the protocol exactly. There isn't a lot of room for error.

EDIT: Added
In parasitic power mode, what is the pullup you're using? Remember when you ask the 1820 to do a conversion, it needs a little more current than when just communicating. Without doing the math, I think I used 1K pullups a lot.


I can't hook up one and play until this weekend either. (I have some next to me in an old RS/6000 that acted as a multi-point CPU temp monitor outputting to serial port)

I thought I had some simple scanning software someplace.. I'll have to look if you're still stuck.
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Guest








PostPosted: Mon Sep 14, 2009 7:49 pm     Reply with quote

Hi,

As stated, I'm using a 4K7 pull-up resistor as described in the DS18B20 datasheet. I don't rely on the pull-up to supply current to the device during temp. conversions, I pull the 1 wire bus high to do this. A 4K7 pull-up by itself will only allow about 1mA of current at 5V, and that is not enough.

I re-read Kenny's last post, and it's ambiguous to me if he used my EXACT code with his test. He mentions something like that, but also provides a link to some other code, so I'm not sure?

I guess at this point I'm waiting for PCM to try it, or for Kenny to come back!

Joe
bkamen



Joined: 07 Jan 2004
Posts: 1530
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Sep 14, 2009 10:39 pm     Reply with quote

oops. 4.7K should do it as long as you "juice" the line with the PIC.

Ok, nevermind - without jumping in as well, not sure why it's not working. I've used bunches of these before (in the TO-92 package) and had no issues.

FAST_IO does make a difference. Timing is CRUCIAL.

You wouldn't happen to have a scope available, would you?

-Ben

p.s. I'm gonna go look for my code.
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
bkamen



Joined: 07 Jan 2004
Posts: 1530
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Sep 14, 2009 11:02 pm     Reply with quote

ok, I found my code in a couple different forms. It's so old that I don't remember if I modified a library or CCS-ized code or WHAT!

I do remember writing it in ASM first and then putting what I learned into CCS friendly source. so I apologize and will delete this if it's CCS Code (someone let me know)

I need to test this. I wrote it in 1997. Shocked

But I also have code I used on a 12C672 inside my RS/6000 running at 4MHz... so it can be done..

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
bkamen



Joined: 07 Jan 2004
Posts: 1530
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Mon Sep 14, 2009 11:05 pm     Reply with quote

Code:
//---------------------------------------------------------------------------
//   CarayMonitor2.c
//   
//   This version uses a 12C672 instead. Plpllpllpllplpl
//

#include <12c672.h>
#rom 0x7ff = { 0x34A0 }     // set RC calibration (A0=.995MHz, B0=1.05MHZ)
#fuses INTRC, PUT, NOWDT, NOPROTECT,NOMCLR
#use delay(clock=4000000)
#use rs232(xmit=PIN_A4, rcv=PIN_A5, baud=9600, bits=8, parity=n )

#include <ds1820.c>

//            Store 8byte Serial Numbers + CRC in EEPROM
//          [Famly] [LSB  <- Serial Number ->  MSB]  [CRC]
int const serialArray[4][8]=
         {{ 0x10, 0x5C, 0x7F, 0x15, 0x0, 0x0, 0x0, 0x13 },   // DS1820 - Thermometer
          { 0x10, 0xE5, 0x9F, 0x15, 0x0, 0x0, 0x0, 0x58 },   // DS1820 - Thermometer
          { 0x10, 0xF9, 0x89, 0x15, 0x0, 0x0, 0x0, 0x9E },   // DS1820 - Thermometer
          { 0x10, 0xF4, 0xA6, 0x15, 0x0, 0x0, 0x0, 0x43 }};   // DS1820 - Thermometer

static int temps[] = { 0x00, 0x00, 0x00, 0x00 };
static int adc[]   = { 0x00, 0x00, 0x00, 0x00 };

// ===========================================================
//
void crlf() {
   putc (13);
   putc (10);
}

// ===========================================================
//
void main () {
 int i,x;
 float a,b;

   setup_adc_ports( AN0_AN1_ANALOG );
   setup_adc( ADC_CLOCK_INTERNAL );

   while(1) {
      putc(12);
      puts("IBM 43p-240 (Type: 7043-240) SN:10-35065");
      crlf();
      puts("System Information:");
      puts("=========================================");
      puts("System Temperatures:");
      printf("CPU-1: %03d%cC -- HeatSink-1: %03d%cC", temps[0], 39, temps[1], 39);
      crlf();
      printf("CPU-2: %03d%cC -- HeatSink-2: %03d%cC", temps[2], 39, temps[3], 39);
      crlf();
      crlf();
      puts("System Voltages:");
      a = adc[0] * .06188;
      b = adc[1] * .0390625;
      printf("+12: %06.2f (0x%02X)", a, adc[0] );
      crlf();
      printf(" +5:  %05.2f (0x%02X)", b, adc[1] );
      crlf();

      for (i=0;i<=1;i++) {
        set_adc_channel(i);
        delay_ms(20);
        adc[i] = read_adc();
      }

      for (i=0;i<=3;i++) {
         for (x=0;x<=7;x++) {
           serial[x] = serialArray[i][x];
         }
         ds_temp();
         temps[i] = (scratchpad[1] * 0x80) + (scratchpad[0] >> 1);
      }
      delay_ms(2000);
   }
}


Code:
//////////////////////////////////////////////////////////////////
// DS1820.C                     //
// Library for the Dallas 1820 Temperature Sensor      //
// 12/22/97 Ben Kamen                  //
//                        //
//                        //
//   dqlow()    - Sets DS-1wire bus low         //
//                        //
//   dqhiz()    - Sets DS-1wire bus high-Z         //
//                        //
//   ds_reset() - Sends Reset over DS-1wire bus      //
//                        //
//   ds_tx()    - Sends byte over DS-1wire bus      //
//                        //
//   ds_rx()    - Gets Byte from DS-1wire bus      //
//                        //
//   ds_temp()  - Sends temp cmd and loads scratchpad[]   //
//         from device            //
//                        //
//   c_or_f(boolean degree) - returns long int of temp   //
//      degree=                  //
//         0=celcius            //
//         1=farenheit            //
//                        //
//                        //
//////////////////////////////////////////////////////////////////

//byte const DLY10 = 5;   //10uS delay value for 10MHz (was 11 for 15uS)
//byte const DLY30 = 20;   //30uS delay value for 10MHz (was 20)
//byte const DLY45 = 40;   //45uS delay value for 10MHz
//byte const DLY60 = 60;  //60uS delay value for 10MHz

byte const DLY10 = 2;   //10uS delay value for 4MHz (was 11 for 15uS)
byte const DLY30 = 8;   //30uS delay value for 4MHz (was 20)
byte const DLY45 = 16;   //45uS delay value for 4MHz
byte const DLY60 = 24;  //60uS delay value for 4MHz


//Common Equates for all Dallas 1-wire bus devices
byte const readrom = 0x33;   // Read ROM Command
byte const matchrom = 0x55;   // Match ROM Command
byte const skiprom = 0xCC;   // Skip ROM Command
byte const skipod = 0x3C;   // Skip ROM OverDrive Mode Command
byte const matchod = 0x69;   // Match ROM OverDrive Mode Command
byte const searchrom = 0xF0;   // Skip ROM Command
byte const searchalarm = 0xEC;   // Skip ROM Command

// DS1820 Equates
byte const ds1820 = 0x10;   // DS1820 Family ID Code
byte const tempconvert = 0x44;   // Convert Command
byte const rscratch = 0xBE;   // Read ScratchPad
byte const wscratch = 0x4E;   // Write ScratchPad
byte const cscratch = 0x48;   // Copy ScratchPad
byte const recalle = 0xB8;   // Recall E2 into scratchpad
byte const rpower = 0xB4;   // Read Power Supply Status


#byte port = 5      //Define your Port to use here.
byte const STATUS = 3;   //Status Register
byte const RP0 = 5;   //Register Page Bit
byte const C = 0;   //Carry Bit
byte const TRIS = 0x85;   //Define the Direction Control Register here.
byte const DSBIT = 2;    //Define your Dallas Connection Pin Here - This is RA2

STATIC byte crc_byte;   //Here's the CRC byte needed throughout

//Here's the Array for the Serial Number
//   byte family;
//   byte number[6];
//   byte crc;

byte serial[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };

// Here's the Array for the DS1820 Scratchpad.
//   byte magn;   //Temp Magnitude
//   byte sign;   //Temp Sign 0=+ve, 255=-ve
//   byte tl;   //User Temp Low Byte
//   byte th;   //User Temp High Byte
//   byte unused[2];   //Reserved Register 4,5
//   byte remain;   //Count Remaining Register
//   byte per_c;   //Counts per 'C Register
//   byte crc;   //End CRC Byte
//

byte scratchpad[9];

///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
// DQ LOW Routine. Set's DQ to output and then to
// Logic Low State
//
void dqlow() {
#asm
   BCF   PORT,DSBIT
   BSF   STATUS, RP0
   BCF   0x85,DSBIT
   BCF   STATUS, RP0
#endasm
}

///////////////////////////////////////////////////////////////
// DQ HIZ Routine. Set's DQ to HI-Z State
//
void dqhiz () {
#asm
   BSF   STATUS, RP0
   BSF   0x85,DSBIT   
   BCF   STATUS, RP0
#endasm
}

///////////////////////////////////////////////////////////////
// DS_Reset - Sends Reset Pulse on the bus and then checks for a
// present pulse. Returns Boolean state of Pulse Detect
// 0 = Present, 1 = No Devices
//
boolean ds_reset () {
  short i;
   dqlow();
   delay_us(600);         // Pause 600uS to Reset Device
               // The spec calls for 480uS MINIMUM
   dqhiz();
   delay_us(60);         // Wait ~67us For Response Pulse
   i = bit_test(port,dsbit);

   while (!bit_test(port,dsbit)) {   // Wait until it goes up again.
   }

   return i;
}

//////////////////////////////////////////////////////////////////////
//   Here's the Transmit Byte Routine
//   It sends out 1 byte at a time LSB first
//   It's in Assembly due to the tight timing requirements
//
void ds_tx (int data) {
   byte counter;
   byte index;

#asm
   MOVLW   8
   MOVWF   index
DSTXLP:   
#endasm
   dqlow();
#asm
   MOVLW   DLY10
   MOVWF    counter
LOOP1:   DECFSZ   counter,f
   GOTO   Loop1
   RRF   data, f
   BTFSC   STATUS, C
   BSF   PORT,DSBIT   
   MOVLW   DLY45
   MOVWF    counter
LOOP2:   DECFSZ   counter,f
   GOTO   Loop2
#endasm
   dqhiz();


//   MOVLW   DLY30
//   MOVWF    counter
//LOOP3:   DECFSZ   counter,f
//   GOTO   Loop3
#asm
   DECFSZ   index, f
   GOTO   DSTXLP
#endasm



}

//////////////////////////////////////////////////////////////////////
//   Here's the Receive Byte Routine
//   It pulls in 1 byte at a time LSB first
//   It's in Assembly due to the tight timing requirements
//
byte ds_rx () {
   byte index;
   byte counter;
#asm
   MOVLW   8
   MOVWF   index
   CLRF   _RETURN_   
DSRXLP:
#endasm
   dqlow();
#asm   
   MOVLW   DLY10
   MOVWF    counter
LOOP1:   DECFSZ   counter,f
   GOTO   Loop1
#endasm
   dqhiz();
#asm
   NOP
   MOVF   PORT,W
   ANDLW   1 << DSBIT   
   ADDLW   255      
   RRF   _RETURN_, f
   MOVLW   DLY45
   MOVWF    counter
LOOP2:   DECFSZ   counter,f
   GOTO   Loop2
   DECFSZ   index, f
   GOTO   DSRXLP
#endasm
}

//////////////////////////////////////////////////////////////////////
//   Here's the CRC Check Routine
//   If ALL Received bytes from the 1820 pass through this routine,
//   the result is Zer0. If all bytes but the CRC byte pass through,
//   this routine passes back a number that should equal the CRC.
//
//  Uses crc polynomial x8+x5+x4+1
//
//  x8 -> x7 -> x6 -> x5 -> XOR -> x4 -> XOR -> x3 -> x2 -> x1
//  ^                        ^            ^                 |
//  |                        |            |                 |
//  +------------------------+------------+------ <- XOR <--+
//                                                    ^
//                                                    |
//                                                  Data-Bit
//
byte ds_crc (int data) {
   byte bit_cnt;
   byte tmp1;
      
    for (bit_cnt = 8; bit_cnt != 0; bit_cnt--) {
      tmp1 =(data ^ crc_byte) &1;
      data >>=1;       /* shift right one bit */
      crc_byte >>=1;       /* shift right one bit */
      if (tmp1 !=0)
        crc_byte ^=0x8c;      /* x8+x5+x4+1 shifted one bit right */
     }
     return (crc_byte);
}

//////////////////////////////////////////////////////////////////////
//   Here's the CRC-16 Check Routine
//   This is used by the 1-wire devices that report 16bit CRC's back
//   to the host when a READ takes place.
//
//   Uses crc ploynomial x16+x15+x2+x1
//
//   
//
// It's not here yet. Can you tell?? -Ben


//////////////////////////////////////////////////////////////////////
//   Send_serialnum Routine
//   Throws array serial[] onto bus
//
void send_serialnum() {
   byte i;

   ds_tx(matchrom);
   delay_us(200);
   for (i=0;i<=7;i++) {
     ds_tx( serial[i] );
   }
}

//////////////////////////////////////////////////////////////////////
//   Here's the load_serialnum Routine
//   Stuffs byte array serial[] into EEPROM offset by inbound
//   "File Pointer"
//
void load_serialnum (int file) {
//   byte i;
//   byte tmp;
//   
//      file *= 8;
//   for (i=0;i<=7;i++) {
//    serial[i] = read_eeprom(file+i);
//   }
}
//////////////////////////////////////////////////////////////////////
//   Here's the Get Temp Routine
//   This returns the entire scratchpad from the 1820 in
//   variable scratchpad[]. It also rolls the received bytes through
//   ds_crc() to get CRC value.
//
void ds_temp () {
   byte i;
   byte tmp;
   
      crc_byte = 0;      // clear CRC Byte
      ds_reset();         // Reset Bus
      delay_us(200);      // Wait
      send_serialnum();      // Send the Serial of device we want
      ds_tx(tempconvert);      // Send command to convert Temp
      delay_ms(300);      // Wait
      ds_reset();         // Reset Bus
      delay_us(200);      // Wait
      send_serialnum();      // Send the Serial of device we want
      ds_tx(rscratch);      // Get ScratchPad

      for (i=0;i<=8;i++) {      // Send it through CRC Routine
      tmp = scratchpad[i] = ds_rx();
      ds_crc(tmp);
      }
}

_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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