First of all, the general IO port. No matter what microcontroller you learn, the IO port is the most important and easiest to learn. It is important because it is the interface between the microcontroller and the peripheral device, and it is also what we usually call the human-machine interface. It is easy to learn because it is easy to control. It is nothing more than enabling the port, setting the direction, and then writing or reading data (depending on the direction you set). The IO port of this super powerful 32-bit ARM core is also different. After all, it is an ARM core, and the IO registers are also richer. Let's take a look at the functions related to the IO port.
1. In order, enable the IO port first. Only when it is enabled can it be used, so of course it is the first step.
SysCtlPeripheralEnable (SYSCTL_PERIPH_GPIOA)
This is the function to enable port A, that is, port A can be used, and its door is open to you.
Doesn't port A have 6 pins in physical characteristics? GPIOA represents those 6 pins.
So how many other general IO ports does M3 have? Just count them and you will know. If you want to use it, you must understand it well. PA 0-5 PB 0-7 PC 0-7 PD 0-7 PE 0-2 ========== Is there a pattern? It seems a bit messy. Look at it this way. 51 is like this, P0, P1, P2, P3 //
Here are PA, PB, PC, PD. What about PE, where does it come from? Because our PA only has 6 pins, so it gives its two pins to others (PE1, 2). Like 51, both have 32 pins.
Remember this, PA has six pins and PE has two pins. The two PE pins can also be used as motors (because its second function is pwm4, pwm5).
Needless to say, the other pins are 8 for power and ground, reset, two for crystal oscillator, and LD0 for voltage regulator. This is a total of 44 pins, and the remaining four pins are AD interfaces AD0-AD3. Just now, the port was enabled, and the port became active and can be used, but the function word is too long and I can't remember it. What should I do? Just make a macro definition, make one that I know.
#define DEVICEEN SysCtlPeripheralEnable
enables the device, and that's it.
What is the second step? What do you want to do? The most common thing is, are you going to connect a button (input) or an LED (output)?
Yes, it is to set the direction, there are three directions.
void GPIOPinTypeGPIOInpu (unsigned long ulPort, unsigned char ucPins)
void GPIOPinTypeGPIOOutput (unsigned long ulPort, unsigned char ucPins)
ulPort is which port, ucPins is which pin or pins
The function name is too long, so it is better to make a macro definition that you are familiar with
#define GPIOIN GPIOPinTypeGPIOInpu
#define GPIOOUT GPIOPinTypeGPIOOutput
Now let's take an example: set the 0th pin of PA as output and the second pin as input.
GPIOOUT (GPIO_PORTA_BASE, GPIO_PIN_0)
GPIOIN (GPIO_PORTA_BASE, GPIO_PIN_2)
Of course, I still think that GPIO_PORTA_BASE, GPIO_PIN_2 are too long.
After all, they are things that we need to deal with frequently. I will make a macro definition:
#define PA GPIO_PORTA_BASE
#define PIN2 GPIO_PIN_2
Then the above statement becomes, GPIOIN (PA, PIN2);
which feels a lot clearer (Note: you must remember the macros you defined)
In the third step, the direction is also set, so all that’s left is reading and writing numbers.
void GPIOPinWrite(unsigned long ulPort, unsigned char ucPins, unsigned char ucVal);
long GPIOPinRead(unsigned long ulPort, unsigned char ucPins)
Then macro definition:
#define WRITE GPIOPinWrite
#define READ GPIOPinRead
Now you can turn on the light. If your PA0 is connected to an LED (cathode is grounded),
you only need this statement to light it up: WRITE(PA,PIN0,1);
Previous article:Solutions based on embedded multimedia entertainment controller
Next article:USB design based on STM32
Recommended ReadingLatest update time:2024-11-17 01:32
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- Bluetooth Low Energy Issues
- TI's TPS92610-Q1 is a single-channel LED driver
- Good video material sharing on UWB in detail
- Please tell me how to use low power resistors when connecting LEDs in series and parallel
- Award-winning live broadcast | Interpretation of TI's latest low-cost C2000 features, quickly get started with precision power supply and motor control!
- Comparison summary of MSP430 FR2xx series MCU BSL and MSP432 P series MCU BSL
- A port to type C port problem
- Build a Prank HID Device with Pico and CircuitPython
- Simulink and UDS on Can
- How to optimize FPGA design area