Azure Sphere – SPI
This sample demonstrates how to use SPI with Azure Sphere in a high-level application.
The sample displays data from an ST LSM6DS3 accelerometer connected to an MT3620 development board through the Serial Peripheral Interface (SPI). The accelerometer data is retrieved every second and is displayed by calling the Applibs SPI APIs.
The sample uses the following Azure Sphere libraries.
|eventloop||Invokes handlers for timer events.|
|log||Displays messages in the Device Output window during debugging.|
|spi||Manages the Serial Peripheral Interfaces (SPIs).|
||Application manifest file, which describes the resources.|
||CMake configuration file, which Contains the project information and is required for all builds.|
||JSON file for configuring Visual Studio to use CMake with the correct command-line options.|
||JSON file that tells Visual Studio how to deploy and debug the application.|
||The license for this sample application.|
||Main C source code file.|
||This README file.|
||Folder containing the JSON files that configure Visual Studio Code for building, debugging, and deploying the application.|
||Folder containing the hardware definition files for various Azure Sphere boards.|
This sample requires the following hardware:
- An Azure Sphere MT3620 board
- ST LSM6DS3 inertial measurement unit (IMU)
- A breadboard (recommended because this sample requires wiring from multiple sources to the same pin)
- Jumper wires to connect the boards
Set up your Azure Sphere device and development environment as described in the Azure Sphere documentation.
Even if you've performed this set up previously, ensure you have Azure Sphere SDK version 21.04 or above. At the command prompt, run azsphere show-version to check. Upgrade the Azure Sphere SDK for Windows or Linux as needed.
Connect your Azure Sphere device to your computer by USB.
Enable application development, if you have not already done so, by entering the following line at the command prompt:
azsphere device enable-development
Set up the ST LSM6DS3 connections
Make the following connections between the ST LSM6DS3 and MT3620 dev boards. Make sure that power is disconnected while you wire the boards.
Note: By default, this sample is configured to use an external ST LSM6DS3 and isn't configured to use the onboard sensors found on some development boards, such as the ST LSM6DS0 on the Avnet Starter Kit. This sample uses ISU1 on the MT3620 board; however, you can use another ISU by adjusting the wiring, the code, and the application manifest.
Build and run the sample
To build and run this sample, follow the instructions in Build a sample application.
Test the sample
When you run the application, it reads the WHO_AM_I register from the accelerometer. This should return the known value 0x69, which confirms that the MT3620 can successfully communicate with the accelerometer. If this fails, verify that the devices are wired correctly, and that the application opened the correct SPI interface. For details on the registers, see the ST LSM6DS3 data sheet.
After displaying the initial values, the application configures the accelerometer and then displays the vertical acceleration every second.
To test the accelerometer data:
Keep the device still, and observe the accelerometer output in the Device Output window. Once the data from the CTRL3_C register is displayed, the output should repeat every second.
Turn the accelerometer upside down and observe the updated data in the Device Output window. The vertical acceleration should change from approximately +1g to approximately -1g.