• AVR Freaks

Hot!PIC MCU with BMP280 temperature and pressure sensor

Author
abhi143
Junior Member
  • Total Posts : 109
  • Reward points : 0
  • Joined: 2018/05/20 09:06:52
  • Location: 0
  • Status: offline
2020/02/20 05:40:07 (permalink)
0

PIC MCU with BMP280 temperature and pressure sensor

 
I am looking help to understand code given here https://simple-circuit.com/pic16f877a-bmp280-sensor-ccs-c/
How does this part works 

while(TRUE)
{
// Read temperature (in hundredths C) and pressure (in Pa)
// values from BMP280 sensor
BMP280_readTemperature(&temperature); // read temperature
BMP280_readPressure(&pressure); // read pressure

}

 
There are two global variables temperature and pressure declared in codes 
BMP280_readTemperature(&temperature);  function pass location of  temperature variable 
BMP280_readPressure(&pressure); //  function pass location of  pressure variable
 
 Where is the data( temperature and pressure ) being stored in microcontroller and sensor ?
#1

13 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 18400
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: PIC MCU with BMP280 temperature and pressure sensor 2020/02/20 06:50:45 (permalink)
    +1 (1)
    The sensor communicates via SPI or I2C.
    #2
    rodims
    Super Member
    • Total Posts : 1555
    • Reward points : 0
    • Joined: 2009/02/10 11:08:59
    • Location: 51.9627, 7.6262
    • Status: online
    Re: PIC MCU with BMP280 temperature and pressure sensor 2020/02/20 07:09:31 (permalink)
    +2 (2)
    The link you provided contains another link to the "driver" source which they use.
    see the link after :
    Driver name is: BMP280_Lib.c.
    BMP280 CCS C driver
    which starts with

    BMP280_Lib.c ////
    //// ////
    //// Driver for CCS C compiler
    https://drive.google.com/file/d/1iIU7oCamRYSERjpxwQWoqJAZj7VEnpkL/view
     
    You should have seen this and this should answer your original question,
    however you still might have to deal with the basic i2c functions given there. 
    i2c is is just the (one possible) interface to the BMP280 chip. 
    And the code in the above link uses i2c.
     
    Microchip MCC library can provide the i2c functions, or you write it on your own.
    As a beginner, better do not write it on your own.
    I guess you are not asking for a datasheet for the BMP280, you can easily find that.
     
     
    #3
    Mysil
    Super Member
    • Total Posts : 3666
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: PIC MCU with BMP280 temperature and pressure sensor 2020/02/20 07:36:29 (permalink)
    +2 (2)
    Hi,
    Where is the data( temperature and pressure ) being stored in microcontroller?

    Short answer: Where your program code provide storage for those.
     
    Code you write in your (main) program, or a function you write,
    need to define storage for temperature and pressure like this:
    int32_t   temperature;
    uint32_t  pressure;

    those lines need to be before the place where those variables are used.
     
    Also, before that again, your code will need
     #include <stdint.h>
    #include "BMP280_Lib.h"

    if those lines are not in place already.
     
    The ampersand '&' before a variable names in function calls, 
    is indicating to the compiler that location (address, pointer) of the variable shall be used when function is called,
    such that the function can fill in the (new) value in the storage your code have defined.
     
    For information about how the sensor work, you will need to read the Datasheet for the sensor:
    https://www.bosch-sensortec.com/products/environmental-sensors/pressure-sensors/pressure-sensors-bmp280-1.html#documents
    open the 'Documents' tab in the webpage, and download or open the Datasheet document.
     
        Mysil
    #4
    abhi143
    Junior Member
    • Total Posts : 109
    • Reward points : 0
    • Joined: 2018/05/20 09:06:52
    • Location: 0
    • Status: offline
    Re: PIC MCU with BMP280 temperature and pressure sensor 2020/02/20 10:34:10 (permalink)
    0
    Mysil
    Hi,
    Where is the data( temperature and pressure ) being stored in microcontroller?

    Short answer: Where your program code provide storage for those.
    Code you write in your (main) program, or a function you write,
    need to define storage for temperature and pressure like this:
     
    those lines need to be before the place where those variables are used.

     BMP280 chip get the data and send it to microcontroller via I2C.  We have to store the data coming from the sensor in the program. I just want to know which variable is being stored in the data of the sensor 
     
    int32_t   temperature;
    uint32_t  pressure;

     
    Are these two variables ?
    #5
    1and0
    Access is Denied
    • Total Posts : 10550
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: PIC MCU with BMP280 temperature and pressure sensor 2020/02/20 10:47:06 (permalink)
    +2 (2)
    abhi143
    int32_t   temperature;
    uint32_t  pressure;

     
    Are these two variables ?

    Are you serious?
    #6
    Mysil
    Super Member
    • Total Posts : 3666
    • Reward points : 0
    • Joined: 2012/07/01 04:19:50
    • Location: Norway
    • Status: offline
    Re: PIC MCU with BMP280 temperature and pressure sensor 2020/02/20 10:47:13 (permalink)
    +1 (1)
    Are these two variables ?

    Yes.
     
    Go to a library or a bookstore and find a textbook on C programming.
    https://en.wikipedia.org/wiki/The_C_Programming_Language
    is a good alternative.
     
        Mysil
    post edited by Mysil - 2020/02/20 10:53:21
    #7
    abhi143
    Junior Member
    • Total Posts : 109
    • Reward points : 0
    • Joined: 2018/05/20 09:06:52
    • Location: 0
    • Status: offline
    Re: PIC MCU with BMP280 temperature and pressure sensor 2020/02/20 18:41:40 (permalink)
    0
    1and0
    abhi143
    Are these two variables ?

    Are you serious?

    Are these two variables that store  temperature and  pressure value in code ? or some other variable storing data.
    I can see only these two variables in the entire code. So I am thinking that these two variable declare to store data in codes
     

    while(TRUE)
    {
       BMP280_readTemperature(&temperature); // read temperature
       BMP280_readPressure(&pressure); // read pressure
    }

     
    I can see function pass the location of variable so we can get the value stored at this position. I think It would better if they use pointer to send value 
    post edited by abhi143 - 2020/02/20 18:43:05
    #8
    ric
    Super Member
    • Total Posts : 26090
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC MCU with BMP280 temperature and pressure sensor 2020/02/20 18:56:23 (permalink)
    0
    What do you think is the difference between "the location of variable", and "a pointer" ?
     

    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!
    #9
    abhi143
    Junior Member
    • Total Posts : 109
    • Reward points : 0
    • Joined: 2018/05/20 09:06:52
    • Location: 0
    • Status: offline
    Re: PIC MCU with BMP280 temperature and pressure sensor 2020/02/20 22:52:58 (permalink)
    0
    ric
    What do you think is the difference between "the location of variable", and "a pointer" ?
     

    Both are same, Pointer hold the address of variable. we can get the value store at that address by dereferencing pointer
     main ()
    {
      int a = 20;
      int * p = NULL;
       p = &a;    
    }

    Pointer point to location of variable a   
    #10
    ric
    Super Member
    • Total Posts : 26090
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC MCU with BMP280 temperature and pressure sensor 2020/02/20 22:58:35 (permalink)
    0
    So you agree they are the same thing.
    Why did you say:
    "I can see function pass the location of variable so we can get the value stored at this position. I think It would better if they use pointer to send value "

    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!
    #11
    abhi143
    Junior Member
    • Total Posts : 109
    • Reward points : 0
    • Joined: 2018/05/20 09:06:52
    • Location: 0
    • Status: offline
    Re: PIC MCU with BMP280 temperature and pressure sensor 2020/02/20 23:49:13 (permalink)
    0
    ric
    So you agree they are the same thing.
    Why did you say:
    "I can see function pass the location of variable so we can get the value stored at this position. I think It would better if they use pointer to send value "


    That was my misunderstanding
     

    #include<stdio.h>
    void fun ( int * p)
    {
    *p = 40;
    }

    int main ()
    {
    int a = 2;
    printf (" value of a = %d before calling to function \n", a);
    fun (&a);
    printf (" value of a = %d after calling to function \n", a) ;
    return 0;
    }

    value of a = 2 before calling to function
    value of a = 40 after calling to function
    Memory location will remain same only previous value will replace with new value 
     
    #12
    1and0
    Access is Denied
    • Total Posts : 10550
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: PIC MCU with BMP280 temperature and pressure sensor 2020/02/20 23:54:00 (permalink)
    #13
    abhi143
    Junior Member
    • Total Posts : 109
    • Reward points : 0
    • Joined: 2018/05/20 09:06:52
    • Location: 0
    • Status: offline
    Re: PIC MCU with BMP280 temperature and pressure sensor 2020/02/21 02:38:49 (permalink)
    0
    1and0
    Have a read of this:   https://www.tutorialspoint.com/cprogramming/c_function_call_by_reference.htm

    yes my example code #11 shows all about this 
    #14
    Jump to:
    © 2020 APG vNext Commercial Version 4.5