Basic I2C Example
Communicate with a peripheral using the I2C API.
- SDK directory:
apps/basic/i2c
- Zentri App Store:
ZENTRI-BAI2C
API Features Demonstrated
Platforms
This app works on:
- AMW004 - Zentri Mackerel evaluation board. See Connecting a Zentri AMW004 to a Zentri ASG001 Backpack.
- AMW106 - Zentri Moray evaluation board
Requirements and Prerequisites
This app requires a ZentriOS device, such as an AMW106 Moray evaluation board, connected to an ST LIS3DH three axes linear accelerometer, such as supplied with the ASG001 Zentri Backpack.
Description
The app uses the I2C API to read from and write to the registers of the accelerometer sensor.
Usage Instructions
This app requires no interaction.
On building, downloading and running, it displays:
> I2C Example starting...
Reading 'Who Am I' register
Response valid: 0x33
Writing CTRL_REG 1-4 (0x20 - 0x23)
Reading CTRL_REG 1-4 (0x20 - 0x23)
Verifying registers
Success, read back data valid
After displaying the above results the app exits and the device reboots.
Implementation
zn_app_init
- zn_i2c_master_read_reg8 reads the value of the LIS3DH "Who Am I" register
- The app validates the result against the expected response and logs success or failure.
- zn_i2c_master_write_reg writes 4 values to successive LIS3DH registers with a single call using the auto-increment feature.
- zn_i2c_master_read_reg reads back the values from successive LIS3DH registers with a single call using the auto-increment feature.
- The app validates the values read back against the values written and logs success or failure.
Source
See: