Gpio
Gpio, short for general purpose I/O. Its pins can be used for programming. Embedded systems often have a large number of external devices, but the structure is relatively simple. to control these devices, sometimes only one control signal is needed, that is, you only need to turn on/off the two states, such as light and off. Traditional serial port and parallel port are not suitable for controlling these devices. Therefore, a general programmable I/O interface (gpio) is generally provided on the microcontroller chip.
S3c gpio
S3C2440 has 130 gpio ports and is divided into 9 groups from A to J: GPa, GPB, GPC... gpj. By setting the registers, you can select whether a gpio port is used for input, output, or other special functions. For example, you can set gph6.
Operate gpio
Gpio (GPA ~ Gpj), can be controlled and accessed through three registers, these three registers are:
1. gpxcon: gpio configuration register.
2. gpxdat: gpio data register.
3. gpxup: the pull-up resistor control register.
(X: A, B... H, J)
Gpxcon register
From the register name, we can see that it belongs to the confugure register-the function of selecting the gpio port. Among them, Porta and portb ~ Portj has different function options. Each bit in gpacon corresponds to one IO port (23 in total ). When a value is 0, the corresponding Io is the output; When a value is set to 1, the corresponding PIN is the address line or used for address control. Portb ~ Portj is identical in terms of register operations. Every two pins in gpxcon are controlled: 00 indicates input, 01 indicates output, 10 indicates special functions, and 11 indicates reserved.
Gpxdat register
Gpxdat registers are used for read/write pins: When the PIN is set to input, read this register to see whether the battery status of the corresponding PIN is high or low; when the PIN is set to output, write the corresponding bit of this register to make this pin output high or low.
Gpxup register
Gpxup: When a pin is set to 1, the corresponding PIN has no internal pull-up resistance. When the value is set to 0, the corresponding PIN uses the internal pull-up resistance. (Pull-up resistance: Because the PIN is relatively flushed by external electromagnetic interference, a resistor is used to connect the pin to a high level so that it is fixed to a high level, such resistance is called a pull-up resistance .)
-
Additional reading:
-
- 1
The gpio is initialized in the file gpio_drv.c. You can use the tool provided by MTK to configure it or use code to directly operate in the program. The two options should be determined by whether the macro _ cust_new __
- 2
Pay attention to configuring codegen during tool initialization. DWS: This file only configures the initialization of the gpio port. Not all gpio ports need to be set to the working mode, especially the gpiio port used as the clock and Bluetooth part, if it is set to work mode during initialization, the current of the motor will be too large.
- 3
During code initialization, drv_writereg () and drv_reg operate on the gpio port registers, respectively defining the mode and direction of the gpio port (0: input; 1: output ), the following functions are used to operate a single gpio port (taking gpio25 as an example ):
- 4
Gpio_modesetup (25, 0); Set gpio25 to Mode 0
- 5
Gpio_initio (); initialize gpio25 to output
- 6
Gpio_writeio (0, 25); set the value of gpio25 input low level 0