View previous topic :: View next topic |
Author |
Message |
mvaraujo
Joined: 20 Feb 2004 Posts: 59 Location: Brazil
|
I2C pin config and signal aspects in the ports |
Posted: Tue Mar 30, 2004 1:08 pm |
|
|
Hi!
I have some problems with i2c master mode comm using a PIC18F452@40MHz and would like to take your thoughts about that.
How do you config the pin for hardware i2c? Output or input?
Datasheet from uChip says both input. In my design, if I set them like these I get a strange CLK signal (slow ramp up of the voltage from 0 to 5V) with 90KHz. If set them to output, the CLK signal looks great, 100khz perfect as expected.
Thanks
Marcus |
|
|
rnielsen
Joined: 23 Sep 2003 Posts: 852 Location: Utah
|
|
Posted: Wed Mar 31, 2004 1:21 pm |
|
|
Look in the CCS Help area. It talks about set_tris_c(). You can set the SDA and SCL pins to inputs using this command.
Ronald |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Mar 31, 2004 6:07 pm |
|
|
I tested your problem on my demo board, and it worked OK.
I didn't test this with the 4x PLL, because my demo board
is not setup for that. So I ran it at 4 MHz.
The following program produced i2c clock and data signals
with fast rise and fall times. At the start of the program,
I set pins C3 and C4 as inputs.
Code: | #include <18F452.H>
#fuses XT, NOPROTECT, BROWNOUT, PUT, NOWDT, NOLVP
#use delay(clock=4000000)
#use i2c(Master, sda=PIN_C4, scl=PIN_C3, FORCE_HW)
//========================
main ()
{
output_float(PIN_C3);
output_float(PIN_C4);
while(1)
{
i2c_write(0x55);
}
} |
|
|
|
mvaraujo
Joined: 20 Feb 2004 Posts: 59 Location: Brazil
|
|
Posted: Thu Apr 01, 2004 11:59 am |
|
|
PCM Programmer,
And which are the pull-up resistors of your demo board on the i2c lines?
It's even more strange because if I use 10k pull-ups, I have slow ramp-ups, if you use 1k, SDA is fast and clear but a 0.5V positive offset appears on the SCL. Crazy, huh?
I'll figure it out, sooner or later!
Thanks,
Marcus |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Apr 01, 2004 12:28 pm |
|
|
1K pullups are out of spec for the i2c bus. For a 5v i2c bus,
the smallest pullup size is 1.6K. So I suggest you use 2.2K
on your demo board. That's a convenient size that you
probably have in your parts cabinet. |
|
|
mvaraujo
Joined: 20 Feb 2004 Posts: 59 Location: Brazil
|
|
Posted: Thu Apr 01, 2004 12:35 pm |
|
|
I understand your point. In fact it's not a demo board, it's power monitoring device that I'm design. I'll try out the 2k2 to how it works.
Thanks,
Marcus |
|
|
|