打印
[MCU]

tm4c123gxl使用串口,不连接串口设备(比如usb转串口)就不能用,为什么

[复制链接]
344|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
elephant00|  楼主 | 2020-12-2 10:41 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
配置使用tm4c123的几个串口,发现必须连上usb转串口,这个串口就能使,不连接,程序卡死。什么原因,下面贴上代码
//UART2
void ConfigureUART2(void)
{

     //
    // Enable the peripherals used by this example.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

                //
    // Enable processor interrupts.
    //
    ROM_IntMasterEnable();
        
                //PD7±»êÇËøסáËμÄ£¬ê1óøÃòy½ÅμÄÆäËû1|ÄüDèòa½«¸ÃIO¿ú½aËø£¬ÅäÖÃíê1|ÄüoóÔùÖØDÂËø¶¨
                //PF0ò2êÇèç′Ë£¬μ«PF0μÄè·¶¨ÖμÎa0x01
                HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY;        //½aËø
                HWREG(GPIO_PORTD_BASE + GPIO_O_CR) |= 0x80;//è·èÏ
                HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = 0;//ÖØDÂËø¶¨
        
    ROM_GPIOPinConfigure(GPIO_PD6_U2RX);
    ROM_GPIOPinConfigure(GPIO_PD7_U2TX);
    ROM_GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6 | GPIO_PIN_7);
               
               
                //
    // Configure the UART for 115,200, 8-N-1 operation.
    //
                ROM_UARTConfigSetExpClk(UART2_BASE, ROM_SysCtlClockGet(), 115200,
                            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_PAR_NONE));

                //
    // Enable the UART interrupt.
    //
    ROM_IntEnable(INT_UART2);
    ROM_UARTIntEnable(UART2_BASE, UART_INT_RX | UART_INT_RT);
        
}

//UART3
void ConfigureUART3(void)
{

     //
    // Enable the peripherals used by this example.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);

                //
    // Enable processor interrupts.
    //
    ROM_IntMasterEnable();
        
    //
    // Configure GPIO Pins for UART mode.
    //
    ROM_GPIOPinConfigure(GPIO_PC6_U3RX);
    ROM_GPIOPinConfigure(GPIO_PC7_U3TX);
    ROM_GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_6 | GPIO_PIN_7);
               
                //
    // Configure the UART for 115,200, 8-N-1 operation.
    //
                ROM_UARTConfigSetExpClk(UART3_BASE, ROM_SysCtlClockGet(), 115200,
                            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_PAR_NONE));

                //
    // Enable the UART interrupt.
    //
    ROM_IntEnable(INT_UART3);
    ROM_UARTIntEnable(UART3_BASE, UART_INT_RX | UART_INT_RT);
        
}
//UART4
void ConfigureUART4(void)
{

     //
    // Enable the peripherals used by this example.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART4);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);

                //
    // Enable processor interrupts.
    //
    ROM_IntMasterEnable();
        
    //
    // Configure GPIO Pins for UART mode.
    //
    ROM_GPIOPinConfigure(GPIO_PC4_U4RX);
    ROM_GPIOPinConfigure(GPIO_PC5_U4TX);
    ROM_GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5);
               
                //
    // Configure the UART for 115,200, 8-N-1 operation.
    //
                ROM_UARTConfigSetExpClk(UART4_BASE, ROM_SysCtlClockGet(), 115200,
                            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_PAR_NONE));

                //
    // Enable the UART interrupt.
    //
    ROM_IntEnable(INT_UART4);
    ROM_UARTIntEnable(UART4_BASE, UART_INT_RX | UART_INT_RT);
}

//UART5
void ConfigureUART5(void)
{

     //
    // Enable the peripherals used by this example.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART5);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

                //
    // Enable processor interrupts.
    //
    ROM_IntMasterEnable();
        
    //
    // Configure GPIO Pins for UART mode.
    //
    ROM_GPIOPinConfigure(GPIO_PE4_U5RX);
    ROM_GPIOPinConfigure(GPIO_PE5_U5TX);
    ROM_GPIOPinTypeUART(GPIO_PORTE_BASE, GPIO_PIN_4 | GPIO_PIN_5);
               
                //
    // Configure the UART for 115,200, 8-N-1 operation.
    //
                ROM_UARTConfigSetExpClk(UART5_BASE, ROM_SysCtlClockGet(), 115200,
                            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_PAR_NONE));

                //
    // Enable the UART interrupt.
    //
    ROM_IntEnable(INT_UART5);
    ROM_UARTIntEnable(UART5_BASE, UART_INT_RX | UART_INT_RT);
}

使用特权

评论回复

相关帖子

沙发
xyz549040622| | 2020-12-2 12:26 | 只看该作者
串口用过好多次,你这种情况肯定不会有,试试不用ROM的函数看看,还有,你中断函数是如何写的。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

914

主题

2368

帖子

4

粉丝