注册 登录
电子工程世界-论坛 返回首页 EEWORLD首页 频道 EE大学堂 下载中心 Datasheet 专题
ooakk的个人空间 https://home.eeworld.com.cn/space-uid-329861.html [收藏] [复制] [分享] [RSS]
日志

TI LM3S同时使用两个以上串口的方法

已有 792 次阅读2012-7-18 20:21

TI LM3S同时使用两个以上的串口正确的方法
自己编写函数:
//*****************************************************************************
//
//! Changes UART printf output port.
//!
//! \param ulPortNum is the number of UART port to use for the serial console
//! (0-2)
//!
//! \return None.
//
//*****************************************************************************
void
UARTPrintfPortChange(unsigned long ulPortNum)
{
    //
    // Select the base address of the UART.
    //
    g_ulBase = g_ulUARTBase[ulPortNum];
}
把该函数放在需要修改的地方即可。

下面简单说明原理

g_ulBase为全局变量,用于选择UART。
TI固有函数
void UARTStdioInitExpClk(unsigned long ulPortNum, unsigned long ulBaud)
初始化串口时,有定义g_ulBase
    //
    // Select the base address of the UART.
    //
    g_ulBase = g_ulUARTBase[ulPortNum];
初始化之后,所有有关串口操作的函数都要根据g_ulBase来选定串口。
因此,修改g_ulBase即可修改串口。
其他不可取的方法有:初始化一个串口,使用后除能,然后再初始化另一个串口。这样效率低下,速度也打不到应用需求,也容易出现初始化错误。

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

热门文章