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.

關於tm4c123g開發板設定PF0為輸出的問題

您好,

我使用tm4c123g開發板,使用ccs內建的一個範例程式"hello.c"

下面是我寫的一小段程式

int
main(void)
{
//volatile uint32_t ui32Loop;

//
// Enable lazy stacking for interrupt handlers. This allows floating-point
// instructions to be used within interrupt handlers, but at the expense of
// extra stack usage.
//
ROM_FPULazyStackingEnable();

//
// Set the clocking to run directly from the crystal.
//
ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
SYSCTL_OSC_MAIN);

//
// Enable the GPIO port that is used for the on-board LED.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0);
//
// Enable the GPIO pins for the LED (PF2 & PF3).
//
ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);

//
// Initialize the UART.
//
ConfigureUART();

//
// Hello!
//
UARTprintf("Hello, world!\n");

GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_PIN_0);

//
// We are finished. Hang around doing nothing.
//
while(1)
{
//
// Turn on the BLUE LED.
//
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);

//
// Delay for a bit.
//
SysCtlDelay(SysCtlClockGet() / 10 / 3);

//
// Turn off the BLUE LED.
//
GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);

//
// Delay for a bit.
//
SysCtlDelay(SysCtlClockGet() / 10 / 3);
}
}

我設定GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_PIN_0);

但在PF0的輸出,不管我設定是HIGH或是LOW,都沒有任何變化.

而且輸出的電壓都是2伏特左有變化

請問我是哪裡設定錯了???

  • TM4C123x的PF0和PD7脚有锁,在解锁后方可以指定管脚功能。详细信息请参考GPIO部分的GPIOLOCK和GPIOCR寄存器及相关描述。
    如果需要调整PF0的功能,需要在使能PF脚后执行如下操作:

    HWREG(BUTTONS_GPIO_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;//解锁

    HWREG(BUTTONS_GPIO_BASE + GPIO_O_CR) |= 0x01;// (GPIOCR 寄存器的内容只有在 GPIOLOCK 寄存器解锁时才能被修改)确认相应的位如果是PD7解锁应该写入0x80

    HWREG(BUTTONS_GPIO_BASE + GPIO_O_LOCK) = 0;//重新锁定

    要包含的头文件

    #include "inc/hw_types.h"

    #include "inc/hw_gpio.h"

  • 感謝您熱心的回覆。

    祝福您一切順心。