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

PIC One-wire problem

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



Joined: 01 Feb 2013
Posts: 3

View user's profile Send private message

PIC One-wire problem
PostPosted: Wed May 22, 2013 3:40 pm     Reply with quote

Hello everyone

I'm pretty sure my problem is basic OW stuff. All I am trying to do is read the ROM number of an EEPROM.

I have an EEPROM (DS2431) that I am interfacing with a Single-Channel 1-Wire Master (DS2482-100) and a PIC18F47J11.

I am trying to read the ROM of the EEPROM with the following code:

Code:

void main()
{
   setup_timer_4(T4_DISABLED,0,1);
   setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
   
   int i=0;
   BYTE rom_and_crc[8]={0,0,0,0,0,0,0,0};
   
   DS2482_write_config(CONFIG_APU); // Configures the active pullup MOSFET mode.
   
   if(DS2482_detect(DS2482_I2CAddr))
   {
      printf("\rDS2842: detected\n\r");
     
      if(OWReset())
      {
      OWWriteByte(0x33); //READ ROM COMMAND
      for(i=0; i<8; i++) rom_and_crc=[i]=OWReadByte();
     }
     while(1);
   }
}


But all I get back is 00 18 18 18 18 18 18 18.

The OWWriteByte and OWReadByte functions are as follows:

Code:

BYTE OWReadByte(void)
{
   
   
   BYTE data, status;
   int poll_count = 0;

   // 1-Wire Read Bytes (Case C)
   //   S AD,0 [A] 1WRB [A] Sr AD,1 [A] [Status] A [Status] A\
   //                                   \--------/       
   //                     Repeat until 1WB bit has changed to 0
   //   Sr AD,0 [A] SRP [A] E1 [A] Sr AD,1 [A] DD A\ P
   //                                 
   //  [] indicates from slave
   //  DD data read

   I2C_start();
   I2C_write(I2C_address | I2C_WRITE_FLAG);
   I2C_write(CMD_1WRB);
   I2C_start();
   I2C_write(I2C_address | I2C_READ_FLAG);

   // loop checking 1WB bit for completion of 1-Wire operation
   // abort if poll limit reached
   status = I2C_read(ACK);
   do
   {
      status = I2C_read(status & STATUS_1WB);
   }
   while ((status & STATUS_1WB) && (poll_count++ < POLL_LIMIT));

   // check for failure due to poll limit reached
   if (poll_count >= POLL_LIMIT)
   {
      // handle error
      // ...
      DS2482_reset();
      return 0;
   }

   I2C_start();
   I2C_write(I2C_address | I2C_WRITE_FLAG);
   I2C_write(CMD_SRP);
   I2C_write(0xE1);
   I2C_start();
   I2C_write(I2C_address | I2C_READ_FLAG);
   data =  I2C_read(NACK);
   I2C_stop();

   return data;
}

BYTE OWWriteByte(BYTE sendbyte)
{
   // set strong pull-up enable
   c1WS = 0;
   cSPU = CONFIG_SPU;
   cPPM = 0;
   cAPU = 0;
   
   // write the new config
   DS2482_write_config(c1WS | cSPU | cPPM | cAPU);

   // perform write byte
   BYTE status;
   int poll_count = 0;

   // 1-Wire Write Byte (Case B)
   //   S AD,0 [A] 1WWB [A] DD [A] Sr AD,1 [A] [Status] A [Status] A\ P
   //                                          \--------/       
   //                             Repeat until 1WB bit has changed to 0
   //  [] indicates from slave
   //  DD data to write

   I2C_start();
   I2C_write(I2C_address | I2C_WRITE_FLAG);
   I2C_write(CMD_1WWB);
   I2C_write(sendbyte);
   I2C_start();
   I2C_write(I2C_address | I2C_READ_FLAG);

   // loop checking 1WB bit for completion of 1-Wire operation
   // abort if poll limit reached
   status = I2C_read(ACK);
   do
   {
      status = I2C_read(status & STATUS_1WB);
   }
   while ((status & STATUS_1WB) && (poll_count++ < POLL_LIMIT));

   I2C_stop();

   // check for failure due to poll limit reached
   if (poll_count >= POLL_LIMIT)
   {
      // handle error
      // ...
      DS2482_reset();
      return FALSE;
   }
   else return TRUE;
}


Did anyone encounter a similar problem? Or maybe I'm just doing everything wrong. If so, does anyone have an example on how to read the ROM number?

Thanks Very Happy
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