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 1接收问题

Guru**** 2390755 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/1106786/tm4c129xnczad-interrupt-driven-uart-1-reception-problem

器件型号:TM4C129XNCZAD

大家好、我在 tm4c129xnczad 微控制器中为 atlease 4 UART 在 interupt 驱动的 UART 接收中工作、我已经实现了 UART 0的 interupt 接收 UART、就像我尝试 uart1的接收一样 、在那里我无法获取通过终端发送的字符、 我使用的 IDE 是 Code Composer、我在下面附上了我的代码。有关这一点的任何想法、请告诉我。

//********************************UART0_INITIALISATION  ************************//
void Uart0_Init(void)
{

	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);

}


//********************************UART1_INITIALISATION  ************************//
void Uart1_Init(void)
{

	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

	MAP_GPIOPinConfigure(GPIO_PB0_U1RX);
	MAP_GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0);


	MAP_GPIOPinConfigure(GPIO_PB1_U1TX);
	MAP_GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_1);

	MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);

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

	MAP_IntEnable(INT_UART1);
	//MAP_UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT);

}

//*****************************************************************************
//
// The UART interrupt handler.
//
//*****************************************************************************
void UART0IntHandler(void)
{
    uint32_t ui32Status;

   // MAP_UARTCharPutNonBlocking(UART0_BASE, input);
   // 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);

    //MAP_UARTCharPutNonBlocking(UART0_BASE,UARTCharGetNonBlocking(UART0_BASE));
    input = UARTCharGetNonBlocking(UART0_BASE);
    //
    // 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));
    }*/
}


void UART1IntHandler(void)
{
    uint32_t ui32Status;

   // MAP_UARTCharPutNonBlocking(UART0_BASE, input);
   // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_PIN_4);
    //
    // Get the interrrupt status.
    //
    ui32Status = MAP_UARTIntStatus(UART1_BASE, true);

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

    //MAP_UARTCharPutNonBlocking(UART0_BASE,UARTCharGetNonBlocking(UART0_BASE));
    input_1 = UARTCharGetNonBlocking(UART1_BASE);
    //
    // 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));
    }*/
}






int main(void)
{
    volatile uint32_t ui32Loop;



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



    Uart0_Init();
    Uart1_Init();
    MAP_UARTCharPutNonBlocking(UART0_BASE, 'a');
    MAP_UARTCharPutNonBlocking(UART1_BASE, 'b');


    //
    // 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(UART1_BASE, 'b');
    	if(input != 0)
    	{
    		MAP_UARTCharPutNonBlocking(UART0_BASE, input);
    		input = 0;
    	}
    	if(input_1 != 0)
		{
			MAP_UARTCharPutNonBlocking(UART1_BASE, input_1);
			input_1 = 0;
		}
    	/*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);
        delayMs(200);
        //
        // 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;
}



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

    您好!

     原因是在您的 Uart1_Init()中,您注释掉该行以启用 RX 中断。 见第46行。 取消注释并重试。 另外,请确保 在 startup_ccs.c 文件的矢量表中有 UART1IntHandler()的中断矢量。  

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

    是的、当我启用它时、我尝试启用它、即使我的 uart0正在工作、但它不工作、并且当我启用它时、uart1也不工作、所以我进行了注释。 当仅注释此行时、uart1 TX 工作正常、而 uart0 TX 和 Rx 工作正常、这就是我注释该行的原因。

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

    首先、为了生成 RX 中断、必须启用中断。 必须先取消注释行、然后调试发生的情况。 您能不能展示 UART1TX 和 UART1RX 引脚的示波器电容。 在 UART1IntHandler 上放置断点。  

    [引用 userid="514814" URL"~/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1106786/tm4c129xnczad-interrupt-drived-uart-1-recite-proby-probion/4101639#4101639"]当此行正常且引用 uartrx 1时,该行也是正常的原因时,并且引用 uartrx 1。]

    如果 uart1tx 正常、则如果以环回方式测试、则还必须检查 uart1tx 和 uart1rx 引脚是否连接在一起。

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

    感谢您的支持、我启用了注释行"MAP_UARTIntEnable (UART1_BASE、UART_INT_RX | UART_INT_RT)"、它对我很有效、我认为由于硬件问题、它以前不起作用。 现在按预期工作、我将尝试 UART 2和 uart3、并将在该论坛中进行更新。