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

Software I2C "FAST"

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







Software I2C "FAST"
PostPosted: Sun Jun 27, 2004 11:24 am     Reply with quote

Hi Group,

I am using PIC18F452 @ 40 MHz and PCWH 3.202

I have a couple of RAMTRON FM24C64 FRAM Serial Memories interfaced with a software I2C bus. These serial memories can use a maximum of 1 MHz I2C bus frequency. If I use the keyword FAST for the #USE I2C directive I believe (I have not measured it) the bus frequency is 400 KHz.

Is there any way to increase the speed of the software I2C bus generated by the compiler so I can use the FRAM chips to their full potential ???

Your help will be highly appreciated.

Aaron
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 27, 2004 1:41 pm     Reply with quote

Quote:
Is there any way to increase the speed of the software I2C bus
generated by the compiler so I can use the FRAM chips to their full
potential ?

Here is one possible solution. In his FAQ article here
http://www.ccsinfo.com/faq/?50
Darren Rook shows how to put two or more #use delay() statements
in a program. So with that concept in mind, what if we put the i2c driver
at the end of the program, and put a 2nd #use delay() right above it, with
the clock speed set to a much lower value than the actual frequency ?
This would trick the compiler into generating software i2c code with
much shorter software delays.

I looked at the .LST file, and it appears to work.

But this is just an idea. I haven't tested it in hardware. If you decide
to use it, you must prove to yourself that it works, and that it's reliable.

Code:
#include <18F452.h>
#fuses H4, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 40000000)
//========================================

void init_ext_eeprom(void);
void write_ext_eeprom(long int address, BYTE data);
BYTE read_ext_eeprom(long int address);
//====================================
void main()
{
char c;

init_ext_eeprom();
write_ext_eeprom(0x1234, 0x55);
c = read_ext_eeprom(0x5678);

while(1);
}
//==================================
#use delay(clock = 4000000)    // Change to 4 MHz
#include <24256.c>             // Put the i2c driver here.
// Note: This i2c driver file uses pins B0 and B1 by default,
// so it will generate software i2c code.
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

I2C 1MHZ
PostPosted: Sun Jun 27, 2004 2:03 pm     Reply with quote

Rather than use the CCS I2C I use Peter Andersons routines (www.phanderson.com) which can be modified for whatever speed you like.

His entire collection of software routines is well worth buying. I have used many of them in cases where I want to do something special that CCS functions can't handle and now have a custom library of those put together I <include> when I need them.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 27, 2004 2:11 pm     Reply with quote

His i2c code is posted on his web site.
http://www.phanderson.com/PIC/PICC/CCS_PCM/24_256_1.html
http://www.phanderson.com/PIC/PICC/index.html
xpercad



Joined: 27 Jun 2004
Posts: 12
Location: MÉXICO

View user's profile Send private message

Software I2C "FAST"
PostPosted: Mon Jun 28, 2004 7:44 am     Reply with quote

Thanks a lot for your help. It is most appreciated !!!!
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