3577 views|0 replies

6555

Posts

0

Resources
The OP
 

What is GPIO? [Copy link]

1. What is GPIO? GPIO, in English, is called General-Purpose IO ports. Embedded systems often have a large number of external devices/circuits with relatively simple structures. Some of these devices/circuits require the CPU to provide control means for them, while others need to be used as input signals by the CPU. Moreover, many of these devices/circuits only require one bit, that is, only two states of on/off are enough, such as the light on and off. It is not appropriate to use traditional serial ports or parallel ports to control these devices/circuits. Therefore, a "general programmable IO interface", namely GPIO, is generally provided on microcontroller chips. The interface has at least two registers, namely the "general IO control register" and the "general IO data register". Each bit of the data register is directly connected to the outside of the chip, and the function of each bit in this register, that is, the signal flow direction of each bit, can be independently set through the corresponding bit in the control register. In this way, the presence or absence of a GPIO interface becomes a feature that distinguishes a microcontroller from a microprocessor. In actual MCU, GPIO has many forms. For example, some data registers can be addressed by bit, while some cannot be addressed by bit, which needs to be distinguished during programming. For example, the traditional 8051 series is divided into two registers: bit-addressable and non-bit-addressable. In addition, for the convenience of use, many MCUs integrate glue logic into the chip to enhance the stability of the system. For example, in addition to the two standard registers that must be provided, the GPIO interface also provides a pull-up register, which can set the output mode of the IO to high impedance, level output with pull-up, or level output without pull-up. In circuit design, the peripheral circuit can be simplified a lot. In addition, it should be noted that for different computer architectures, the device may be port-mapped or memory-mapped. If the system structure supports independent IO address space and is port-mapped, assembly language must be used to complete the actual control of the device, because the C language does not provide a real "port" concept. If it is memory-mapped, it will be much more convenient. For example, if register A (address is assumed to be 0x48000000) writes data 0x01, then it can be set like this. #define A (*(volatile unsigned long *)0x48000000) ... A = 0x01; ... This is actually the convenience of the memory mapping mechanism. The volatile keyword is an important feature of embedded system development. The above expression is analyzed separately. First, (volatile unsigned long *)0x48000000 means to force 0x48000000 to be converted into a pointer of type volatile unsigned long, temporarily recorded as p, then it is #define A *p, that is, A is the content of the location pointed to by P pointer. Here, register A is accessed through memory addressing, and read/write operations can be performed. 2. Features of S3C2410 GPIO The s3c2410 GPIO has 117 pins. Next we should go to 9 IO ports to see the details. The S3C2410X has 117 multi-functional input/output port pins. The ports are: — Port A (GPA): 23-output port — Port B (GPB): 11-input/output port — Port C (GPC): 16-input/output port [size= 4]— Port D (GPD): 16-input/output port — Port E (GPE): 16-input/output port — Port F (GPF): 8-input/output port — Port G (GPG): 16-input/output port — Port H (GPH): 11-input/ output port There are so many IO ports, many of which are actually composite functions. They can be used as ordinary IO ports or as special peripheral interfaces. When designing a program, you should plan the overall resources. When initializing, you should arrange all resources reasonably. This will avoid problems. The registers of the current 8 ports are similar. In addition to the two general registers GPxCON and GPxDAT, GPxUP is also provided to determine whether to use the internal pull-up resistor (where x is AH, and it should be noted that there is no GPAUP). The main steps of the application are: · Set the GPIO control register GPxCON · Set the GPIO pull-up register GPxUP After initialization, you can implement the corresponding application by operating GPxDAT. Among them, PORT A and PORT BH are different in function selection. Each bit of GPACON corresponds to a pin (a total of 23 pins are valid). When a bit is set to 0, the corresponding pin is an output pin. At this time, writing 0/1 to GPADAT can make the pin output low/high level; when a bit is set to 1, the corresponding pin is an address line, or used for address control, and GPADAT is useless at this time. Generally speaking, GPACON is usually set to all 1s to access external storage devices. PORT BH is exactly the same in terms of register operation. Every two bits in GPxCON control a pin: 00 means input, 01 means output, 10 means special function, and 11 is reserved. GPxDAT is used to read/write pins: when the pin is set to input, reading this register can tell whether the corresponding pin state is high/low; when the pin is set to output, writing the corresponding bit of this register can make the corresponding pin output low or high level. GPxUP: When a bit is set to 0, the corresponding pin has no internal pull-up; when it is 1, the corresponding pin uses internal pull-up. As for special functions, they have to be set in combination with special peripherals.

This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list