Detect Single and Double Clicks Using LIS3DH Single-Click Interrupt
This example shows how to use the single-click interrupt of LIS3DH linear accelerometer connected to a TI's™ C2000-based hardware to sense the single and double clicks of the sensor.
To run this example, you can use any TI C2000 hardware. For your convenience, the following hardware is preconfigured to execute the example:
TI Delfino F28377S
Before you start this example, complete the Getting Started with Texas Instruments C2000 Microcontroller Blockset.
Supported TI C2000 hardware
Connect the INT1 pin of the LIS3DH sensor to pin 60 on the TI C2000 hardware.
Connect the SDA, SCL, 3.3V, and GND pin of the TI C2000 hardware to the respective pins on the LIS3DH sensor.
Hardware Configuration in the Model
c28x_i2c_lis3dh_clickdetection Simulink model.
The model is preconfigured to work with the TI Delfino F28377S hardware. If you are using a different C2000 hardware, change the hardware board by performing the following steps:
1. In the Simulink model, navigate to Modeling > Model Settings to open the Configuration Parameters dialog box.
3. Under the Hardware Implementation pane, under Hardware board list, select the TI C2000 board that you are using.
3. Click Apply and OK to close the dialog box.
Configure the Click Detection on LIS3DH for Interrupt Service Routine (ISR)
1. In the model, open the External Interrupt block, and specify the values for CPU interrupt numbers, PIE interrupt numbers, and Simulink task priorities, and Preemption flags. For more information on working with External Interrupts, see External Interrupt Workflow for Texas Instruments C2000 Processors.
Verify that the LIS3DH sensor block is placed in the Initialize Function subsystem.
2. Verify that the Enable click detection parameter is selected in the LIS3DH sensor block, and that the Type parameter is set to
Initiate Monitor and Tune Action for the Model
When you initiate the action to tune parameters and monitor signals, Simulink deploys the model as C code on the hardware. The code obtains real-time data from the hardware and tunes the parameters while the application is running on the hardware.
Note: Ensure that the TI C2000 hardware you are using has sufficient memory to run the application on hardware.
1. On the Hardware tab, in the Mode section, select Run on board (External Mode) and then click Monitor & Tune.
The lower-left corner of the model window displays status while Simulink prepares, downloads, and runs the Simulink model on the hardware. During simulation, the pin 60 on TI C2000 hardware generates an interrupt on every rising edge of the signal, which triggers the function-call subsystem.
2. Tap the sensor to verify the output in the display data area of the model. Simulink outputs 1 for single clicks and 2 for double clicks.