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

i2c

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







i2c
PostPosted: Mon Dec 09, 2002 9:32 am     Reply with quote

Hello every body,
I am new using pic, i have been trying to communicate with ds1624(slave) temparature sensor using i2c by pic16f877(master). i have gone through data sheets, now the problem is that i can use i2c and can send data to slave but, i get no acknowlegement bits for every transfar.i did not use any pullup resistors in the circuite. i can not figure it out, may be i failed to notice a small mistake.i would appriciate if any body give me some hints.

my code >>

#byte SSPSTAT = 0x94 //In bank1
#byte SSPCON = 0x14 //In bank0
#byte SSPCON2 = 0x91 //in bank1
#byte SSPBUF = 0x13 //in bank0 i2c buffer
#byte SSPADD = 0x93 //in bank1 i2c
//slave address register
#byte STATUS = 0x03 //in bank0
#byte PIR1 = 0x0c

//Bits of SSPSTAT/////////////////

#bit SMP = 0x94.7
#bit CKE = 0x94.6
#bit D_A = 0x94.5
#bit P = 0x94.4
#bit S = 0x94.3
#bit R_W = 0x94.2
#define R_W_MASK 0x04
#bit UA = 0x94.1
#bit BF = 0x94.0
//Bits of PIR1////////////////////

#bit PSPIF = 0x0c.7
#bit ADIF =0x0c.6
#bit RCIF =0x0c.5
#bit TXIF =0x0c.4
#bit SSPIF =0x0c.3
#define SSPIF_MASK 0x08
#bit CCP1IF =0x0c.2
#bit TMR2IF =0x0c.1
#bit TMR1IF =0x0c.0
//////////////////////////////////
//Bits of SSPCON//////////////////

#bit WCOL = 0x14.7
#bit SSPOV = 0x14.6
#bit SSPEN = 0x14.5
#bit CKP = 0x14.4
#bit SSPM3 = 0x14.3
#bit SSPM2 = 0x14.2
#bit SSPM1 = 0x14.1
#bit SSPM0 = 0x14.0
//Bits of SSPCON2 /////////////////

#bit GCEN =0x91.7
#bit ACKSTAT =0x91.6
#bit ACKDT =0x91.5
#bit ACKEN =0x91.4
#bit RCEN =0x91.3
#bit PEN =0x91.2
#bit RSEN =0x91.1
#bit SEN =0x91.0
//Bits of STATUS Regtr/////////////

#bit IRP =0x03.7
#bit RP1 =0x03.6
#bit RP0 =0x03.5
#bit TO =0x03.4
#bit PD =0x03.3
#bit Z =0x03.2
#bit DC =0x03.1
#bit C =0x03.0

void i2c_init(void);
void i2cSend(char);
char i2cReceive(void);
void i2cAck(void);
void i2cNak(void);
void i2cStart(void);
void i2cStop(void);
void i2csspifClear(void);
void i2c_init(void){
set_tris_c(0x18); //So the C3 and C4 port set to be as input
output_high(pin_c3);
output_high(pin_c4);
//in the bank0
RP0=0;
RP1=0;
//basic enable bits in SSP module
SSPEN=1; //Enable the i2c mode
SSPM3=1; //set bit 1 setting the boud rate
SSPM2=0; // 0
SSPM1=0; // 0
SSPM0=0; // 0
////////////////////////////
RP0=1; /*** Select bank 1 *******/

SSPCON2 = 0x0;


SMP=1; //Slew rate controll disabled for standard speed (100k or 1M)
CKE=0; // Input level conforms i2c specs
//SSPSTAT = 0x80;

// Now bit Rate setup i2c speed //
SSPADD = 0x09; //100K @ 4 MHz clock
RP0=0;

}

void i2cSend(char ch){
SSPBUF = ch;
i2csspifClear();
}

char i2cReceive(void){


RP0=1; //Register to bank1

while(R_W!=0); //Waiting transmission to end

RCEN=1; //Enable i2c receiver
RP0=0; //back to bank0
i2csspifClear(); //Wait for data to arrive
return SSPBUF; //Retun the data

}
void i2cAck(void){

RP0=1; // Register page1
ACKDT=0; //Acknowledge Data bit
ACKEN=1; //Acknowledge Sequence Enable
RP0=0; // back to bank0
i2csspifClear(); //Wait for completion

}
void i2cNak(void){
RP0=1;
ACKDT=1;
ACKEN=1;
RP0=0;
i2csspifClear();
}
void i2cStart(void){
RP0=1;
SEN=1;
RP0=0;
i2csspifClear();

}
void i2cRestart(void){
RP0=1;
RSEN=1;
RP0=0;
i2csspifClear();
}
void i2cStop(void){
RP0=1;
PEN=1;
RP0=0;
i2csspifClear();

}
void i2csspifClear(void){
while (!SSPIF); //Wait for the interrupt

SSPIF=0; //Clear Interrupt Flag
}

void slaveConfig(char mode){
i2cStart();
i2cSend(0x90);
i2cSend(0xac);
i2cSend(mode); //1 shot mode can be 0x8 00001000b
i2cSend(0x90);
i2cSend(0xee);
i2cStop();

}
long int i2cReadTemp(){
int dataH,dataL;
long int tData;
i2cStart();
i2cSend(0x90);
i2cSend(0xaa);
i2cSend(0x91);
dataH=i2cReceive();
i2cAck();
dataL=i2cReceive();
i2cNak();
i2cStop();
tData = dataH;
tData = (tData<<8);
tData= (tData | dataL);
return tData;


}


thank you inadvance......
___________________________
This message was ported from CCS's old forum
Original Post ID: 9884
Ed Arnold
Guest







Re: i2c
PostPosted: Mon Dec 09, 2002 11:58 am     Reply with quote

:=now the problem is that i can use i2c and can send data to :=slave but, i get no acknowlegement bits for every transfar
:=.i did not use any pullup resistors in the circuite.

You must use pull-up resistors on the SDA and SCL lines. Also in your code you should not use output_high() functions. This is why you can send data, but do not receive. If you wish, you can use output_float() fuctions instead. This function is used for open drain inputs, but many programmers on this forum use it for the SDA and SCL pins. The i2c bus has always worked for me, with or without it. If you are only planning to talk to slave chips, I don't see the need for you to hand write all of the i2c functions. CCS's built in fuctions work very well for the Master side code.

Just my two cents

Ed Arnold
___________________________
This message was ported from CCS's old forum
Original Post ID: 9890
zax
Guest







Re: i2c
PostPosted: Mon Dec 09, 2002 12:16 pm     Reply with quote

:=:=now the problem is that i can use i2c and can send data to :=slave but, i get no acknowlegement bits for every transfar
:=:=.i did not use any pullup resistors in the circuite.
:=
:=You must use pull-up resistors on the SDA and SCL lines. Also in your code you should not use output_high() functions. This is why you can send data, but do not receive. If you wish, you can use output_float() fuctions instead. This function is used for open drain inputs, but many programmers on this forum use it for the SDA and SCL pins. The i2c bus has always worked for me, with or without it. If you are only planning to talk to slave chips, I don't see the need for you to hand write all of the i2c functions. CCS's built in fuctions work very well for the Master side code.
:=
:=Just my two cents
:=
:=Ed Arnold

I thank you for your kind suggestion.
___________________________
This message was ported from CCS's old forum
Original Post ID: 9893
zax
Guest







Re: i2c
PostPosted: Mon Dec 09, 2002 12:19 pm     Reply with quote

:=:=now the problem is that i can use i2c and can send data to :=slave but, i get no acknowlegement bits for every transfar
:=:=.i did not use any pullup resistors in the circuite.
:=
:=You must use pull-up resistors on the SDA and SCL lines. Also in your code you should not use output_high() functions. This is why you can send data, but do not receive. If you wish, you can use output_float() fuctions instead. This function is used for open drain inputs, but many programmers on this forum use it for the SDA and SCL pins. The i2c bus has always worked for me, with or without it. If you are only planning to talk to slave chips, I don't see the need for you to hand write all of the i2c functions. CCS's built in fuctions work very well for the Master side code.
:=
:=Just my two cents
:=
:=Ed Arnold

thank you for your kind suggestion.
___________________________
This message was ported from CCS's old forum
Original Post ID: 9894
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