• AVR Freaks

Hot!Pressure measurement using bmp180 with pic16f1509

Author
faruk97
New Member
  • Total Posts : 14
  • Reward points : 0
  • Joined: 2020/06/11 15:23:49
  • Location: 0
  • Status: offline
2020/08/03 04:04:58 (permalink)
2 (1)

Pressure measurement using bmp180 with pic16f1509

Hello friends,
I'm dealing with a pressure measurement project. I use pic16f1509 and bmp180 in this project. But some things have problems.
I cannot see the measurements in the simulation program. I can only see the first post I printed.I think I have some errors in BMP180_I2C_bus_write / BMP180_I2C_bus_read functions in the main.c file of the program. Can you help me ? thank you so much.
KODS:
s8 BMP180_I2C_bus_read(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
{
    s32 iError = BMP180_INIT_VALUE;
    u8 array[I2C_BUFFER_LEN] = { BMP180_INIT_VALUE };
    u8 stringpos = BMP180_INIT_VALUE;

    array[BMP180_INIT_VALUE] = reg_addr;
    //char available;
// Please take the below function as your reference
// * for read the data using I2C communication
// * add your I2C rad function here.
// * "IERROR = I2C_WRITE_READ_STRING(DEV_ADDR, ARRAY, ARRAY, C_BMP180_ONE_U8X, CNT)"
// * iError is an return value of SPI write function
// * Please select your valid return value
// * In the driver SUCCESS defined as BMP180_INIT_VALUE
// * and FAILURE defined as -C_BMP180_ONE_U8X
//
    
    i2c_basla();//START
    i2c_yaz(dev_addr<<1);//WRITE
    //adres_oku(dev_addr);//READ
    iError=i2c_yaz(array[0]);//WRITE
    i2c_yenidenbasla();//RESTART
    i2c_yaz(0xEF);//WRİTE
    
    //degisken=adres_oku(0xEF); //ADRESS READ
    //reg_data=
    //iError = adres_oku(dev_addr);
    
    
 //
  //Wire.requestFrom(BMP180_ADDR,length);
       // requestFrom(BMP180_ADDR,cnt);
        //softi2c_yenidenbaslat();
  //while(available != cnt); // wait until bytes are ready*/
    //if (iError == 0)
 //{
        
        //array=i2c_oku();
    
    for (stringpos = BMP180_INIT_VALUE; stringpos < cnt; stringpos++)
        {
            
            char ack;
            ack=1;
            array[stringpos]=( (adres_oku(1)<<8)+adres_oku(ack) );
            *(reg_data + stringpos) = array[stringpos];
            if(stringpos==(cnt-1)) ack=0;
            else ack=1;
        }
        i2c_dur();
    //}
    /*if (iError == 0)
        return(1);
 else
    return(0);*/
        iError=0;
    //return *reg_data;
    return (s8)iError;
}

 
s8 BMP180_I2C_bus_write(u8 dev_addr, u8 reg_addr, u8 *reg_data, u8 cnt)
{
    s32 iError = BMP180_INIT_VALUE;
    u8 array[I2C_BUFFER_LEN];
    u8 stringpos = BMP180_INIT_VALUE;
    
    array[BMP180_INIT_VALUE] = reg_addr;
    

    i2c_basla();//BASLA
    i2c_yaz(dev_addr<<1);//WRITE
    iError=i2c_yaz(array[0]);//WRITE
    //i2c_yaz(*reg_data);//WRITE
    i2c_dur();//STOP
    //i2c_yaz(dev_addr);//WRITE
    //iError=adres_oku(dev_addr);//READ
    
  //while(stringpos != cnt) ; // wait until bytes are ready
    for (stringpos = BMP180_INIT_VALUE; stringpos < cnt; stringpos++)
    {
        array[stringpos + BMP180_INITIALIZE_NUMBER_OF_SAMPLES_U8X] = *(reg_data + stringpos);
    }
    //i2c_dur();
// *
// * Please take the below function as your reference for
// * write the data using I2C communication
// * "IERROR = I2C_WRITE_STRING(DEV_ADDR, ARRAY, CNT+C_BMP180_ONE_U8X)"
// * add your I2C write function here
// * iError is an return value of I2C read function
// * Please select your valid return value
// * In the driver SUCCESS defined as BMP180_INIT_VALUE
// * and FAILURE defined as -C_BMP180_ONE_U8X
// * Note :
// * This is a full duplex operation,
// * The first read data is discarded, for that extra write operation
// * have to be initiated. For that cnt+C_BMP180_ONE_U8X operation done in the I2C write string function
// * For more information please refer data sheet SPI communication:
// *
    /*if (iError == 0)
  return(1);
 else
  return(0);*/
    
    return (s8)iError;
   // return *reg_data;
}

post edited by faruk97 - 2020/08/03 06:24:21

Attached Image(s)

#1

0 Replies Related Threads

    Jump to:
    © 2020 APG vNext Commercial Version 4.5