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 822 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

    I2CMaster_WriteThenRead fucntion documentation:

     

    https://docs.microsoft.com/en-us/azure-sphere/reference/applibs-reference/applibs-i2c/function-i2cmaster-writethenread

     

    azure-sphere-sample code from main.c (https://github.com/Azure/azure-sphere-samples/blob/master/Samples/I2C/I2C_LSM6DS3_HighLevelApp/I2C_LSM6DS3_HighLevelApp/… )

     

     

    // Demonstrates three ways of reading data from the attached device.
    // This also works as a smoke test to ensure the Azure Sphere can talk to the I2C device.
    static int ReadWhoAmI(void)
    {
        // DocID026899 Rev 10, S9.11, WHO_AM_I (0Fh); has fixed value 0x69.
        static const uint8_t whoAmIRegId = 0x0F;
        static const uint8_t expectedWhoAmI = 0x69;
        uint8_t actualWhoAmI;
    
    
        // Read register value using AppLibs combination read and write API.
        ssize_t transferredBytes =
            I2CMaster_WriteThenRead(i2cFd, lsm6ds3Address, &whoAmIRegId, sizeof(whoAmIRegId),
                                    &actualWhoAmI, sizeof(actualWhoAmI));
        if (!CheckTransferSize("I2CMaster_WriteThenRead (WHO_AM_I)",
                               sizeof(whoAmIRegId) + sizeof(actualWhoAmI), transferredBytes)) {
            return -1;
        }
        Log_Debug("INFO: WHO_AM_I=0x%02x (I2CMaster_WriteThenRead)\n", actualWhoAmI);
        if (actualWhoAmI != expectedWhoAmI) {
            Log_Debug("ERROR: Unexpected WHO_AM_I value.\n");
            return -1;
        }
    
    
        // Read register value using AppLibs separate read and write APIs.
        transferredBytes = I2CMaster_Write(i2cFd, lsm6ds3Address, &whoAmIRegId, sizeof(whoAmIRegId));
        if (!CheckTransferSize("I2CMaster_Write (WHO_AM_I)", sizeof(whoAmIRegId), transferredBytes)) {
            return -1;
        }
        transferredBytes = I2CMaster_Read(i2cFd, lsm6ds3Address, &actualWhoAmI, sizeof(actualWhoAmI));
        if (!CheckTransferSize("I2CMaster_Read (WHO_AM_I)", sizeof(actualWhoAmI), transferredBytes)) {
            return -1;
        }
        Log_Debug("INFO: WHO_AM_I=0x%02x (I2CMaster_Write + I2CMaster_Read)\n", actualWhoAmI);
        if (actualWhoAmI != expectedWhoAmI) {
            Log_Debug("ERROR: Unexpected WHO_AM_I value.\n");
            return -1;
        }
    
    
        // Read register value using POSIX APIs.
        // This uses the I2C target address which was set earlier with
        // I2CMaster_SetDefaultTargetAddress.
        transferredBytes = write(i2cFd, &whoAmIRegId, sizeof(whoAmIRegId));
        if (!CheckTransferSize("write (WHO_AM_I)", sizeof(whoAmIRegId), transferredBytes)) {
            return -1;
        }
        transferredBytes = read(i2cFd, &actualWhoAmI, sizeof(actualWhoAmI));
        if (!CheckTransferSize("read (WHO_AM_I)", sizeof(actualWhoAmI), transferredBytes)) {
            return -1;
        }
        Log_Debug("INFO: WHO_AM_I=0x%02x (POSIX read + write)\n", actualWhoAmI);
        if (actualWhoAmI != expectedWhoAmI) {
            Log_Debug("ERROR: Unexpected WHO_AM_I value.\n");
            return -1;
        }
    
    
        return 0;
    }

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

    I2CMaster_WriteThenRead fucntion documentation:

     

    https://docs.microsoft.com/en-us/azure-sphere/reference/applibs-reference/applibs-i2c/function-i2cmaster-writethenread

     

    azure-sphere-sample code from main.c (https://github.com/Azure/azure-sphere-samples/blob/master/Samples/I2C/I2C_LSM6DS3_HighLevelApp/I2C_LSM6DS3_HighLevelApp/… )

     

     

    // Demonstrates three ways of reading data from the attached device.
    // This also works as a smoke test to ensure the Azure Sphere can talk to the I2C device.
    static int ReadWhoAmI(void)
    {
        // DocID026899 Rev 10, S9.11, WHO_AM_I (0Fh); has fixed value 0x69.
        static const uint8_t whoAmIRegId = 0x0F;
        static const uint8_t expectedWhoAmI = 0x69;
        uint8_t actualWhoAmI;
    
    
        // Read register value using AppLibs combination read and write API.
        ssize_t transferredBytes =
            I2CMaster_WriteThenRead(i2cFd, lsm6ds3Address, &whoAmIRegId, sizeof(whoAmIRegId),
                                    &actualWhoAmI, sizeof(actualWhoAmI));
        if (!CheckTransferSize("I2CMaster_WriteThenRead (WHO_AM_I)",
                               sizeof(whoAmIRegId) + sizeof(actualWhoAmI), transferredBytes)) {
            return -1;
        }
        Log_Debug("INFO: WHO_AM_I=0x%02x (I2CMaster_WriteThenRead)\n", actualWhoAmI);
        if (actualWhoAmI != expectedWhoAmI) {
            Log_Debug("ERROR: Unexpected WHO_AM_I value.\n");
            return -1;
        }
    
    
        // Read register value using AppLibs separate read and write APIs.
        transferredBytes = I2CMaster_Write(i2cFd, lsm6ds3Address, &whoAmIRegId, sizeof(whoAmIRegId));
        if (!CheckTransferSize("I2CMaster_Write (WHO_AM_I)", sizeof(whoAmIRegId), transferredBytes)) {
            return -1;
        }
        transferredBytes = I2CMaster_Read(i2cFd, lsm6ds3Address, &actualWhoAmI, sizeof(actualWhoAmI));
        if (!CheckTransferSize("I2CMaster_Read (WHO_AM_I)", sizeof(actualWhoAmI), transferredBytes)) {
            return -1;
        }
        Log_Debug("INFO: WHO_AM_I=0x%02x (I2CMaster_Write + I2CMaster_Read)\n", actualWhoAmI);
        if (actualWhoAmI != expectedWhoAmI) {
            Log_Debug("ERROR: Unexpected WHO_AM_I value.\n");
            return -1;
        }
    
    
        // Read register value using POSIX APIs.
        // This uses the I2C target address which was set earlier with
        // I2CMaster_SetDefaultTargetAddress.
        transferredBytes = write(i2cFd, &whoAmIRegId, sizeof(whoAmIRegId));
        if (!CheckTransferSize("write (WHO_AM_I)", sizeof(whoAmIRegId), transferredBytes)) {
            return -1;
        }
        transferredBytes = read(i2cFd, &actualWhoAmI, sizeof(actualWhoAmI));
        if (!CheckTransferSize("read (WHO_AM_I)", sizeof(actualWhoAmI), transferredBytes)) {
            return -1;
        }
        Log_Debug("INFO: WHO_AM_I=0x%02x (POSIX read + write)\n", actualWhoAmI);
        if (actualWhoAmI != expectedWhoAmI) {
            Log_Debug("ERROR: Unexpected WHO_AM_I value.\n");
            return -1;
        }
    
    
        return 0;
    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
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