CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

I2C strange frequency on 18F452

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
mvaraujo



Joined: 20 Feb 2004
Posts: 59
Location: Brazil

View user's profile Send private message

I2C strange frequency on 18F452
PostPosted: Mon Mar 08, 2004 12:39 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 08, 2004 1:44 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 08, 2004 1:52 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 08, 2004 2:50 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Mar 08, 2004 2:51 pm     Reply with quote

Thanks!

I'll do it and let you know the results.

Marcus
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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