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.

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Microsoft vcsetup.exe and vcssetup.exe 8 424
Using unmanaged DLL from managed application 14 294
Grammars for C C++ and java 1 122
How to install SVN Command Line Client? 5 67
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode ( They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

821 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