• AVR Freaks

Hot!BMP180 and pic 18F452

Author
alejandrodaniel
New Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2020/06/07 03:44:09
  • Location: 0
  • Status: offline
2020/09/12 13:19:39 (permalink)
0

BMP180 and pic 18F452

hi, I'm trying to make the 18F452 talk to a BMP180.
I2C communication with the BMP180 gives me these results
AC1 = -1
AC2 = -1
AC3 = -1
AC4 = -1
AC5 = -1
AC6 = -1
MB = -1
MC = -1
MD = -1
UP_MSB = 255
UP_LSB = 255
UP_XLSB = 255
UP = -1
UT = -1
I have read the datasheets hundreds of times, and I cannot understand the reason for these values.
provided that the I2C routine is the same with which the pic communicates with other peripherals.
internet is full of arduino with its libraries, but there are no examples with microchips.
do you have any documentation I can consult?
#1

8 Replies Related Threads

    katela
    Super Member
    • Total Posts : 1877
    • Reward points : 0
    • Joined: 2013/06/11 05:25:18
    • Location: South Africa
    • Status: offline
    Re: BMP180 and pic 18F452 2020/09/12 13:51:01 (permalink)
    0 (2)
    You didn't any of your code, it's difficult for anybody to comment.

    Free online Microcontroller Tutorials and Projects for Hobbyists and students. From beginners to advanced. Website: www.studentcompanion.co.za
    YouTube Tutorials: https://www.youtube.com/StudentCompanionSA
    #2
    typematrix
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2019/03/04 08:11:26
    • Location: Ireland
    • Status: offline
    Re: BMP180 and pic 18F452 2020/09/12 14:12:13 (permalink)
    +1 (1)
    Hi 
     
    Are you reading the correct datasheet? here:
    https://media.digikey.com/pdf/Data%20Sheets/Bosch/BMP180.pdf
    Page 15 shows the calculation for that data. and gives example data for a typical read for a given value
    Those values you have look like "nothing" , not data. What did you read them back with?
    Here is a working example for a PIC16F18346 + BMP180   
    https://github.com/gavinlyonsrepo/pic_16F18346_projects/tree/master/projects/bmp180
     
    regards
    #3
    alejandrodaniel
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2020/06/07 03:44:09
    • Location: 0
    • Status: offline
    Re: BMP180 and pic 18F452 2020/09/14 01:45:23 (permalink)
    0
    ok,it's the same datasheet.here are the values ​​measured by I2C
    AC1 = -1
    AC2 = -1
    AC3 = -1
    AC4 = -1
    AC5 = -1
    AC6 = -1
    MB = -1
    MC = -1
    MD = -1
    UP_MSB = 255
    UP_LSB = 255
    UP_XLSB = 255
    UP = -1
    UT_H = 255
    UT_L = 255
    UT = -1

     
    and this is the code for 18F452 with xc8 and mplab.given that i2c functions are fine with HMC5883L and MPU6050
    /*
     * File: 18F452_BMP180.c
     * Author: alejandro
     *
     * Created on 2 agosto 2020, 20.54
     */

    #include <xc.h>
    #include <pic18f452.h>
    #include <stdio.h>
    #include <stdlib.h>

    // CONFIG1H
    #pragma config OSC=HS // Oscillator Selection bits (HS oscillator)
    #pragma config OSCS=ON // Oscillator System Clock Switch Enable bit (Oscillator system clock switch option is enabled (oscillator switching is enabled))
    // CONFIG2L
    #pragma config PWRT=OFF // Power-up Timer Enable bit (PWRT enabled)
    #pragma config BOR=ON // Brown-out Reset Enable bit (Brown-out Reset enabled)
    #pragma config BORV=27 // Brown-out Reset Voltage bits (VBOR set to 2.0V)
    // CONFIG2H
    #pragma config WDT=OFF // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
    #pragma config WDTPS=1 // Watchdog Timer Postscale Select bits (1:1)
    // CONFIG3H
    #pragma config CCP2MUX=ON // CCP2 Mux bit (CCP2 input/output is multiplexed with RC1)
    // CONFIG4L
    #pragma config STVR=ON // Stack Full/Underflow Reset Enable bit (Stack Full/Underflow will cause RESET)
    #pragma config LVP=OFF // Low Voltage ICSP Enable bit (Low Voltage ICSP disabled)
    // CONFIG5L
    #pragma config CP0=OFF // Code Protection bit (Block 0 (000200-001FFFh) not code protected)
    #pragma config CP1=OFF // Code Protection bit (Block 1 (002000-003FFFh) not code protected)
    #pragma config CP2=OFF // Code Protection bit (Block 2 (004000-005FFFh) not code protected)
    #pragma config CP3=OFF // Code Protection bit (Block 3 (006000-007FFFh) not code protected)
    // CONFIG5H
    #pragma config CPB=OFF // Boot Block Code Protection bit (Boot Block (000000-0001FFh) not code protected)
    #pragma config CPD=OFF // Data EEPROM Code Protection bit (Data EEPROM not code protected)
    // CONFIG6L
    #pragma config WRT0=OFF // Write Protection bit (Block 0 (000200-001FFFh) not write protected)
    #pragma config WRT1=OFF // Write Protection bit (Block 1 (002000-003FFFh) not write protected)
    #pragma config WRT2=OFF // Write Protection bit (Block 2 (004000-005FFFh) not write protected)
    #pragma config WRT3=OFF // Write Protection bit (Block 3 (006000-007FFFh) not write protected)
    // CONFIG6H
    #pragma config WRTC=OFF // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write protected)
    #pragma config WRTB=OFF // Boot Block Write Protection bit (Boot Block (000000-0001FFh) not write protected)
    #pragma config WRTD=OFF // Data EEPROM Write Protection bit (Data EEPROM not write protected)
    // CONFIG7L
    #pragma config EBTR0=OFF // Table Read Protection bit (Block 0 (000200-001FFFh) not protected from Table Reads executed in other blocks)
    #pragma config EBTR1=OFF // Table Read Protection bit (Block 1 (002000-003FFFh) not protected from Table Reads executed in other blocks)
    #pragma config EBTR2=OFF // Table Read Protection bit (Block 2 (004000-005FFFh) not protected from Table Reads executed in other blocks)
    #pragma config EBTR3=OFF // Table Read Protection bit (Block 3 (006000-007FFFh) not protected from Table Reads executed in other blocks)
    // CONFIG7H
    #pragma config EBTRB=OFF //Boot Block Table Read Protection bit (Boot Block (000000-0001FFh) not protected from Table Reads executed in other blocks)
    #pragma warning disable 752
    #pragma warning disable 520
    // FREQUENCY CLOCK
    #define _XTAL_FREQ 20000000
    //CONSTANTE
    #define OSS 0x01

    short AC1,AC2,AC3,B1,B2,MC,MD;
    long MB,UP_MSB,UP_LSB,UP_XLSB;
    unsigned short UT_H,UT_L,AC4,AC5,AC6;
    long UT,UP,B5,Altitud;
    unsigned long B7;

    //---------------------------- INTERRUPT ---------------------------------------
    void __interrupt() ISR()
         {
          //CODIGO
         }

    //--------------------------- CONFIGURACIÒN PIC --------------------------------
    void Config_PIC(void)
         {
          TRISA=0b00000000;
          TRISB=0b00000000;
          TRISC=0b00011000;
          TRISD=0b00000000;
          TRISE=0b000;
          PORTA=0b00000000;
          PORTB=0b00000000;
          PORTC=0b00000000;
          PORTD=0b00000000;
          PORTE=0b000;
          LATA=0b000000000;
          LATB=0b00000000;
          LATC=0b00000000;
          LATD=0b00000000;
          LATE=0b000;
          RCONbits.IPEN=0;
          INTCON=0b00000000;
          INTCON2=0b10000000;
          INTCON3=0b00000000;
          PIR1=0b00000000;
          PIR2=0b00000000;
          PIE1=0b00000000;
          PIE2=0b00000000;
          IPR1=0b00000000;
          IPR2=0b00000000;
          ADCON0=0b00000000;
          ADCON1=0b00000110;
         }

    //--------------------------- GESTIÒN I2C --------------------------------------
    void Config_I2C()
         {
          SSPSTATbits.SMP=1; //Controllo della velocità disabilitato per la modalità velocità standard (100 kHz e 1 MHz)
          SSPADD=49;
          SSPCON1bits.WCOL=0;
          SSPCON1bits.SSPOV=0;
          SSPCON1bits.SSPEN=1;
          SSPCON1bits.CKP=0;
          SSPCON1bits.SSPM0=0; //I2C Master,Clock=FOSC/(4 * (SSPADD+1))
          SSPCON1bits.SSPM1=0;
          SSPCON1bits.SSPM2=0;
          SSPCON1bits.SSPM3=1;
          PIR1bits.SSPIF=0;
          PIR2bits.BCLIF=0;
         }

    void W_MSSP_I2C(void)
         {
          while((SSPCON2&0x1F)||(SSPSTAT&0x04));
         }

    void Start_I2C(void)
         {
          SEN=1;
          while(SEN);
         }

    void ReStart_I2C(void)
         {
          RSEN=1;
          while(RSEN);
         }

    void Stop_I2C(void)
         {
          PEN=1;
          while(PEN);
         }

    void Tx_I2C(unsigned char SendByte)
         {
          SSPBUF=SendByte;
          while(BF);
          W_MSSP_I2C();
         }

    unsigned char Rx_I2C(unsigned char vACK)
         {
          unsigned char ReadByte;
          RCEN=1;
          while(!BF);
          ReadByte=SSPBUF;
          if(vACK==0)
            {
             ACKDT=0;
            }
          else
            {
             ACKDT=1;
            }
          ACKEN=1;
          W_MSSP_I2C();
          return ReadByte;
         }

    void Wr_I2C(unsigned char IDAddress,unsigned short Address,unsigned short Dato)
         {
          Start_I2C();
          Tx_I2C(IDAddress);
          Tx_I2C(Address);
          Tx_I2C(Dato);
          Stop_I2C();
          __delay_ms(25);
         }

    long Rd_I2C(unsigned char IDAddress,unsigned short Address)
         {
          long Respuesta;
          Start_I2C();
          Tx_I2C(IDAddress);
          Tx_I2C(Address);
          ReStart_I2C();
          Tx_I2C(IDAddress+1);
          Respuesta=Rx_I2C(1);
          Stop_I2C();
          __delay_ms(5);
          return Respuesta;
         }

    void Wr_I2C_Eeprom(unsigned char IDAddress,unsigned short Address,unsigned short Dato)
         {
          Start_I2C();
          Tx_I2C(IDAddress);
          Tx_I2C(Address>>8);
          Tx_I2C(Address);
          Tx_I2C(Dato);
          Stop_I2C();
          __delay_ms(25);
         }

    unsigned int Rd_I2C_Eeprom(unsigned char IDAddress,unsigned int Address)
         {
          unsigned int Respuesta;
          Start_I2C();
          Tx_I2C(IDAddress);
          Tx_I2C(Address>>8);
          Tx_I2C(Address);
          ReStart_I2C();
          Tx_I2C(IDAddress+1);
          Respuesta=Rx_I2C(1);
          Stop_I2C();
          __delay_ms(25);
          return Respuesta;
         }

    //--------------------------- GESTION USART ------------------------------------
    void Config_UART()
         {
          SYNC=0;
          SPBRG=32;
          BRGH=0;
          TXSTAbits.CSRC=0;
          TXSTAbits.TX9=0;
          TXSTAbits.TXEN=1;
          TXSTAbits.SYNC=0;
          TXSTAbits.TX9D=0;
          RCSTAbits.SPEN=1;
          RCSTAbits.RX9=0;
          RCSTAbits.SREN=0;
          RCSTAbits.CREN=0;
          RCSTAbits.ADDEN=0;
          RCSTAbits.RX9D=0;
          PIE1bits.TXIE=0;
         }

    void Tx_UART(char Dato)
         {
          while(!TRMT);
          TXREG=Dato;
         }

    char Tx_UART_Empty()
         {
          return TRMT;
         }

    void Tx_strUART(const char *Caracter,unsigned short Escape)
         {
          while(*Caracter)
               {
                Tx_UART(*Caracter);
                Caracter++;
               }
          if(Escape==1)Tx_UART('\n');
         }

    //--------------------------- BMP180 -------------------------------------------
    void Lectura_BMP180(void)
         {
          //Lectura Eeprom
          Start_I2C();
          Tx_I2C(0xEE);
          Tx_I2C(0xAA);
          ReStart_I2C();
          Tx_I2C(0xEF);
          AC1=Rx_I2C(0)<<8|Rx_I2C(0);
          AC2=Rx_I2C(0)<<8|Rx_I2C(0);
          AC3=Rx_I2C(0)<<8|Rx_I2C(0);
          AC4=Rx_I2C(0)<<8|Rx_I2C(0);
          AC5=Rx_I2C(0)<<8|Rx_I2C(0);
          AC6=Rx_I2C(0)<<8|Rx_I2C(0);
          B1=Rx_I2C(0)<<8|Rx_I2C(0);
          B2=Rx_I2C(0)<<8|Rx_I2C(0);
          MB=Rx_I2C(0)<<8|Rx_I2C(0);
          MC=Rx_I2C(0)<<8|Rx_I2C(0);
          MD=Rx_I2C(0)<<8|Rx_I2C(1);
          Stop_I2C();
          __delay_ms(5);
          //Lectura Temperatura raw
          Start_I2C();
          Tx_I2C(0xEE);
          Tx_I2C(0xF4);
          Tx_I2C(0x2E);
          Stop_I2C();
          __delay_ms(20);
          Start_I2C();
          Tx_I2C(0xEE);
          Tx_I2C(0xF6);
          ReStart_I2C();
          Tx_I2C(0xEF);
          UT_H=Rx_I2C(0);
          UT_L=Rx_I2C(1);
          Stop_I2C();
          UT=UT_H<<8|UT_L;
          __delay_ms(5);
          //Lectura Presion raw
          Start_I2C();
          Tx_I2C(0xEE);
          Tx_I2C(0xF4);
          Tx_I2C(0x34+(OSS<<6));
       __delay_ms(20);
          Start_I2C();
          Tx_I2C(0xEE);
          Tx_I2C(0xF6);
          ReStart_I2C();
          Tx_I2C(0xEF);
          UP_MSB=Rx_I2C(0);
          UP_LSB=Rx_I2C(0);
          UP_XLSB=Rx_I2C(1);
          Stop_I2C();
          UP=((UP_MSB<<16)+(UP_LSB<<8)+UP_XLSB)>>8;
         }

    //--------------------------- CICLO --------------------------------------------
    void main(void)
         {
          char Datos[20];
          Config_PIC();
          Config_I2C();
          Config_UART();
          __delay_ms(100);
          while(1)
               {
                Lectura_BMP180();
                sprintf(Datos,"AC1 = %d",AC1);
                Tx_strUART(Datos,1);
                sprintf(Datos,"AC2 = %d",AC2);
                Tx_strUART(Datos,1);
                sprintf(Datos,"AC3 = %d",AC3);
                Tx_strUART(Datos,1);
                sprintf(Datos,"AC4 = %d",AC4);
                Tx_strUART(Datos,1);
                sprintf(Datos,"AC5 = %d",AC5);
                Tx_strUART(Datos,1);
                sprintf(Datos,"AC6 = %d",AC6);
                Tx_strUART(Datos,1);
                sprintf(Datos,"MB = %d",MB);
                Tx_strUART(Datos,1);
                sprintf(Datos,"MC = %d",MC);
                Tx_strUART(Datos,1);
                sprintf(Datos,"MD = %d",MD);
                Tx_strUART(Datos,1);
                sprintf(Datos,"UP_MSB = %d",UP_MSB);
                Tx_strUART(Datos,1);
                sprintf(Datos,"UP_LSB = %d",UP_LSB);
                Tx_strUART(Datos,1);
                sprintf(Datos,"UP_XLSB = %d",UP_XLSB);
                Tx_strUART(Datos,1);
                sprintf(Datos,"UP = %d",UP);
                Tx_strUART(Datos,1);
                sprintf(Datos,"UT_H = %d",UT_H);
                Tx_strUART(Datos,1);
                sprintf(Datos,"UT_L = %d",UT_L);
                Tx_strUART(Datos,1);
                sprintf(Datos,"UT = %d",UT);
                Tx_strUART(Datos,1);
                Tx_strUART("----------------",1);
                __delay_ms(2000);
               }
         }

     
    I will study the code you posted to me.sorry for english, but i use google translate.
    #4
    alejandrodaniel
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2020/06/07 03:44:09
    • Location: 0
    • Status: offline
    Re: BMP180 and pic 18F452 2020/09/17 02:59:33 (permalink)
    0
    ops. it was a hardware problem. the i2c bus works and the peripherals work fine. only I have a problem calculating the data of BMP180. something is amiss.
    #5
    ric
    Super Member
    • Total Posts : 28660
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: BMP180 and pic 18F452 2020/09/17 05:20:11 (permalink)
    +2 (2)
    Don't put "code" tags around normal text, that makes it really hard to read.
    alejandrodaniel
    ops. it was a hardware problem. the i2c bus works and the peripherals work fine. only I have a problem calculating the data of BMP180. something is amiss.




    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #6
    alejandrodaniel
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2020/06/07 03:44:09
    • Location: 0
    • Status: offline
    Re: BMP180 and pic 18F452 2020/09/19 04:44:53 (permalink)
    0
    the i2c bus is working now.
    But I have a problem with the pressure conversion. The temperature is correct.
    I run the algorithm according to the datasheet in Gambas3 and the data match.
    but the same algorithm in mplab from these values ​​which do not match according to the datasheet example.
    PIC Gambas3 Datasheet(example)
    Temperatura = 29.00°C 15,05°C 15°C
    Presion = 72245.00Pa 69965,73Pa 69965Pa

    this is the code
    #include <xc.h>
    #include <pic18f452.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>

    // CONFIG1H
    #pragma config OSC=HS // Oscillator Selection bits (HS oscillator)
    #pragma config OSCS=ON // Oscillator System Clock Switch Enable bit (Oscillator system clock switch option is enabled (oscillator switching is enabled))
    // CONFIG2L
    #pragma config PWRT=OFF // Power-up Timer Enable bit (PWRT enabled)
    #pragma config BOR=ON // Brown-out Reset Enable bit (Brown-out Reset enabled)
    #pragma config BORV=27 // Brown-out Reset Voltage bits (VBOR set to 2.0V)
    // CONFIG2H
    #pragma config WDT=OFF // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
    #pragma config WDTPS=1 // Watchdog Timer Postscale Select bits (1:1)
    // CONFIG3H
    #pragma config CCP2MUX=ON // CCP2 Mux bit (CCP2 input/output is multiplexed with RC1)
    // CONFIG4L
    #pragma config STVR=ON // Stack Full/Underflow Reset Enable bit (Stack Full/Underflow will cause RESET)
    #pragma config LVP=OFF // Low Voltage ICSP Enable bit (Low Voltage ICSP disabled)
    // CONFIG5L
    #pragma config CP0=OFF // Code Protection bit (Block 0 (000200-001FFFh) not code protected)
    #pragma config CP1=OFF // Code Protection bit (Block 1 (002000-003FFFh) not code protected)
    #pragma config CP2=OFF // Code Protection bit (Block 2 (004000-005FFFh) not code protected)
    #pragma config CP3=OFF // Code Protection bit (Block 3 (006000-007FFFh) not code protected)
    // CONFIG5H
    #pragma config CPB=OFF // Boot Block Code Protection bit (Boot Block (000000-0001FFh) not code protected)
    #pragma config CPD=OFF // Data EEPROM Code Protection bit (Data EEPROM not code protected)
    // CONFIG6L
    #pragma config WRT0=OFF // Write Protection bit (Block 0 (000200-001FFFh) not write protected)
    #pragma config WRT1=OFF // Write Protection bit (Block 1 (002000-003FFFh) not write protected)
    #pragma config WRT2=OFF // Write Protection bit (Block 2 (004000-005FFFh) not write protected)
    #pragma config WRT3=OFF // Write Protection bit (Block 3 (006000-007FFFh) not write protected)
    // CONFIG6H
    #pragma config WRTC=OFF // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write protected)
    #pragma config WRTB=OFF // Boot Block Write Protection bit (Boot Block (000000-0001FFh) not write protected)
    #pragma config WRTD=OFF // Data EEPROM Write Protection bit (Data EEPROM not write protected)
    // CONFIG7L
    #pragma config EBTR0=OFF // Table Read Protection bit (Block 0 (000200-001FFFh) not protected from Table Reads executed in other blocks)
    #pragma config EBTR1=OFF // Table Read Protection bit (Block 1 (002000-003FFFh) not protected from Table Reads executed in other blocks)
    #pragma config EBTR2=OFF // Table Read Protection bit (Block 2 (004000-005FFFh) not protected from Table Reads executed in other blocks)
    #pragma config EBTR3=OFF // Table Read Protection bit (Block 3 (006000-007FFFh) not protected from Table Reads executed in other blocks)
    // CONFIG7H
    #pragma config EBTRB=OFF //Boot Block Table Read Protection bit (Boot Block (000000-0001FFh) not protected from Table Reads executed in other blocks)
    #pragma warning disable 752
    #pragma warning disable 520
    // FREQUENCY CLOCK
    #define _XTAL_FREQ 20000000
    //CONSTANTE
    #define OSS 0x00

    int AC1,AC2,AC3,B1,B2,MC,AC4,AC5,AC6;
    long MB,UP_MSB,UP_LSB,UP_XLSB,UT,UP,B5,B7,X1,X2,X3,B3,B4,B6,MD;
    float P,T,Altitud,P0;

    //---------------------------- INTERRUPT ---------------------------------------
    void __interrupt() ISR()
         {
          //CODIGO
         }

    //--------------------------- CONFIGURACIÒN PIC --------------------------------
    void Config_PIC(void)
         {
          TRISA=0b00000000;
          TRISB=0b00000000;
          TRISC=0b00011000;
          TRISD=0b00000000;
          TRISE=0b000;
          PORTA=0b00000000;
          PORTB=0b00000000;
          PORTC=0b00000000;
          PORTD=0b00000000;
          PORTE=0b000;
          LATA=0b000000000;
          LATB=0b00000000;
          LATC=0b00000000;
          LATD=0b00000000;
          LATE=0b000;
          RCONbits.IPEN=0;
          INTCON=0b00000000;
          INTCON2=0b10000000;
          INTCON3=0b00000000;
          PIR1=0b00000000;
          PIR2=0b00000000;
          PIE1=0b00000000;
          PIE2=0b00000000;
          IPR1=0b00000000;
          IPR2=0b00000000;
          ADCON0=0b00000000;
          ADCON1=0b00000110;
         }

    //--------------------------- GESTION USART ------------------------------------
    void Config_UART()
         {
          SYNC=0;
          SPBRG=32;
          BRGH=0;
          TXSTAbits.CSRC=0;
          TXSTAbits.TX9=0;
          TXSTAbits.TXEN=1;
          TXSTAbits.SYNC=0;
          TXSTAbits.TX9D=0;
          RCSTAbits.SPEN=1;
          RCSTAbits.RX9=0;
          RCSTAbits.SREN=0;
          RCSTAbits.CREN=0;
          RCSTAbits.ADDEN=0;
          RCSTAbits.RX9D=0;
          PIE1bits.TXIE=0;
         }

    void Tx_UART(char Dato)
         {
          while(!TRMT);
          TXREG=Dato;
         }

    char Tx_UART_Empty()
         {
          return TRMT;
         }

    void Tx_strUART(const char *Caracter,unsigned short Escape)
         {
          while(*Caracter)
               {
                Tx_UART(*Caracter);
                Caracter++;
               }
          if(Escape==1)Tx_UART('\n');
         }

    //--------------------------- BMP180 -------------------------------------------
    void Lectura_BMP180(void)
         {
          AC1=408;
          AC2=-72;
          AC3=-14383;
          AC4=32741;
          AC5=32757;
          AC6=23153;
          B1=6190;
          B2=4;
          MB=-32768;
          MC=-8711;
          MD=2868;
          UT=27898;
          UP=23843;
          //Temperatura
          X1=(UT-AC6)*AC5/32768;
          X2=MC*2048/(X1+MD);
          B5=X1+X2;
          T=((B5+8)/16)/10;
          //Presion
          B6=B5-4000;
          X1=(B2*(B6*B6/4096))/2048;
          X2=AC2*B6/2048;
          X3=X1+X2;
          B3=(((AC1*4+3)<<OSS)+2)/4;
          X1=AC3*B6/8192;
          X2=(B1*((B6*B6)/4095))/65536;
          X3=((X1+X2)+2)/4;
          B4=AC4*(X3+32768)/32768;
          B7=(UP-B3)*(50000>>OSS);
          if(B7<0x80000000)
            {
             P=(B7*2)/B4;
            }
          else
            {
             P=(B7/B4)*2;
            }
          X1=(P/256)*(P/256);
          X1=(X1*3038)/65536;
          X2=(-7357*P)/65536;
          P=P+(X1+X2+3791)/16;
          P0=P;
         }

    //--------------------------- CICLO --------------------------------------------
    void main(void)
         {
          char Datos[30];
          Config_PIC();
          Config_I2C();
          Config_UART();
          __delay_ms(100);
          while(1)
               {
                Lectura_BMP180();
                sprintf(Datos,"Temperatura = %.2f",T);
                Tx_strUART(Datos,1);
                sprintf(Datos,"Presion = %.2f",P);
                Tx_strUART(Datos,1);
                Tx_strUART("--------------------",1);
                __delay_ms(500);
               }
         }


    [/code]
    what am I wrong?
    #7
    typematrix
    New Member
    • Total Posts : 17
    • Reward points : 0
    • Joined: 2019/03/04 08:11:26
    • Location: Ireland
    • Status: offline
    Re: BMP180 and pic 18F452 2020/09/19 11:31:36 (permalink)
    0
    Hi 
     
    In  line 164 
    B3=(((AC1*4+3)<<OSS)+2)/4;
     
    It should be 
     
    B3=(((AC1*4+X3)<<OSS)+2)/4;
     
    missing X
     
    Regards
     
     
    #8
    alejandrodaniel
    New Member
    • Total Posts : 14
    • Reward points : 0
    • Joined: 2020/06/07 03:44:09
    • Location: 0
    • Status: offline
    Re: BMP180 and pic 18F452 2020/09/19 15:28:37 (permalink)
    0 (2)
    oops, I haven't seen this. yet I have read and reread the code.
    tomorrow I make the correction and program the 18f452 ...... let's see.

     
    #9
    Jump to:
    © 2020 APG vNext Commercial Version 4.5