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

1-wire

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








1-wire
PostPosted: Wed Mar 23, 2005 4:08 pm     Reply with quote

Hi !

I'd like to use the DS2480 or DS2490 or DS1481 1-Wire for a project.
Could anybody provide me some C code?

Many thanks.
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Thu Mar 24, 2005 12:18 pm     Reply with quote

Look at EX_TOUCH.C in the examples file. It shows how to use Dallas one-touch devices in general. You will have to write your own drivers for specific chips.
_________________
The search for better is endless. Instead simply find very good and get the job done.
global



Joined: 01 Feb 2005
Posts: 21
Location: Paris

View user's profile Send private message

1-wire DS2411
PostPosted: Fri Mar 25, 2005 2:27 am     Reply with quote

Hi,

i have this program which uses 1-wire, and it gives :

Quote:
DS2411_DATA = aab7dfaeb6af5555


In the datasheet, it indicates that if the CRC matches the last 8 bits of the registration number, the transmission is error free.

I think here it is not good, could someone tell me what is wrong in there ?

Code:

#include <header.h>

/*******************************************************************************
****************************** Functions prototypes ****************************
*******************************************************************************/

void main (void);
void init(void);
int8 Reset(void);
void Write1(void);
void Write0(void);
int8 Readx(void);
void WriteByte(int Data);
int8 ReadByte(void);

byte ROM_BUFFER[8];                //ROM Code Buffer

/*******************************************************************************
************************************** main ************************************
*******************************************************************************/

void main(void)
{
   init();
   while(1)
   {
      byte i;
      if(!Reset())
      {
         WriteByte(0x33);

         for(i = 0; i < 8; i++)
         {
         ROM_BUFFER[i] = ReadByte();
         }
       printf("\nDS2411_DATA = %x%x%x%x%x%x%x%x",ROM_BUFFER[7], ROM_BUFFER[6],ROM_BUFFER[5],
       ROM_BUFFER[4], ROM_BUFFER[3], ROM_BUFFER[2], ROM_BUFFER[1], ROM_BUFFER[0]);
       //printf("\nCRC_DATA = %x", ROM_BUFFER[0]);
       //printf("\nFAMILY_CODE_DATA = %x", ROM_BUFFER[7]);
       delay_ms(2000);
      }
   }
}
/*
DS2411_DATA = b7dfaeb6af55                                                                                                                                                                         
CRC_DATA = 55                                                                                                                                                                                     
FAMILY_CODE_DATA = aa 

DS2411_DATA = adf7ebab6fd5                                                                                                                                                                         
CRC_DATA = 55                                                                                                                                                                                     
FAMILY_CODE_DATA = aa             
*/

/*******************************************************************************
********************************** Initialization ******************************
*******************************************************************************/

void init(void)
{
   output_low(DS2411_IO);
}

/*******************************************************************************
*************************************** Reset **********************************
*******************************************************************************/

int8 Reset(void)
{
   int8 result=0;

   output_low(DS2411_IO);  // Drives DQ low
   delay_us(480);
   output_high(DS2411_IO); // Releases the bus
   delay_us(60);

   // Sample and return the Presence Detect
   result=input(DS2411_IO) & 0x01;
   delay_us(240);

   return result;
}

/*******************************************************************************
*************************************** Write1 *********************************
*******************************************************************************/

void Write1(void)
{
   output_low(DS2411_IO);  // Drives DQ low
   delay_us(1);
   output_high(DS2411_IO); // Releases the bus
   delay_us(59);
}

/*******************************************************************************
*************************************** Write0 *********************************
*******************************************************************************/
void Write0(void)
{
   output_low(DS2411_IO);  // Drives DQ low
   delay_us(55);
   output_high(DS2411_IO); // Releases the bus
   delay_us(5);
}

/*******************************************************************************
**************************************** Readx *********************************
*******************************************************************************/
int8 Readx(void)
{
   int8 result=0;

   output_low(DS2411_IO);  // Drives DQ low
   delay_us(1);
   output_high(DS2411_IO); // Releases the bus
   delay_us(14);

   result=input(DS2411_IO) & 0x01;
   delay_us(45);

   return result;
}

/*******************************************************************************
************************************* WriteByte ********************************
*******************************************************************************/
void WriteByte(int8 Data)
{
   int8 loop;

   for(loop = 0;loop < 8;loop++)
   {
      // 0x01,0x02,0x04,0x08,0x10,etc.
      if(Data&(0x01 << loop)) Write1();
      else Write0();
   }
}

/*******************************************************************************
************************************** ReadByte ********************************
*******************************************************************************/
int8 ReadByte(void)
{
   int8 loop;
   int8 result=0;

   for(loop = 0;loop < 8;loop++) result = result + (Readx() << loop);

   return result;
}
jds-pic



Joined: 17 Sep 2003
Posts: 205

View user's profile Send private message

Re: 1-wire DS2411
PostPosted: Fri Mar 25, 2005 10:35 am     Reply with quote

global wrote:

In the datasheet, it indicates that if the CRC matches the last 8 bits of the registration number, the transmission is error free.

I think here it is not good, could someone tell me what is wrong in there ?

see my onewire routines, here:
http://www.ccsinfo.com/forum/viewtopic.php?t=19520
and compare your CRC calculation function.

also,
read and understand
http://pdfserv.maxim-ic.com/arpdf/AppNotes/app27.pdf

jds-pic
global



Joined: 01 Feb 2005
Posts: 21
Location: Paris

View user's profile Send private message

PostPosted: Tue Mar 29, 2005 9:32 am     Reply with quote

Thanks for the links ! I'll do what i can
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