View previous topic :: View next topic |
Author |
Message |
arrow
Joined: 17 May 2005 Posts: 213
|
Speed of i2c and How can it be increased? |
Posted: Wed Feb 22, 2006 12:06 am |
|
|
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
|
|
Posted: Wed Feb 22, 2006 12:35 am |
|
|
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
|
|
Posted: Wed Feb 22, 2006 12:43 am |
|
|
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
|
|
Posted: Wed Feb 22, 2006 12:51 am |
|
|
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
|
|
Posted: Wed Feb 22, 2006 1:01 am |
|
|
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
|
|
Posted: Wed Feb 22, 2006 1:15 am |
|
|
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
|
|
Posted: Wed Feb 22, 2006 1:38 am |
|
|
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
|
|
Posted: Wed Feb 22, 2006 8:55 am |
|
|
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
|
|
Posted: Wed Feb 22, 2006 9:21 am |
|
|
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 |
|
|
|