Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6691857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:48:02+00:00 2026-05-26T05:48:02+00:00

I’m interfacing a Rabbit 5760 CPU to a Bosch BMP085 sensor via I2C. Everything

  • 0

I’m interfacing a Rabbit 5760 CPU to a Bosch BMP085 sensor via I2C. Everything is fine except reading the temperature register is reading back 0xffff (see BP_FINISHTEMP case in switch). I can’t see why it isn’t working. The code is below. Can anyone see what’s wrong? The pressure and calibration values read back fine. Thanks if anyone can help.

    // baro.lib, Barometer related functions

/*** BeginHeader InitBarometer, ReadBarometer */
int InitBarometer(void);
int ReadBarometer(void); // has 4 phases

/*** EndHeader */

// this all comes from the barometer data sheet
struct s_baroparams {
    short ac1;
    short ac2;
    short ac3;
    unsigned short ac4;
    unsigned short ac5;
    unsigned short ac6;
    short b1;
    short b2;
    short mb;
    short mc;
    short md;
} baroparams;
enum {BP_FAIL,BP_STARTTEMP,BP_FINISHTEMP,BP_STARTPRESSURE,BP_FINISHPRESSURE} BarometerPhase;
unsigned long LastBarometerStartTime;
long baro_ut;
long baro_up;

// Returns TRUE if successful, else FALSE
int InitBarometer(void) {
    char *ptmp;
       char hi,lo;
    int i;

    assert(Stack_Low());

    BarometerPhase = BP_FAIL;
    // OLD CODE THAT USED TO USE PORT B FOR I2C
    // cannot use i2c_init because it assumes port D
       // so these lines sorta replace it
       // PB1,PB3,PB5 are SCL, SDA, and XCLR on the barometer
       // we want pb1 and pb3 to be low inputs to let the pullups work, and pb5 to be low, output, then high output

    // These pins assigned to portD for the HS4, used to be port B
    /*
    WrPortI(PDDR,&PDDRShadow,0); // all low to start
    WrPortI(PDDDR,&PDDDRShadow,(1<<5)); // all inputs except pd5
    WrPortI(PDDR,&PDDRShadow,PDDRShadow|(1<<5)); // now pd5 is high
    */

    // pull baro. sensor out of reset by setting XLR high (XLR is port D bit 1).
    // This assumes we'll want it out of reset before initting the I2C interface,
    // VERIFY THIS
    BitWrPortI(PDDDR,&PDDDRShadow,1,1);
    BitWrPortI(PDDR,&PDDRShadow,1,1);

    i2c_init();

   // i2c_clocks_per_us = (int)(19200L*32*freq_divider/1000000L);

       // evil evil hack here
       ptmp = (char *)&baroparams.ac1;
       for (i=0;i<11;i++) {    // 11 is number of 2-byte values in baroparams above
        // start condition
           if (i2c_start_tx()) {
            return FALSE;
           }
           // send ef
           if (i2c_write_char(0xee))
            return FALSE;
           if (i2c_write_char(0xaa+i*2))
            return FALSE;
           if (i2c_start_tx()) {
            return FALSE;
           }
           if (i2c_write_char(0xef))
            return FALSE;
           if (i2c_read_char(&hi))
            return FALSE;
           i2c_send_ack();
           if (i2c_read_char(&lo))
            return FALSE;
           i2c_send_nak();
           // stop condition
           i2c_stop_tx();
          *ptmp++ = lo;
          *ptmp++ = hi;
    }
    BarometerPhase = BP_STARTTEMP;
       LastBarometerStartTime = 0;

       return TRUE;
}

// Return -1 if failed, 0 if success
int ReadBarometer()    {
    unsigned long dt;
//   unsigned char hi,lo,xlo;
       union { long l; unsigned char uc[4]; } u;
       long x1,x2,x3,b3,b5,b6,b7,t,p;
       unsigned long b4;
       long b6x;

    assert(Stack_Low());

       switch (BarometerPhase) {
        case BP_FAIL:
              return -1;
        case BP_STARTTEMP:
               if (i2c_start_tx()) {
                return -1;
               }
              if (i2c_write_char(0xee))
                return -1;
              if (i2c_write_char(0xf4))
                return -1;
              if (i2c_write_char(0x2e))
                 return -1;
              i2c_stop_tx();
             BarometerPhase = BP_FINISHTEMP;
             LastBarometerStartTime = MS_TIMER;
             break;
        case BP_FINISHTEMP:
              u.l = 0;
            dt = MS_TIMER - LastBarometerStartTime;
             if (dt < 6) break;

             if (i2c_start_tx()) {
                return -1;
               }
              if (i2c_write_char(0xee))
                return -1;
              if (i2c_write_char(0xf6))
                return -1;
               if (i2c_start_tx()) {
                return -1;
               }
              if (i2c_write_char(0xef))
                return -1;
              if (i2c_read_char(&u.uc[1]))
                return -1;
              i2c_send_ack();
              if (i2c_read_char(&u.uc[0]))
                return -1;
              i2c_send_nak();
              i2c_stop_tx();
            baro_ut = u.l; // THIS IS THE PROBLEM U.L IS 0XFFFF HERE ******************************
            BarometerPhase = BP_STARTPRESSURE;
             break;
        case BP_STARTPRESSURE:
               if (i2c_start_tx()) {
                return -1;
               }
              if (i2c_write_char(0xee))
                return -1;
              if (i2c_write_char(0xf4))
                return -1;
              if (i2c_write_char(0x34+(BARO_OSS<<6)))
                return -1;
              i2c_stop_tx();
             BarometerPhase = BP_FINISHPRESSURE;
             LastBarometerStartTime = MS_TIMER;
             break;
          case BP_FINISHPRESSURE:
            u.l = 0;
            dt = MS_TIMER - LastBarometerStartTime;
             if (dt < BARO_TIME) break;
               if (i2c_start_tx()) {
                return -1;
               }
              if (i2c_write_char(0xee))
                return -1;
              if (i2c_write_char(0xf6))
                return -1;
               if (i2c_start_tx()) {
                return -1;
               }
              if (i2c_write_char(0xef))
                return -1;
              if (i2c_read_char(&u.uc[2]))
                return -1;
              i2c_send_ack();
              if (i2c_read_char(&u.uc[1]))
                return -1;
              i2c_send_ack();
              if (i2c_read_char(&u.uc[0]))
                return -1;
              i2c_send_nak();
              i2c_stop_tx();
             baro_up = u.l >> (8-BARO_OSS);

            // need lots of work here
            x1 = ((baro_ut-baroparams.ac6)*baroparams.ac5) >> 15;
              x2 = (((long)baroparams.mc)<<11)/(x1+baroparams.md);
              b5 = x1+x2;
              t = (b5+8)>>4;
//          sprintf(g_Temperature,"%ld",t);
            // append units
            gf_Temperature = t / 10.0;
            if (gConfiguration.tempUnits == Celcius) {
                sprint_fixedpoint(g_Temperature,t,1);
                strlcat(g_Temperature, "&deg;C", sizeof g_Temperature);
            }
            else {
                sprint_fixedpoint(g_Temperature, CelciusToF(t), 1);
                strlcat(g_Temperature, "&deg;F", sizeof g_Temperature);
            }
            b6 = b5 - 4000;
            b6x = (b6*b6)>>12;
             x1 = (baroparams.b2*b6x)>>11;
             x2 = (baroparams.ac2*b6)>>11;
            x3 = x1 + x2;
             b3 = ((((long)baroparams.ac1*4+x3)<<BARO_OSS)+2)/4;

             x1 = (baroparams.ac3*b6)>>13;
             x2 = (baroparams.b1*b6x)>>16;
             x3 = ((x1+x2)+2)>>2;
             b4 = baroparams.ac4*(unsigned long)(x3+32768)>>15;
             b7 = ((unsigned long)baro_up-b3)*(50000>>BARO_OSS);
             if (b7 < 0x80000000)
                 p = (b7*2)/b4;
             else
                 p = (b7/b4)*2;
             x1 = (p>>8)*(p>>8);
             x1 = (x1*3038)>>16;
             x2 = (-7357*p)>>16;
             p = p + ((x1+x2+3791)>>4);

            gf_Pressure = p / 100.0;
            // append units
            if (gConfiguration.baroUnits == Millibars) {
                sprint_fixedpoint(g_Pressure,p,2);
                strlcat(g_Pressure, " millibars", sizeof g_Pressure);
            }
            else {
                sprint_fixedpoint(g_Pressure, millibarsToInHg(p), 2);
                strlcat(g_Pressure, " inHg", sizeof g_Pressure);
            }
            BarometerPhase = BP_STARTTEMP;
        break;
    }

    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:48:03+00:00Added an answer on May 26, 2026 at 5:48 am

    Turns out it was bad hardware. A new batch of chips works fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.