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 speed a function of the PIC Xstal?

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



Joined: 17 May 2005
Posts: 213

View user's profile Send private message

i2c speed a function of the PIC Xstal?
PostPosted: Mon Jul 04, 2005 9:31 am     Reply with quote

Hi

Is the clock speed of the i2c a function of the PIC Xstal?

I have been using a 4MHz Xstal, and the following code:

Code:
#use i2c(master,sda=EEPROM_SDA, scl=EEPROM_SCL, FAST)


and

Code:

  START:
   i2c_start();
   if(i2c_write(0xa0 | mask)!=0)            //Device must ACKNOWLEDGE
      goto START;
   iTimer = 0;
   set_timer1(0);
   i2c_write(address>>8);                   //High Byte of Address
   iTimer = get_timer1();
   printf("+%x%x ", (iTimer>>8)&0X00FF, iTimer&0X00FF);
   set_timer1(0);
   i2c_write(address&0X00FF);               //Low Byte of Address
   iTimer = get_timer1();
   printf("+%x%x ", (iTimer>>8)&0X00FF, iTimer&0X00FF);
   set_timer1(0);
      i2c_write(232);
      i2c_write(232);
      i2c_write(232);
      i2c_write(232);
   iTimer=get_timer1();
   printf("-%x%x ", (iTimer>>8)&0X00FF, iTimer&0X00FF);
   i2c_stop();


I have found that the first printf (first address byte) takes 235 Xstal "ticks"- the length due to the operation on the address.
the second printf- 2nd byte of the address takes
240 Xtal "ticks"- once again due to the address computation.
the 4 data writes take on average 42.5 Xstal "ticks" ie. 170 ticks for 4 writes. The last translates to approximately 211kHz.
Surely the i2c should be running at 400kHz- ie two times faster?

What am I doing wrong?

Thank you in advance for your help
Regards
arrow
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Jul 04, 2005 11:24 am     Reply with quote

First, if you want to measure the speed of the I2C then you must measure the duration of the clock and not how long it takes to send 4 bytes.

But to answer your question, yes the xtal frequency affects the speed. The hardware mssp uses the sspadd register as a baud rate generator. By writing different values to this register, you will get different speeds. This value is decremented twice per instruction cycle time or 1/2 of the xtal freq. CCS handles this value if you use their setup functions. Obviously the software I2C functions will run faster if the clock is faster. You will have to look at the lst file to determine if CCS accounts for this or you could change the use delay and see the difference.
arrow



Joined: 17 May 2005
Posts: 213

View user's profile Send private message

PostPosted: Tue Jul 05, 2005 2:45 am     Reply with quote

Hi

Thank You for your reply.

Is it normal for the i2c_write(address) to take so much longer than i2c_write(data)?
I am finding that writting the address takes about 4 times longer than writtign data.

Can you please tell me what I am doing wrong?

Regards
arrow
arrow



Joined: 17 May 2005
Posts: 213

View user's profile Send private message

PostPosted: Tue Jul 05, 2005 2:46 am     Reply with quote

Hi

Thank You for your reply.

Is it normal for the i2c_write(address) to take so much longer than i2c_write(data)?
I am finding that writting the address takes about 4 times longer than writtign data.

Can you please tell me what I am doing wrong?

Regards
arrow
arrow



Joined: 17 May 2005
Posts: 213

View user's profile Send private message

PostPosted: Tue Jul 05, 2005 2:47 am     Reply with quote

Hi

Thank You for your reply.

Is it normal for the i2c_write(address) to take so much longer than i2c_write(data)?
I am finding that writting the address takes about 4 times longer than writtign data.

Can you please tell me what I am doing wrong?

Regards
arrow
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Jul 05, 2005 6:38 am     Reply with quote

No. Take a look at it with a scope if you want to see what is going on.
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