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.

[参考译文] TM4C129XNCZAD:中断驱动的 UART 接收问题

Guru**** 2391705 points
Other Parts Discussed in Thread: TM4C129XNCZAD

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1105669/tm4c129xnczad-interrupt-driven-uart-reception-problem

器件型号:TM4C129XNCZAD

大家好,我在 tm4c129xnczad 微控制器中处理中断驱动 UART 接收,我在 code composer studio 中工作,问题是我没有收到 UART 接收,ISR 处理程序也没有触发,我在下面附上了我的代码

任何 tho

//*****************************************************************************
//
// The UART interrupt handler.
//
//*****************************************************************************
void
UARTIntHandler(void)
{
    uint32_t ui32Status;
    GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_PIN_4);
    //
    // Get the interrrupt status.
    //
    ui32Status = MAP_UARTIntStatus(UART0_BASE, true);

    //
    // Clear the asserted interrupts.
    //
    MAP_UARTIntClear(UART0_BASE, ui32Status);

    //
    // Loop while there are characters in the receive FIFO.
    //
    while(MAP_UARTCharsAvail(UART0_BASE))
    {
        //
        // Read the next character from the UART and write it back to the UART.
        //
        MAP_UARTCharPutNonBlocking(UART0_BASE,
                                   UARTCharGetNonBlocking(UART0_BASE));
    }
}
//*****************************************************************************
//
// Send a string to the UART.
//
//*****************************************************************************
void
UARTSend(const uint8_t *pui8Buffer, uint32_t ui32Count)
{
    //
    // Loop while there are more characters to send.
    //
    while(ui32Count--)
    {
        //
        // Write the next character to the UART.
        //
        MAP_UARTCharPutNonBlocking(UART0_BASE, *pui8Buffer++);
    }
}


void delayMs(uint32_t ui32Ms) {

	// 1 clock cycle = 1 / SysCtlClockGet() second
	// 1 SysCtlDelay = 3 clock cycle = 3 / SysCtlClockGet() second
	// 1 second = SysCtlClockGet() / 3
	// 0.001 second = 1 ms = SysCtlClockGet() / 3 / 1000

	SysCtlDelay(ui32Ms * (120000000 / 3 / 1000));
}

void delayUs(uint32_t ui32Us)
{
	SysCtlDelay(ui32Us * (120000000 / 3 / 1000000));
}
int main(void)
{
    volatile uint32_t ui32Loop;
    uint32_t ui32SysClock;


    ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                               SYSCTL_OSC_MAIN |
                                               SYSCTL_USE_PLL |
                                               SYSCTL_CFG_VCO_240), 120000000);

        MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

        MAP_GPIOPinConfigure(GPIO_PA0_U0RX);
    	MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0);


    	MAP_GPIOPinConfigure(GPIO_PA1_U0TX);
    	MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_1);

    	 MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

        MAP_UARTConfigSetExpClk(UART0_BASE, ui32SysClock, 115200,
                                (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                                 UART_CONFIG_PAR_NONE));

        MAP_IntEnable(INT_UART0);
        MAP_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

        MAP_UARTCharPutNonBlocking(UART0_BASE, 'a');


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


    //
    // Check if the peripheral access is enabled.
    //
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPION))
    {
    }

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);



    //
    // Check if the peripheral access is enabled.
    //
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOF))
    {
    }
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOE))
    {
    }

    //
    // Enable the GPIO pin for the LED (PN0).  Set the direction as output, and
    // enable the GPIO pin for digital function.
    //
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_4);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3);
    GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_5);
    GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_6);
    /*PORTF_DIR |= 0x0000003E;    //set PF1, PF2, PF3 as output
    PORTF_DEN |= 0x0000003E;    //enable PF1, PF2, PF3
    PORTF_DATA = 0;*/

    //
    // Loop forever.
    //
    while(1)
    {
        //
        // Turn on the LED.
        //
    	//MAP_UARTCharPutNonBlocking(UART0_BASE, 'a');
    	/*if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_5))
    	{
    		GPIO_PORTF_AHB_DATA_R |= (GPIO_PIN_4);
    	}
    	else
    	{
    		GPIO_PORTF_AHB_DATA_R &= ~(GPIO_PIN_4);
    	}*/
       /* GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_PIN_4);
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_PIN_3);
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_5, GPIO_PIN_5);
        GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_6, GPIO_PIN_6);*/


        //
        // Delay for a bit.
        //
       /* for(ui32Loop = 0; ui32Loop < 2000000; ui32Loop++)
        {
        }*/
    	// PORTF_DATA |= (GPIO_PIN_4 | PF2 | PF3);
       // SysCtlDelay(5000000);
        delayUs(100);
        //
        // Turn off the LED.
        //
      //  GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_4, 0x0);
        /*GPIO_PORTF_AHB_DATA_R &= ~((GPIO_PIN_4));
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3, 0x0);
        GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_6, 0x0);
        //PORTF_DATA &= ~(GPIO_PIN_4 | PF2 | PF3 );*/
        delayUs(100);
       // SysCtlDelay(5000000);
        //
        // Delay for a bit.
        //
       /* for(ui32Loop = 0; ui32Loop < 2000000; ui32Loop++)
        {
        }*/
    }

	return 0;
}
请与我分享

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!

     我认为您的代码基于 TivaWare 中的 UART_ECHO、对吧? 我有一些建议。

     -请确保 UART_echo 按 预期工作。

     -我在 代码中看不到 MAP_IntMasterEnable()。 请添加它以启用处理器级中断、除非您已在其他地方启用它。  

     -您需要在矢量表中插入一个名为 UARTIntHandler 的中断矢量。 请参阅下面的 startup_ccs.c 文件。

     -如何连接 UARTRX 和 UARTTX? 如果您要向 UARTTX 写入内容并希望从 UARTRX 接收内容、请确保电路板上已连接 PA0和 PA1引脚。  

     -从 MAP_UARTCharPutNonBlocking (UART0_BASE、'A')更改为 MAP_UARTCharPut (UART0_BASE、'A');

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    "我认为您的代码基于 TivaWare 中的 UART_ECHO、对吧? "  

    是的、我使用 UART 回显代码作为基础。

    " 您需要在矢量表中插入一个名为 UARTIntHandler 的中断矢量。 请参阅下面的 startup_ccs.c 文件。"

    非常感谢您解决了我的问题。 我必须在 startup_ccs.c 文件中映射 UARTIntHandler。

    " 我在 代码中看不到 MAP_IntMasterEnable()。"

    如果不添加此项,则在我们添加上述 Map_IntMasterEnable()时代码也可以正常工作。

    谢谢

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    [引用 userid="514814" URL"~/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1105669/tm4c129xnczad-interrupt-drived-uart-recitive-probion/4097813#4097813"]我们在不添加上述代码时也应添加此函数/内部链接(integle)。]

    根据之前 在 TM4C1294NCPDT:RTOS:BIOS 不工作的调查、 在处理器复位后、PRIMASK 已经为零、这意味着中断已经全局启用并且 不需要 IntMasterEnable()调用。

    引用的线程中的问题是使用引导加载程序时,引导加载程序在传输到应用程序时将全局禁用中断,并且应用程序没有 IntMasterEnable()调用。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    感谢 Chester Gillon 提供的宝贵意见。