element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Azure Sphere Starter Kit
  • Products
  • Dev Tools
  • Avnet Boards Community
  • Azure Sphere Starter Kit
  • More
  • Cancel
Azure Sphere Starter Kit
Forum How to access barometer readings?
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Azure Sphere Starter Kit to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 5 replies
  • Answers 3 answers
  • Subscribers 48 subscribers
  • Views 818 views
  • Users 0 members are here
  • azurespherech
  • azure sphere
  • i2c bus
  • azuresphkt
  • azure sphere starter kit
  • registers
Related

How to access barometer readings?

mysliwiec_tech
mysliwiec_tech over 6 years ago

I'm a novice in C and in embedded programming. Let's say I started with Azure Sphere as there was an occasion to enter to this field in a cheap way. As a training I have successfully accessed the readings from gyro and accelerometer, but having issues with accessing pressure readings. I understand that between the barometer and ARM there is the accelerometer (which functions like some "proxy" as I understand). Can someone explain to me how to access the:

  • WHO_AM_I register of the barometer, - if I get this, I think I will easily get to point bellow
  • readings of air pressure.

Reading the source code of an example is difficult to me (probably not yet adjusted to my level yet). I'm looking for someone to point me to what registers in sequence I have to write, in order to get value of WHO_AM_I, with the explanation why it is done that way.

So far I have that:

static const uint8_t lsm6dsoAddress = 0x6A;
static const uint8_t lps22hh = 0x5C;


static const uint8_t regId = 0x01;
static const uint16_t hub[] = { regId, 0x40 }; //setting SHUB_REG_ACCESS flag
uint8_t val;

static const uint8_t masterConfigRegId = 0x14;
static const uint16_t masterOn[] = { masterConfigRegId, 0x04 }; //setting MASTER_ON flag

static const uint16_t slv0Addr[] = { 0x15, 0xB9 }; //read address of barometer
static const uint16_t slv0WhoAmIRegId[] = { 0x16, 0x0F }; //who_am_i register of barometer
uint8_t actualWhoAmI;

int i2cFd = I2CMaster_Open(2);
if (i2cFd < 0) {
Log_Debug("ERROR: I2CMaster_Open: errno=%d (%s)\n", errno, strerror(errno));
return -1;
}

I2CMaster_Write(i2cFd, lsm6dsoAddress, &hub, 8); //enabling the access to the hub registers

I2CMaster_Write(i2cFd, lsm6dsoAddress, &masterOn, 16); //thought I need to enable that, so I can access the barometer

I2CMaster_Write(i2cFd, lsm6dsoAddress, &slv0Addr, 16); //setting that so the next write will go to barometer directky
I2CMaster_WriteThenRead(i2cFd, lsm6dsoAddress, &slv0WhoAmIRegId, 16, &actualWhoAmI, 8); //getting the value of who_am_i register - unfortunately the program returns 0x00 here
Log_Debug("0x%02x", actualWhoAmI);
return 0;

Please forgive me the lack of error catching (doing that for simplification). Just want to understand the approach to my problem. I'm really eager to start learning by doing + learn how to read technical documentation, but I think so far I lack some crucial points.

  • Sign in to reply
  • Cancel

Top Replies

  • mfetting
    mfetting over 6 years ago +1 suggested
    I found the following information related to the barameter sensor. The LPS22HH device (from ST MicroElectronics) provides digital pressure output. Measurements are accessed via the LSM6DSO interface to…
  • mysliwiec_tech
    mysliwiec_tech over 6 years ago in reply to mfetting +1
    Thanks for your answer :-) I know there is a code, but following it seems problematic to person that starts his journey with embedded programming like me. Wanted something in digested format I also wanted…
  • clem57
    clem57 over 6 years ago +1 suggested
    mysliwiec_tech wrote: I'm a novice in C and in embedded programming. Let's say I started with Azure Sphere as there was an occasion to enter to this field in a cheap way. As a training I have successfully…
Parents
  • mfetting
    0 mfetting over 6 years ago

    I found the following information related to the barameter sensor.

     

    The LPS22HH device (from ST MicroElectronics) provides digital pressure output. Measurements are accessed via the LSM6DSO interface to the I2C bus.

    The LSM6DSO acts as a sensor hub and is the I2C master on the secondary I2C bus to which the LPS22HH pressure sensor device is attached.

     

    I would suggest looking at the code found in the AvnetStarterKitReferenceDesign  project. 

     

    Starting with lps22hh_reg.h and lps22hh_reg.c

    You will find the initialization and retrieval of data from the sensor in i2c.c

     

     

     

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Reply
  • mfetting
    0 mfetting over 6 years ago

    I found the following information related to the barameter sensor.

     

    The LPS22HH device (from ST MicroElectronics) provides digital pressure output. Measurements are accessed via the LSM6DSO interface to the I2C bus.

    The LSM6DSO acts as a sensor hub and is the I2C master on the secondary I2C bus to which the LPS22HH pressure sensor device is attached.

     

    I would suggest looking at the code found in the AvnetStarterKitReferenceDesign  project. 

     

    Starting with lps22hh_reg.h and lps22hh_reg.c

    You will find the initialization and retrieval of data from the sensor in i2c.c

     

     

     

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
Children
  • mysliwiec_tech
    0 mysliwiec_tech over 6 years ago in reply to mfetting

    Thanks for your answer :-)

    I know there is a code, but following it seems problematic to person that starts his journey with embedded programming like me. Wanted something in digested format image I also wanted to understand on high level what is the reasoning of writing to the proper registers (why to those and why in this order). If there is no other way then I can try to follow the code, but comments doesn't seem to be explaining why some registers were being written. In that case I think I just need to keep going and ask what each register means.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • mfetting
    0 mfetting over 6 years ago in reply to mysliwiec_tech

    I understand, we share the same interest to continue learning.  I spent time last night working through the OLED, and face similar questions.  I have found it helpful to start with a working solution and then begin moving in the direction I want it to go.  I want to learn about the OLED but the example wants to teaching me about IOT_CENTRAL_APPLICATION.  First I will make the solution work, then I will dissect it to learn what I want to learn.

     

    My approach would be to start with disassembling AvnetStarterKitReferenceDesign by removing the features you do not need. By removing the other sensors and leaving only the Barometer.  That way you start from a position of a working solution and move towards learning why something is there.   The who_am_i is a verification of the sensor/bus so that the program knows it is communicating with something it understands.  It is a static variable defined in the .h file

     

    /** Device Identification (Who am I) **/

    #define LPS22HH_ID                              0xB3U

     

    I'm learning about the Azure Sphere as I go as well, but have many years of coding behind me.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube