Solved

embedded c

Posted on 2010-08-16
7
1,087 Views
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 );
}

Regards,
shailendra.

 PIC32-Family-Reference-Manual--S.pdf
0
Comment
Question by:skadulkar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 35

Expert Comment

by:mccarl
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.

0
 

Author Comment

by:skadulkar
ID: 33451656
Thanks mccart.
0
 

Author Comment

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

Shailendra.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:mccarl
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.
0
 
LVL 11

Accepted Solution

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

Expert Comment

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

Expert Comment

by:cup
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
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-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.

738 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