Professional Documents
Culture Documents
1. Interrupt:
- For doing the Handler after interrupt, we should define the Handler in startup_rvmdk.S.
- When into the Handler, we should clear the interrupt by using
GPIO_PORTX_ICR_R
Writing a bit 1 in this register clear the corresponding interrupt edge detection logic register.
Writing a bit 0 has no effect.- Sau thc thi on code mnh mong mun.
- Example:
void
INTGPIOF(void)
{
// Clear the interrupt at F.1
GPIO_PORTF_ICR |= 0x02;
.
}
II. GPIO:
- When we want to use any PORT or GPIO, we need to give clock to that PORT by using:
SYSCTL_RCGC2_R |=
- Here are the software definitions for PORT:
+ SYSCTL_RCGC2_GPIOA
0x00000001
+ SYSCTL_RCGC2_GPIOG
0x00000040
+ SYSCTL_RCGC2_GPIOF
0x00000020
+ SYSCTL_RCGC2_GPIOE
0x00000010
+ SYSCTL_RCGC2_GPIOD
0x00000008
+ SYSCTL_RCGC2_GPIOC
0x00000004
+ SYSCTL_RCGC2_GPIOB
0x00000002
- Example:
int
main(void)
{
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF;
}
- Then we must set the Digital Enable Register- GPIODEN. By default, with the exception of
the GPIO signals is used for JTAG/SWD function, all other GPIO signals are configured to be
undriven. Their digital function is disabled which mean that they do not drive a logic value on
the pin and they do not alow the pin voltage into the GPIO reciever. To use the pin in digital
function we must use:
GPIO_PORTX_DEN_R =
- Example:
int
main(void)
{
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF;
GPIO_PORTF_DEN_R |= ((1<<0)|(1<<1));
}
- After that we must set the Data Direction Registers GPIODIR, bit set to 1 in the
GPIODIR register configure the corresponding pin to be output, while bits set to 0 configure the
pin to be inbut. By default, all GPIO pins are input.
GPIO_PORTX_DIR_R
- Example:
int
main(void)
{
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF;
GPIO_PORTF_DEN_R |= ((1<<0)|(1<<1));
GPIO_PORTF_DIR_R &= ~(1<<1);
GPIO_PORTF_DIR_R |= (0x1);
}
- Then, if we want to use the Switch, we must configure the Pull-up Register GPIOPUR and
8-mA or 4-mA or 2-mA Drive Control Register GPIODR8R GPIODR4R GPIODR2R
for the corresponding pin of Switch.
GPIO_PORTX_DR8R_R
GPIO_PORTX_PUR_R
- Example:
int
main(void)
{
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF;
GPIO_PORTF_DEN_R |= ((1<<0)|(1<<1));
GPIO_PORTF_DIR_R &= ~(1<<1);
GPIO_PORTF_DIR_R |= (0x1);
GPIO_PORTF_PUR_R |= (1<<1);
GPIO_PORTF_DR8R_R |= (1<<1);
}