Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

DS1621 I2C communication with PIC16F887

Status
Not open for further replies.

IShan0039

Newbie level 4
Joined
Dec 26, 2009
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
India
Activity points
1,334
Hi,
Iam trying to communicate with DS1621 for a while now but the problem is I am not getting the proper temperature values.The output is always equal to FF.Iam getting proper acknowledgement for every command sent to DS1621.

Please help me with this problem..Thank you in Advance..
 

This is my code:-

#include<pic16f887.h>


#define SCL TRISC3 // I2C bus
#define SDA TRISC4 //
#define SCL_IN RC3 //
#define SDA_IN RC4 //
#define LED RA2
#define I2C_READ 0X91
#define I2C_WRITE 0X90
//******************global**************

bit ACK=0;
unsigned char LSB=0,MSB=0,TEMP=0,MSB1=0,LSB1=0;


//**********************DELAY*************************

void delay_ms(unsigned int td)
{
unsigned int i,j;
for(i=0;i<=td;i++)
{
for(j=0;j<=1000;j++)
{
}
}
}

//***********************hex2bcd***********************
unsigned char hex2bcd(unsigned char data)
{
unsigned char msb,lsb;
msb = data/10;
msb = msb << 4;
lsb = data % 10;
data = msb|lsb;
return data;
}
//******************BUS IDLE CHECK****************
void IDLEI2C( void )
{
while ( ( SSPCON2 & 0x1F ) || ( RW ) )
continue;
}


//**************************START COMMAND **********************
void i2c_start()
{
IDLEI2C();
SEN=1;
SSPIF=0;
while(SEN);
}

//**************************STOP COMMAND *************************
void i2c_stop()
{
IDLEI2C();
PEN=1;
SSPIF=0;
while(SEN);
}

//**************************** TRANSMIT ***************************
void i2c_transmit(unsigned char b)
{
IDLEI2C();
SSPBUF=b; //WRITE TO BUFFER
while(SSPIF!=1); //WAIT UNTIL ALL NINE BITS ARE SENT
SSPIF=0;
WCOL=0; //CLEARING THE WCOL TO AVOID BUSY FLAG SET
while(ACKSTAT!=0); //ACK ON 9TH CLOCK PULSE
ACKSTAT=1;
}

//************************ configuration for temperature control ******************************
void i2c_config()
{
unsigned int t,i;
i2c_start();
i2c_transmit(I2C_WRITE);

i2c_transmit(0xac); //acess configuration command

i2c_transmit(0x00); //continous conversion command
delay_ms(20); //delay of more than 20msec for data write.

i2c_stop();
}


//**************************RECEIVE*************************
unsigned char i2c_receive(unsigned char ack)
{
IDLEI2C();
RCEN=1;

while(SSPIF!=1);
SSPIF=0;
TEMP = SSPBUF;
ACKEN=ack;
SSPBUF=0;
BF=0;
SSPOV=0;
WCOL=0;
return TEMP;
}



//***********************START CONVERSION*******************
void i2c_start_convert()
{
unsigned char t2;
unsigned int t,i=0;
i2c_start();
RSEN=1;
i2c_transmit(I2C_WRITE);

i2c_transmit(0xee); //start convert command

i2c_stop();

}


//*********************INITIALISE****************
void init()
{
SDA=1;
SCL=1;
SDA_IN=0;
SCL_IN=0;
SSPADD=0X09; //TO SET THE CLOCK RATE TO 100KHZ.
SSPCON=0X28; //SERIAL TRANSFER ENBLE;IN MASTER MODE.

LED =0;
TRISB=0X00;
PORTB=0X00;
TRISD=0X00;
PORTD=0X00;

}

//****************READ TEMPERATURE**************
void read_temperature()
{
delay_ms(800); //delay of 800ms
i2c_start();
i2c_transmit(I2C_WRITE);
i2c_transmit(0xaa); //start convert command
i2c_start();
i2c_transmit(I2C_READ);
MSB=i2c_receive(1); //send with ack=1
LSB=i2c_receive(0); //send with ack=0;
i2c_stop();
MSB1 = hex2bcd(MSB);
PORTB = MSB1;
LSB = LSB >> 3;
LSB = LSB*1000;
LSB = (LSB*32)/100; // here we get the value of decimal points
LSB1 = hex2bcd(LSB);
PORTD = LSB1;

}



//************************* MAIN*************
void main()

{

while(1)
{
init();
i2c_config();
i2c_start_convert();

read_temperature();
}

}
 

Re: DS1621 I2C communication

DS1621 I2C communication with C8051F120
Hi,
Am using DS1621 to communicate with C8051F120 via I2c...Could someone help me regaring the command set of DS1621.? Am unable to figure out how to use the command set..(Read Temperature [AAh], Access TH [A1h] ..e.t.c).

Am new to this, if someone has worked on this command set of DS1621..Please help.. Am leftout with very less time to complete this...
Thanks,
EH
 

Re: DS1621 I2C communication

DS1621 I2C communication with C8051F120
Hi,
Am using DS1621 to communicate with C8051F120 via I2c...Could someone help me regaring the command set of DS1621.? Am unable to figure out how to use the command set..(Read Temperature [AAh], Access TH [A1h] ..e.t.c).

Am new to this, if someone has worked on this command set of DS1621..Please help.. Am leftout with very less time to complete this...
Thanks,
EH

Hey ,
I was working on this from 2 days ,read the datasheet of DS1621 they have give it very nicely and stepwise.
 

Attachments

  • DS1624.pdf
    309.9 KB · Views: 96

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top