This section talks about external interrupts.
Reading the introduction and understanding the program is the best way.
External interrupts are the lowest priority interrupts of MSP430 and are maskable interrupts. They are relatively simple to use.
1.2.7 Simple port interrupts (external interrupts)
All ports of P1 and P2 have interrupt capabilities and can be configured through registers PxIFG, PxIE and PxIES. For other ports, please refer to the specific pin manual. All P1 interrupt flags are the highest priority (compared to external interrupts of other pins), and P1IFG.0 is the best.
PXIV interrupt vector register: only P1IV and P2IV. The highest priority enabled interrupt generates a sequence number in the P1IV register, which will be recognized or added to the program counter, and then automatically execute the appropriate interrupt service routine. Disabling the P1 port interrupt will not affect the value in the P1IV register. The P2 port has the same function. The PxIV register can only be accessed by word.
PxIFGx interrupt flag register: This register is valid only when the corresponding interrupt enable PXIE is turned on and the general interrupt GIE is turned on.
A low level indicates that there is no interrupt request waiting for response;
a high level indicates that there is an interrupt request waiting for response;
Note: During the use of the port's interrupt function, if PXIN, PXOUT and other operations are performed, the interrupt may change.
Note: The interrupt flag needs to be cleared by software. There is one exception: if two interrupts occur at the same time, respond to the interrupt with a higher priority first. When the interrupt service program ends, the interrupt flag of this bit will be automatically cleared, and then respond to another interrupt. The low level
of the PxIE interrupt enable register
indicates that the interrupt is turned off;
the high level indicates that the interrupt is allowed; The low level
of the PXIES interrupt trigger mode selection register
indicates a rising edge trigger;
the high level indicates a falling edge trigger;
External interrupt application example: /*Using the interrupt mode, switch S2 (connected to P2.2) controls the LEDs (connected to P1) to light up one by one (see the PCB diagram for wiring)*/
#include
int s=0; //s is used to indicate the number of key presses
int num =0; //num indicates the LED value
void main(void){
WDTCTL=WDTPW+WDTHOLD; //Turn off the watchdog
P1DIR=0xff; //P1 is all connected to output
P1OUT=0x00; //Connect the LEDs for initialization, so pull them all low, so the lights are off at the beginning
P2DIR=0x00; //P2 is all set to input Because it needs to accept external interrupts
P2IFG=0x00; //Clear the interrupt flag of port P2
P2IE=BIT2; //P2.2 turns on interrupt
P2IES=0xff; //P2 is triggered by a falling edge
P2IN=BIT2; //P2.2 input is pulled high, so when the switch is closed it will be pulled low to generate a falling edge (i.e. an interrupt)
P2OUT=0xff;
P2REN=0xff; //When used as an input, be sure to configure a pull-up resistor (very important, easy to forget, I made a mistake here -_')
__enable_interrupt(); //Turn on the total interrupt
while(1)
{
num=s%5;
switch(num){
case 0:P1OUT=BIT1; break; case 1:P1OUT=
BIT2;break;
case 2:P1OUT=BIT3;break;
case 3:P1OUT=BIT4;break;
case 4:P1OUT=BIT5;break;}}}
#pragma vector=PORT2_VECTOR //Fixed format, declare interrupt vector address__interrupt
void Port2_ISR(void) {//interrupt subroutineunsigned
int temp; //local variableint
i;
for(i=0;i<12000;i++); //delay debounceif
((P2IN&0xff)!=0xff){ //if a key is pressedtemp
=P2IFG; //read interrupt
flagP2IFG=0x00; //clear flagif
(temp==0x04) //if P2.2 generates interrupts
++;}} //This part actually has a few redundant sentences, mainly to reflect the knowledge of each port interrupt
RemarksInterrupt subroutine call format:
#pragma vector=interrupt vector address__interrupt
void interrupt service program name(void)
{
//interrupt handler
}
1.2.8 Unused I/OUnused
I/O pins are best set to normal I/O function, output direction and do not connect these pins on the PCB board to prevent floating input and reduce power consumption. Since these pins are not connected, their output values do not need to be considered. Alternatively, you can enable the high/low registers by setting the PxREN register of the unused pins to avoid interference from floating inputs.
Keywords:MSP430F5529
Reference address:MSP430F5529 (I) General I/O port settings-2
Reading the introduction and understanding the program is the best way.
External interrupts are the lowest priority interrupts of MSP430 and are maskable interrupts. They are relatively simple to use.
1.2.7 Simple port interrupts (external interrupts)
All ports of P1 and P2 have interrupt capabilities and can be configured through registers PxIFG, PxIE and PxIES. For other ports, please refer to the specific pin manual. All P1 interrupt flags are the highest priority (compared to external interrupts of other pins), and P1IFG.0 is the best.
PXIV interrupt vector register: only P1IV and P2IV. The highest priority enabled interrupt generates a sequence number in the P1IV register, which will be recognized or added to the program counter, and then automatically execute the appropriate interrupt service routine. Disabling the P1 port interrupt will not affect the value in the P1IV register. The P2 port has the same function. The PxIV register can only be accessed by word.
PxIFGx interrupt flag register: This register is valid only when the corresponding interrupt enable PXIE is turned on and the general interrupt GIE is turned on.
A low level indicates that there is no interrupt request waiting for response;
a high level indicates that there is an interrupt request waiting for response;
Note: During the use of the port's interrupt function, if PXIN, PXOUT and other operations are performed, the interrupt may change.
Note: The interrupt flag needs to be cleared by software. There is one exception: if two interrupts occur at the same time, respond to the interrupt with a higher priority first. When the interrupt service program ends, the interrupt flag of this bit will be automatically cleared, and then respond to another interrupt. The low level
of the PxIE interrupt enable register
indicates that the interrupt is turned off;
the high level indicates that the interrupt is allowed; The low level
of the PXIES interrupt trigger mode selection register
indicates a rising edge trigger;
the high level indicates a falling edge trigger;
External interrupt application example: /*Using the interrupt mode, switch S2 (connected to P2.2) controls the LEDs (connected to P1) to light up one by one (see the PCB diagram for wiring)*/
#include
int s=0; //s is used to indicate the number of key presses
int num =0; //num indicates the LED value
void main(void){
WDTCTL=WDTPW+WDTHOLD; //Turn off the watchdog
P1DIR=0xff; //P1 is all connected to output
P1OUT=0x00; //Connect the LEDs for initialization, so pull them all low, so the lights are off at the beginning
P2DIR=0x00; //P2 is all set to input Because it needs to accept external interrupts
P2IFG=0x00; //Clear the interrupt flag of port P2
P2IE=BIT2; //P2.2 turns on interrupt
P2IES=0xff; //P2 is triggered by a falling edge
P2IN=BIT2; //P2.2 input is pulled high, so when the switch is closed it will be pulled low to generate a falling edge (i.e. an interrupt)
P2OUT=0xff;
P2REN=0xff; //When used as an input, be sure to configure a pull-up resistor (very important, easy to forget, I made a mistake here -_')
__enable_interrupt(); //Turn on the total interrupt
while(1)
{
num=s%5;
switch(num){
case 0:P1OUT=BIT1; break; case 1:P1OUT=
BIT2;break;
case 2:P1OUT=BIT3;break;
case 3:P1OUT=BIT4;break;
case 4:P1OUT=BIT5;break;}}}
#pragma vector=PORT2_VECTOR //Fixed format, declare interrupt vector address__interrupt
void Port2_ISR(void) {//interrupt subroutineunsigned
int temp; //local variableint
i;
for(i=0;i<12000;i++); //delay debounceif
((P2IN&0xff)!=0xff){ //if a key is pressedtemp
=P2IFG; //read interrupt
flagP2IFG=0x00; //clear flagif
(temp==0x04) //if P2.2 generates interrupts
++;}} //This part actually has a few redundant sentences, mainly to reflect the knowledge of each port interrupt
RemarksInterrupt subroutine call format:
#pragma vector=interrupt vector address__interrupt
void interrupt service program name(void)
{
//interrupt handler
}
1.2.8 Unused I/OUnused
I/O pins are best set to normal I/O function, output direction and do not connect these pins on the PCB board to prevent floating input and reduce power consumption. Since these pins are not connected, their output values do not need to be considered. Alternatively, you can enable the high/low registers by setting the PxREN register of the unused pins to avoid interference from floating inputs.
Previous article:MSP430F5529 (II) Watchdog settings
Next article:MSP430F5529 (I) General I/O port settings-1
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
MoreDaily News
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
Guess you like
- Easily solve design challenges with MSP430 MCUs
- TI Logistics Robot CPU Board
- I would like to ask which one has better performance, thank you for your recommendation
- TI supports Bluetooth technology for high-precision body temperature measurement flexible PCB reference design
- Problems of charging and discharging dual capacitors in peak detectors
- EK140P Linux-4.1.15 Test Manual
- EEWORLD University Hall----Live Replay: HARTING- How to quickly and cost-effectively install cables in electrical control cabinets
- Introduction to Machine Vision Technology
- 【RT-Thread Reading Notes】1. RT-Thread RTOS Preface
- I would like to ask about an EXCEL curve fitting formula. I cannot get the value of Y by substituting the values of X (0, 150, 300). The value of Y is not correct.