TI论坛
直播中

朱志兴

7年用户 298经验值
私信 关注
[问答]

TM4C123GH6PZ在使用UARTCharGet函数循环接收时第一次没有阻塞

ti的工程师们 请教下
UARTCharGet函数循环接收时第一次没有阻塞,

回帖(9)

冯敬宇

2018-8-17 07:13:59
//*****************************************************************************
//
//! Waits for a character from the specified port.
//!
//! param ui32Base is the base address of the UART port.
//!
//! This function gets a character from the receive FIFO for the specified
//! port. If there are no characters available, this function waits until a
//! character is received before returning.
//!
//! return Returns the character read from the specified port, cast as a
//! e int32_t.
//
//*****************************************************************************
int32_t
UARTCharGet(uint32_t ui32Base)
[
//
// Check the arguments.
//
ASSERT(_UARTBaseValid(ui32Base));
//
// Wait until a char is available.
//
while(HWREG(ui32Base + UART_O_FR) & UART_FR_RXFE)
[
]
//
// Now get the char.
//
return(HWREG(ui32Base + UART_O_DR));
]
注意标注红色部分,其可能没有获取字符,停留在此等待。
举报

韦明

2018-8-17 07:20:33
在规定的时间内,没有收到数据,就会阻塞,这属于你程序的问题。建议你用接收中断,判断接收到字符,然后发送出去。或者循环判断接收到字符后才发送。
举报

朱志兴

2018-8-17 07:28:33
引用: ljmlvmd 发表于 2018-8-17 07:20
在规定的时间内,没有收到数据,就会阻塞,这属于你程序的问题。建议你用接收中断,判断接收到字符,然后发送出去。或者循环判断接收到字符后才发送。

用了接收中断 但是每次上电只能进一次中断,后面发数据就进不去了
举报

朱志兴

2018-8-17 07:39:06
引用: guigui_7044 发表于 2018-8-17 07:13
//*****************************************************************************
//
//! Waits for a character from the specified port.

直接用串口可以了 ,后来改成用485和中断接收的模式 每次上点只能进一次中断
用了接收中断 但是每次上电只能进一次中断,后面发数据就进不去了
举报

更多回帖

发帖
×
20
完善资料,
赚取积分