|
|
View previous topic :: View next topic |
Author |
Message |
mvaraujo
Joined: 20 Feb 2004 Posts: 59 Location: Brazil
|
I2C strange frequency on 18F452 |
Posted: Mon Mar 08, 2004 12:39 pm |
|
|
Hi folks,
I used to have a i2c master application using a 18F452 to communicate to external clock and eeprom. XTAL is 10MHz model, multiplied by 4 inside and i2c doesnt work at all.
If I observe the SCL line I see frequencies different that the expected 100Khz. Sometimes, 90Khz, others, 80Khz. This is driving me crazy since I don't find any problem with the whole application except the I2c frequency.
I used to have the same routines working fine in other application with different XTAL, no internal multiply, and they were working fine!
Anyone has any idea of what's happening?
Thanks,
Marcus |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 08, 2004 1:44 pm |
|
|
When you changed to 40 MHz operation, did you also change your
#use delay statement to 40 MHz ? |
|
|
mvaraujo
Joined: 20 Feb 2004 Posts: 59 Location: Brazil
|
|
Posted: Mon Mar 08, 2004 1:52 pm |
|
|
Yes I did!
Here you go:
Code: |
//Definicoes de projeto
#include <18f452.h>
#include <regs_18fxx2.h>
#include <sipig_modbus.h>
#device ADC=10 // ADC de 10bits
#use delay(clock=40000000) // clock de 40MHz
#use i2c (master, sda = PIN_C4, scl = PIN_C3, force_hw) // I2C master por HW
#use rs232 (baud = 19200, xmit = PIN_C6, rcv = PIN_C7, parity = E, bits = 8) // rs232 por HW, com paridade PAR, dados de 8bits, ENABLE control signal para RS485 nao ligado ainda
#fuses H4,NOOSCSEN,NOWDT,PUT,NOPROTECT,NOBROWNOUT,NOSTVREN,NOLVP,NODEBUG // config bits
#use fast_io (A) // I/O com selecao manual
#use fast_io (B)
#use fast_io (C)
#priority ccp1, rtcc, rda, tbe
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Mar 08, 2004 2:50 pm |
|
|
My suggestion is to make a very small, and very simple test program.
Copy this program directly into MPLAB, compile it, load it into the PIC,
and run it. Look at the SCL and SDA pins with an oscilloscope.
You may have to use the Hold Off control on the oscilloscope to
get a stable waveform.
Then see if this program still has a problem with changing frequencies
of the SCL clock.
Code: | #include <18F452.h>
#fuses H4,NOOSCSEN,NOWDT,PUT,NOPROTECT,NOBROWNOUT,NOSTVREN,NOLVP,NODEBUG
#use delay(clock=40000000)
#use i2c (master, sda = PIN_C4, scl = PIN_C3, force_hw)
//===============================
main()
{
while(1)
{
i2c_write(0x55);
}
} |
|
|
|
mvaraujo
Joined: 20 Feb 2004 Posts: 59 Location: Brazil
|
|
Posted: Mon Mar 08, 2004 2:51 pm |
|
|
Thanks!
I'll do it and let you know the results.
Marcus |
|
|
|
|
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
|