This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD) ;
GPIODirModeSet(GPIO_PORTD_BASE,GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|
GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7,GPIO_DIR_MODE_IN);
GPIOPadConfigSet(GPIO_PORTD_BASE,GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|
GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD);
HWREG(ui32Port + GPIO_O_DIR) = ((ui32PinIO & 1) ?
(HWREG(ui32Port + GPIO_O_DIR) | ui8Pins) :
(HWREG(ui32Port + GPIO_O_DIR) & ~(ui8Pins)));//就是这句
楼主要把所有的PD脚都配置为输入吧。PD7比较特殊需要解锁,其他脚都按照正常处理就ok。
试一下这个代码:
#include "driverlib/gpio.h"
#include "inc/hw_gpio.h"
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
SysCtlDelay(5);
HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;
HWREG(GPIO_PORTD_BASE + GPIO_O_CR) = 0xFF;
GPIOPinTypeGPIOInputt(GPIO_PORTD_BASE,GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3| GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);
楼主用的哪颗芯片?
说的PD7需要解锁是针对TM4C123x。PD7、PF0和NMI功能复用的,还有JTAG功能脚都有锁,只有执行解锁才能切换GPIO的功能。
129x需要解锁的就是别的脚了。总之还是JTAG和NMI复用的脚。
上Datasheet,来自TM4C1294NCPDT:
The GPIO commit control registers provide a layer of protection against accidental programming of
critical hardware peripherals. Protection is provided for the GPIO pins that can be used as the four
JTAG/SWD pins and the NMI pin (see “Signal Tables” on page 1781 for pin numbers). Writes to
protected bits of the GPIO Alternate Function Select (GPIOAFSEL) register (see page 770), GPIO
Pull Up Select (GPIOPUR) register (see page 776), GPIO Pull-Down Select (GPIOPDR) register
(see page 778), and GPIO Digital Enable (GPIODEN) register (see page 781) are not committed to
storage unless the GPIO Lock (GPIOLOCK) register (see page 783) has been unlocked and the
appropriate bits of the GPIO Commit (GPIOCR) register (see page 784) have been set.
需要解锁的脚包括JTAG的4个信号所在的脚,以及NMI功能所在的2个脚。
详细说明和步骤,参考Datasheet中,GPIO章节:Commit Control的描述。