|
|
View previous topic :: View next topic |
Author |
Message |
Spaark Guest
|
Switch between Fast and Slow Mode of i2c |
Posted: Wed Apr 30, 2003 2:19 am |
|
|
Is it possible to switch from the Slow-Mode to the Fast-Mode of i2c in the Programmcode? And how if it is possible?
I now use #use i2c(master,sda=PIN_C4, scl=PIN_C3, SLOW) and want to switch to #use i2c(master,sda=PIN_C4, scl=PIN_C3, FAST) when i press a key.
Thanks.
Spaark
___________________________
This message was ported from CCS's old forum
Original Post ID: 14077 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: Switch between Fast and Slow Mode of i2c |
Posted: Wed Apr 30, 2003 12:48 pm |
|
|
:=Is it possible to switch from the Slow-Mode to the Fast-Mode of i2c in the Programmcode? And how if it is possible?
:=
:=I now use #use i2c(master,sda=PIN_C4, scl=PIN_C3, SLOW) and want to switch to #use i2c(master,sda=PIN_C4, scl=PIN_C3, FAST) when i press a key.
---------------------------------------------------
The easiest way is to use hardware i2c mode, and then change
the baudrate by writing to the SSPADD register.
Here is a sample program. If your crystal frequency is
different from 8 MHz, then change the #define statement
for Fosc so that it's set to your frequency.
<PRE>
#define Fosc 8000000 // I'm using a 8 MHz crystal
<BR>
#include "c:\Program Files\Picc\Devices\16F877.H"
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, NOLVP, PUT
#use delay(clock = Fosc)
#use rs232(baud = 9600, xmit=PIN_C6, rcv = PIN_C7, ERRORS)
<BR>
// Tell the compiler to use hardware i2c.
#use i2c(Master, SDA=PIN_C4, SCL=PIN_C3, FORCE_HW, slow)
<BR>
// Calculate the i2c baudrate values, to program
// into the SSPADD register.
#define SLOW ((Fosc / (4 * 100000)) -1) // 100 KHz i2c clock
#define FAST ((Fosc / (4 * 400000)) -1) // 400 KHz i2c clock
<BR>
#byte SSPADD = 0x93 // Address of i2c baudrate register
<BR>
//=====================================
void main()
{
char c;
<BR>
delay_us(1);
<BR>
while(1)
{
i2c_write(0x55);
<BR>
if(kbhit())
{
c = getc() & 0x5F;
<BR>
if(c == 'F') // If the F key is pressed, use Fast speed.
SSPADD = FAST;
<BR>
if(c == 'S') // If the S key is pressed, use Slow speed.
SSPADD = SLOW;
}
<BR>
}
<BR>
}
</PRE>
___________________________
This message was ported from CCS's old forum
Original Post ID: 14091 |
|
|
|
|
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
|