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

multiple 18B20 - need working example - i'm stupid in 1-wire

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







multiple 18B20 - need working example - i'm stupid in 1-wire
PostPosted: Mon Jan 01, 2007 8:24 am     Reply with quote

Does anybody have a working example how to select and read one of 18B20's on bus?
I've read this ccsinfo.com/forum/viewtopic.php?t=19255 but i do not understand how to assemble this in a whole program.
dyeatman



Joined: 06 Sep 2003
Posts: 1937
Location: Norman, OK

View user's profile Send private message

PostPosted: Mon Jan 01, 2007 8:53 am     Reply with quote

Did you look in the code library?

Try here:
http://www.ccsinfo.com/forum/viewtopic.php?t=28425
40ind
Guest







PostPosted: Mon Jan 01, 2007 9:48 am     Reply with quote

Quote:
This code will not work with 2 or more DS1820 sharing the same 1-wire bus.
Assen



Joined: 18 Oct 2006
Posts: 8

View user's profile Send private message

PostPosted: Mon Jan 01, 2007 11:50 am     Reply with quote

Check this driver: DS2432.c
It is written for DS2432 but the function search_rom can be used with any 1Wire chip. It is very simple to find all available 1Wire chips using that function and then select one of them using MATCH_ROM_CMD. I'll try to make an example if you cannot do it yourself.
40inD
Guest







PostPosted: Mon Jan 01, 2007 1:32 pm     Reply with quote

Assen, I need to get temperature from 3 18B20. Could you explain me the algorythm? Which function follows after which?
Assen



Joined: 18 Oct 2006
Posts: 8

View user's profile Send private message

PostPosted: Mon Jan 01, 2007 2:19 pm     Reply with quote

I'm not using DS1820 and your reference code (ccsinfo.com/forum/viewtopic.php?t=19255) but from what I see it must be like this:

Use the function FindDevices to create your own search/read function.
Insert after the last printf a call to Send_MatchRom and if it returns TRUE then do whatever you want with the selected chip - you can read the temperature for example. That's all. Using FindDevices you will have access to your 3 chips once at time.
Kenny



Joined: 07 Sep 2003
Posts: 173
Location: Australia

View user's profile Send private message

PostPosted: Mon Jan 01, 2007 5:25 pm     Reply with quote

Yep, that's pretty much it. Here's an example for testing.

Edited:
onewire.c is here
http://www.ccsinfo.com/forum/viewtopic.php?t=19255

Code:

#include <16F88.h>
#fuses XT,NOWDT,NOLVP,PUT,NOPROTECT,NOBROWNOUT,NOWRT,CCPB3
#use delay(clock=4000000)
#use rs232(baud=9600,xmit=PIN_B5,rcv=PIN_B2,ERRORS)

#define DQ PIN_B0      // One Wire Bus pin assignment

#include "onewire.c"

void main(void)
{
   int8 i;
   signed int16 temperature;
   int8 scratch[9];       
   
   output_float(DQ);       // Set as input. 4k7 pullup on bus.
   FindDevices();         
   
   while(1)
   {
      if (!ow_reset())     // If a device is present
      {
         write_byte(0xCC); // Skip Rom command
         write_byte(0x44); // Temperature convert command
         output_float(DQ);
         delay_ms(750);    // Max. conv. time is 750mS for 12 bit
         ow_reset();
 
         // Now get the device raw temperature data using Match ROM with the
         // addresses obtained with FindDevices().
         // 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.
                     
         for (numRoms=1;numRoms<=8;numRoms++)
         {
            if (Send_MatchRom())
            {
               write_byte(0xBE); // Read scratch pad command
               dowcrc = 0;       
               
               // Get the data bytes
               
               for (i=0;i<=7;i++)
               {
                   scratch[i] = read_byte();
                   ow_crc(scratch[i]);     
               }
   
               scratch[8] = read_byte();   // Get crc byte
               ow_reset();
   
               // If calculated crc from incoming bytes equal to crc byte
               // then data is valid.
                                         
               if (scratch[8] == dowcrc) 
               {
                  temperature = (signed int16) make16(scratch[1],scratch[0]);
                 
                  if (temperature >= 0)
                     temperature = (temperature + 8)/16;
               
                  else
                     temperature = (temperature - 8)/16;
                     
                  printf("%4Ld ",temperature);
               }
               
               else
                  printf("Error in data\n\r");
            }
         }
         
         putc('\n'); putc('\r');
      }   
   }
}


Here's the output with four DS18B20 and four DS1822 on the bus.
Code:

Device No.1 address B400000056245628   DS18B20 family code 28
Device No.2 address 8500000042A0AE28       "     "    "    "
Device No.3 address 8300000042521128       "     "    "    "
Device No.4 address 8A00000042889128       "     "    "    "
Device No.5 address 920000000232B022   DS1822  family code 22
Device No.6 address 3C0000000227B022       "     "    "    "
Device No.7 address 870000000235C422       "     "    "    "
Device No.8 address EE00000002311222       "     "    "    "

  25   25   25   25   25   25   24   25
  25   25   25   25   25   25   24   25
  25   25   25   25   25   25   24   25
etc.


Last edited by Kenny on Thu Apr 30, 2009 12:23 am; edited 2 times in total
Guest








PostPosted: Sun Apr 01, 2007 1:37 pm     Reply with quote

Quote:
// include one wire functions here


Which OneWire functions are to be included here? From one of the CCS example programs or some other ones? Can you post the specific ones? Thanks.
Guest








PostPosted: Mon Apr 02, 2007 2:31 am     Reply with quote

The ones from the link in the first post in this thread.
Keith1130



Joined: 31 Oct 2009
Posts: 6

View user's profile Send private message

PostPosted: Sat Nov 07, 2009 11:08 am     Reply with quote

Hi, Kenny, how can you show the outputs in computer? I am using one DS1822 communicated with PIC18F2480. I have finished the driver code, but when I try to debug it, I don't know how to get the outputs like yours. Can you show me how to do it in MPLAB?
Kenny



Joined: 07 Sep 2003
Posts: 173
Location: Australia

View user's profile Send private message

PostPosted: Sat Nov 07, 2009 3:04 pm     Reply with quote

For one device the address is not required. Either use the code in the link, or the code in the code library section of this forum. However, the code above should work with just one device connected.

I use the CCS IDE.
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