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.

我的TimerB好像没有计时,求大神指导,用串口观察当前计时值一直是0



SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN| SYSCTL_XTAL_16MHZ);

SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_ONE_SHOT );

TimerLoadSet(TIMER0_BASE, TIMER_B, 0);

TimerEnable(TIMER0_BASE, TIMER_B);

while(1)
{
uint32_t VALUE=TimerValueGet(TIMER0_BASE, TIMER_B);
UARTprintf("TIME:%4u\n",VALUE);
}

  • 本来打算在中断中,使能TimerB的,但是发现没法启动计时,不知道怎么回事,求大神指导,还有获得当前计时值是用

    uint32_t VALUE=TimerValueGet(TIMER0_BASE, TIMER_B);吗?

  • 以下是完整程序

    #include<stdint.h>
    #include <stdbool.h>
    #include "driverlib/gpio.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/timer.h"
    #include "driverlib/uart.h"
    #include "driverlib/pin_map.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_ints.h"
    #include "inc/hw_gpio.h"
    #include "utils/uartstdio.h"

    uint32_t GPIOE_INT(void)
    {
    uint32_t value=0;
    unsigned long ulStatus;
    // 读取中断状态
    ulStatus = GPIOIntStatus(GPIO_PORTE_BASE, true);
    //进入中断指示灯亮
    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,GPIO_PIN_1);
    // 清除中断状态
    GPIOIntClear(GPIO_PORTE_BASE, ulStatus);
    if (ulStatus & GPIO_PIN_1)
    {
    TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_ONE_SHOT );
    TimerLoadSet(TIMER0_BASE, TIMER_B, 0);
    TimerEnable(TIMER0_BASE, TIMER_B);
    //SysCtlDelay(1000 * (SysCtlClockGet() / 3000));
    }
    if (ulStatus & GPIO_PIN_2)
    {
    TimerDisable(TIMER0_BASE, TIMER_B);
    value=TimerValueGet(TIMER0_BASE, TIMER_B);
    UARTprintf("LASTTIME:%4u\n",value);
    }
    return value;

    }
    void InitConsole(void)
    {
    // Enable GPIO port C which is used for UART1 pins.
    // TODO: change this to whichever GPIO port you are using.
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    // Configure the pin muxing for UART1 functions on port C4 and C5.
    // This step is not necessary if your part does not support pin muxing.
    // TODO: change this to select the port/pin you are using.
    GPIOPinConfigure(GPIO_PC4_U1RX);
    GPIOPinConfigure(GPIO_PC5_U1TX);
    // Enable UART1 so that we can configure the clock.
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
    // Use the internal 16MHz oscillator as the UART clock source.
    UARTClockSourceSet(UART1_BASE, UART_CLOCK_PIOSC);
    // Select the alternate (UART) function for these pins.
    // TODO: change this to select the port/pin you are using.
    GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5);
    // Initialize the UART for console I/O.
    UARTStdioConfig(1, 115200, 16000000);
    }

    /*
    * main.c
    */
    void main(void) {
    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN| SYSCTL_XTAL_16MHZ);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);

    GPIODirModeSet(GPIO_PORTE_BASE, GPIO_PIN_1|GPIO_PIN_2 , GPIO_DIR_MODE_IN);//声音接收中断PE1,PE2

    GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_1|GPIO_PIN_2, GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_STD_WPU);//上拉输入

    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_1);//中断指示,进入中断灯亮

    GPIOIntTypeSet(GPIO_PORTE_BASE, GPIO_PIN_1|GPIO_PIN_2, GPIO_LOW_LEVEL);//低电平产生中断

    GPIOIntEnable(GPIO_PORTE_BASE, GPIO_PIN_1|GPIO_PIN_2);

    InitConsole(); //初始化串口1

    TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_ONE_SHOT );

    TimerLoadSet(TIMER0_BASE, TIMER_B, 0);

    IntEnable(INT_GPIOE_TM4C123);

    IntMasterEnable();

    GPIOIntClear(GPIO_PORTE_BASE, GPIO_PIN_1|GPIO_PIN_2);

    while(1)
    {
    GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_1,0);
    uint32_t VALUE=TimerValueGet(TIMER0_BASE, TIMER_B);
    UARTprintf("TIME:%4u\n",VALUE);
    }

    }

  • TimerLoadSet(TIMER0_BASE, TIMER_B, 0);

    我把这句注释掉了,程序就可以计数了,有大神指导是为什么吗?