Input PAD
This sample uses the PAD input function to detect the GPIO input signal by interrupt.
It is necessary to configure the PAD to PAD_SW_MODE
mode and enable the wake up function. When the input signal changes, it will trigger the system handler interrupt, and the input level information will be printed in the interrupt handler.
Users can modify pin information through different macro configurations. For specific macro configurations, refer to Configurations.
Requirements
For hardware requirements, please refer to the Requirements.
Configurations
The following macros can be configured to modify PAD pin definitions.
#define GPIO_DEMO_INPUT_PIN0 P1_0 #define GPIO_DEMO_INPUT_PIN1 P1_1 #define GPIO_DEMO_INPUT_PIN2 P2_1 #define GPIO_DEMO_INPUT_PIN3 P2_2
The entry function is as follows, call this function in
main()
to run this sample code. For more details, please refer to the Initialization.pad_int_demo();
Building and Downloading
For building and downloading, please refer to the Building and Downloading.
Experimental Verification
Press the Reset button on the EVB and the message will be displayed in the Debug Analyzer.
pad_int_demo: pad interrupt demo start
When a low level input is detected on
P1_0
, the following message is printed in the Debug Analyzer.system_handler: pin0 interrupt triggered, pin_0_state 0
Code Overview
This section introduces the code and process description for initialization and corresponding function implementation in the sample.
Source Code Directory
The directory for project file and source code are as follows.
For project directory, please refer to Source Code Directory.
Source code directory:
sdk\sample\io_demo\gpio\interrupt\pad_int_demo.c
.
Initialization
The initialization flow for peripherals can refer to Initialization Flow.
Call
Pad_Config()
to initialize the PAD. The PAD initialization parameters are configured as shown in the table below.
PAD Hardware Parameters |
PAD |
---|---|
Pin Number |
|
PAD Mode |
|
PAD Power Mode |
|
PAD Pull Mode |
|
PAD Output Mode |
|
PAD Output Value |
PAD Hardware Parameters |
PAD |
---|---|
Pin Number |
|
PAD Mode |
|
PAD Power Mode |
|
PAD Pull Mode |
|
PAD Output Mode |
|
PAD Output Value |
PAD Hardware Parameters |
PAD |
---|---|
Pin Number |
|
PAD Mode |
|
PAD Power Mode |
|
PAD Pull Mode |
|
PAD Output Mode |
|
PAD Output Value |
PAD Hardware Parameters |
PAD |
---|---|
Pin Number |
|
PAD Mode |
|
PAD Power Mode |
|
PAD Pull Mode |
|
PAD Output Mode |
|
PAD Output Value |
Call
System_WakeUpPinEnable()
to enable wake up function.Call
System_WakeUpInterruptEnable()
to enable wake up interrupt.Configure NVIC, and refer to Interrupt Configuration for NVIC-related configurations.
Functional Implementation
When connecting P1_0 to GND, detecting the low level of P1_0 triggers the system handler.
The interrupt handler function system_handler
prints interrupt information.
if (System_WakeUpInterruptValue(GPIO_DEMO_INPUT_PIN0))
{
if (pin_0_state == 0)
{
pin_0_state = 1;
System_WakeUpPinEnable(GPIO_DEMO_INPUT_PIN0, PAD_WAKEUP_POL_LOW);
}
else
{
pin_0_state = 0;
System_WakeUpPinEnable(GPIO_DEMO_INPUT_PIN0, PAD_WAKEUP_POL_HIGH);
}
IO_PRINT_INFO1("system_handler: pin0 interrupt triggered, pin_0_state %d", pin_0_state);
}