• C

embedded c

Hi all,

I am interfacing TMP275 temperature IC with PIC 32. I read the code given on microchip website. They have taken I2C_CLOCK_FREQ=5000 and PBCLK=40MHZ . If calculated value of BRG from that. I got 3998. But in table given in datasheet of PIC32 does not have this value.

Here I am giving related information about code.

#define GetSystemClock()            (SYS_CLOCK)
#define GetPeripheralClock()        (SYS_CLOCK/2)
#define GetInstructionClock()       (SYS_CLOCK)
#define I2C_CLOCK_FREQ              5000

// EEPROM Constants
#define EEPROM_I2C_BUS              I2C1
#define EEPROM_ADDRESS              0x50        // 0b1010000 Serial EEPROM address

 actualClock = I2CSetFrequency(EEPROM_I2C_BUS, GetPeripheralClock(), I2C_CLOCK_FREQ);
    if ( abs(actualClock-I2C_CLOCK_FREQ) > I2C_CLOCK_FREQ/10 )
        DBPRINTF("Error: I2C1 clock frequency (%u) error exceeds 10%%.\n", (unsigned)actualClock);

UINT32 I2CSetFrequency ( I2C_MODULE id, UINT32 sourceClock, UINT32 i2cClock )
      I2C_REGISTERS * const i2cRegisters = i2cBase[id];

      i2cRegisters->I2CxBRG = ( (sourceClock/i2cClock)/2 ) - 2;

      return( ( sourceClock/(i2cRegisters->I2CxBRG + 2) )/2 );


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
Of course there won't be values in that table of 3998 because all those entries in the table are for I2C clocks of 100kHz or 400kHz but you are trying to calculate a BRG value for an I2C clock of 5kHz.

I guess the question is... why are you worried about if the value is in that table or not? That table is just "examples" of the values you would use in those specific situations. It's not a table of the "only" possible values that you are allowed to use.

skadulkarAuthor Commented:
Thanks mccart.
skadulkarAuthor Commented:
   In above code, SYS_CLOCK is not #defined anywhere.still it is not giving any error in original code. And i copy pasted the same code , it was giving an error that HardwareProfile.h file not found so i gave full path. But now it is giving me an error that SYS_CLOCK is undeclared.

Now my question How it is not giving any error in original code. And as i copy pasted the same code but it is showing an error.

Powerful Yet Easy-to-Use Network Monitoring

Identify excessive bandwidth utilization or unexpected application traffic with SolarWinds Bandwidth Analyzer Pack.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
No idea, since you haven't posted any of the code that you are talking about.

However, this is a totally different question so you should open a new question about this. You will get more people looking at the new question and that way, a better chance of getting the right help.
Check your line terminations.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Hmmmm.... how does the accepted answer relate to the _original_ question in any way?
That was the solution to the 08/17/10 05:34 AM question but not the original question - I think the points should be split
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.