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

Speed of i2c and How can it be increased?

 
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

Speed of i2c and How can it be increased?
PostPosted: Wed Feb 22, 2006 12:06 am     Reply with quote

Hi

I am trying to do an operation every 1ms and I use Timer2 interrupts. This works pretty well. Now I am trying to write to an FRAM chip occassionally while the 1ms interrupt is occuring. I use:
Code:

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

I am using a 4MHz Xstal on the PIC16F873.
My compiler is rather old (Version 2.686).

What I find is that although the FRAM chip should respond in useconds, I sometimes do not complete the write to FRAM in the 1ms, causing all sorts of problems. I would like to write only 2 bytes in this time period. I know for certain that without the FRAM writting, things work well.

Could some one please tell me what I am doing wrong?

Thank you in advance.
a.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 22, 2006 12:35 am     Reply with quote

Look in your eeprom driver file. Does the function called
write_ext_eeprom() have a delay_ms() statement at the end ?
If so, remove it. FRAM doesn't need the delay.


Also, please delete your double-post. You can do this by viewing
the post, and then click on the little "X" in the upper right corner.
arrow



Joined: 17 May 2005
Posts: 213

View user's profile Send private message

PostPosted: Wed Feb 22, 2006 12:43 am     Reply with quote

Hi PCM Programmer

I am sorry about the double post- one of them is deleted.

I have written my own external eeprom writer, and it has no delays. It looks like this:

Code:

//***WRITTING TO EEPROM ASSUMING only two bytes per page
void pageWrite_ext_eeprom(int addressH, int addressL, int mask){
   int ik;
   i2c_start();
   i2c_write(0xa0 | mask);
   i2c_write(addressH);                   //High Byte of Address
   i2c_write(addressL);               //Low Byte of Address
   i2c_write(dat[0]);
   i2c_write(dat[1]);
   i2c_stop();
}


Could you please tell me what I am doing wrong?

Even at 100kHz with say 64bits written it would take
64*10us = 640us
so I cant see how the 1ms is being achieved.

Thank you
a.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 22, 2006 12:51 am     Reply with quote

CCS didn't support hardware i2c in your version of the compiler.

Here is some code that will allow you to do hardware i2c:
http://www.ccsinfo.com/wwwboard/messages/725.html
You must use pin C4 for SDA and pin C3 for SCL with this code.
arrow



Joined: 17 May 2005
Posts: 213

View user's profile Send private message

PostPosted: Wed Feb 22, 2006 1:01 am     Reply with quote

Hi PCM Programmer

Thank you very much for your link and code.
Could you please explain your sentence:

"CCS didn't support hardware i2c in your version of the compiler"

since in my manual there are i2c_write and i2c_read commands.
I am not sure what "hardware support" means.

Regards
a.

PS in the latest version of the compiler, can I set the clock speed in the i2c commands?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Feb 22, 2006 1:15 am     Reply with quote

Software i2c consists of "bit banging" two pins on an i/o port.
The writing of high and low levels on the i2c bus is done completely
by the PIC program with ASM instructions.

Hardware i2c makes use of the MSSP module that's available in some
PICs. The MSSP contains a baud rate generator, and a shift register,
and other logic. The hardware can shift out the bits much faster than
with the software "bit banging" method.

The "#use i2c()" library code in your version of the CCS compiler
only supports software i2c. To use hardware i2c, you either have to
upgrade the compiler or use the routines in the link that I posted.
(Or find other routines).
arrow



Joined: 17 May 2005
Posts: 213

View user's profile Send private message

PostPosted: Wed Feb 22, 2006 1:38 am     Reply with quote

Hi PCM Programmer

Thank you- once again you have explained things very well!

One last question:
Using the code that you posted where should the clock and data pins be connected to for the PIC16F873 chip?

(Is it PIN_C3=SCL and PIN_C4=SDA?)

Once again thank you for all your help.
Regards
a.
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Wed Feb 22, 2006 8:55 am     Reply with quote

You now understand that this is done in hardware. Look at the hardware spec. microchip 16F873 and see if you can find the sda scl.

hint. look for MSSP or sda or scl
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Wed Feb 22, 2006 9:21 am     Reply with quote

One thing I ran into, when I first started using PICs, is that I was trying to do too much at once. I had interrupts going off all the time and there just wasn't enough time to service them all. Your 4MHZ clock could be increased quite a bit in case your instructions aren't being executed fast enough to service everything you're trying to do. Remember to keep your ISR's as short as possible and that each command takes a certain amount of time to execute. They all add up.

Ronald
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