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.