Solved

embedded c

Posted on 2010-08-16
7
1,082 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
  • 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
Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

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 (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops 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