User manual

Table Of Contents
Zynq-7000 AP SoC Technical Reference Manual www.xilinx.com 387
UG585 (v1.11) September 27, 2016
Chapter 14: General Purpose I/O (GPIO)
Example: Configure MIO pin 10 as an input
1.
Set the direction as input: Write 0x0 to the gpio.DIRM_0 register. T
his sets gpio.DIRM_0[10]
= 0.
14.3.3
Writing Data to
GPIO
Output Pins
For GPIO pins configured as outputs, there are two options to program the desired value.
Option 1: Read, modify, and update the GPIO pin using the gpio.DATA_0 register.
Example: Set GPIO output pin 10 using the DATA_0 register.
1. Read the gpio.DATA_0 register: Read gpio.DATA_0 register to the reg_val variable.
2. Modify the value: Set reg_val [10] =1.
3. Write updated value to output pin: Write reg_val to the gpio.DATA_0 register.
Option 2: Use the MASK_DATA_x_MSW/LSW registers to update one or more GPIO pins.
Example: Set output pins 20, 25, and 30 to 1 using the MASK_DATA_0_MSW register.
1. Generate the mask value for pins 20, 25, and 30: To drive pins 20, 25 and 30, 0xBDEF is the
mask value for gpio.MASK_DATA_0_MSW [MASK_0_MSW].
2. Generate the data value for pins 20, 25, 30: To drive 1 on pins 20, 25, and 30, 0x4210 is the
data value for gpio.MASK_DATA_0_MSW [DATA_0_MSW].
3. Write the mask and data to the MASK_DATA_x_MSW register: Write 0xBDEF_4210 to the
gpio.MASK_DATA_0_MSW register.
14.3.4
Reading Data from GPIO Input Pins
For GPIO pins configured as inputs, there are two options to monitor the input.
Option 1: Use the gpio.DATA_RO_x register of each bank.
Example: Read the state of all GPIO input pins in bank 0 using the DATA_RO_0 register.
1. Read Input Bank 0: Read the gpio.DATA_0 register.
Option 2: Use interrupt logic on input pins (refer to section 14.2.4 Interrupt Function).
Example: Configure MIO pin 12 to be triggered as rising edge.
1. Set the trigger as a rising edge: Write 1 to gpio.INT_TYPE_0 [12]. Write 1 to
gpio.INT_POLARITY_0 [12]. Write 0 to gpio.INT_ANY_0 [12].
2.
Enable interrupt: Write 1 to gpio.INT_EN_0 [12].
3.
Status of Input pin: gpio.INT_STAT_0 [12] =1 implies that an interrupt event occurred.
4.
Disable interrupt: Write 1 to gpio.INT_DIS_0 [12].