View previous topic :: View next topic |
Author |
Message |
xpercad Guest
|
Software I2C "FAST" |
Posted: Sun Jun 27, 2004 11:24 am |
|
|
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
|
|
Posted: Sun Jun 27, 2004 1:41 pm |
|
|
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
|
I2C 1MHZ |
Posted: Sun Jun 27, 2004 2:03 pm |
|
|
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
|
|
|
xpercad
Joined: 27 Jun 2004 Posts: 12 Location: MÉXICO
|
Software I2C "FAST" |
Posted: Mon Jun 28, 2004 7:44 am |
|
|
Thanks a lot for your help. It is most appreciated !!!! |
|
|
|