embedded c

Posted on 2010-08-16
Last Modified: 2012-05-10
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 );


Question by:skadulkar
  • 3
  • 2
  • 2
LVL 35

Expert Comment

ID: 33451639
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.


Author Comment

ID: 33451656
Thanks mccart.

Author Comment

ID: 33451677
   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.

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

LVL 35

Expert Comment

ID: 33451798
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.
LVL 11

Accepted Solution

cup earned 500 total points
ID: 33461319
Check your line terminations.
LVL 35

Expert Comment

ID: 33594652
Hmmmm.... how does the accepted answer relate to the _original_ question in any way?
LVL 11

Expert Comment

ID: 33599244
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

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at  To view more iPhone tutorials, visit This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

937 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now