for UART FreeRTOS Driver, How can I receive data with vary data length

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

for UART FreeRTOS Driver, How can I receive data with vary data length

932 Views
phantomgz
Contributor III

I'm using FRDM-K22F with KDSK2.1. for the UART FreeRTOS Driver there is only one method for receiving data, that is UART_RTOS_Receive(), it just can receiving data with exact data length. if I don't know how many data would be received. How can I do that?

 

Regards,

Cai.

Labels (1)
0 Kudos
2 Replies

496 Views
yuanhanchen
Contributor III

您好,这个问题我在K64的板子上是这样解决的:

思路1:

1.我先是把UART中的FIFO的接收设置为1,设置接收中断使能,这样在接收到数据后会产生中断信号,我在中断中用buffer数组接收数据。

2.开启一个任务,这个任务是用于检验是否总线空闲,如果是,则认为之前中断buffer接收到的数据为一个完整的数据(原理:K64自带的有一个总线空闲标志,如果有连续的数据一直在发送,则这个标志不会置位,在空闲时则会置位,读取后,要记得清理标志位。具体参见K64手册P1548,UARTx_S1中的IDLE)。

思路2:

使用片上PIT组件,设定一个定时时间,UART中断用于接收数据,在接收到第一个数据时,保存UART接收到的数据,同时UART中断内部开启PIT定时,如果在设定时间内接收到第二个数据,则在UART中断中重置定时时间,以避免PIT组件产生中断,而在PIT中断中设置接收完成标志位,开启一个任务,用于读取这个接受完成标志位和处理数据。

以上两种思路我都已经代码实例化并测试通过,你可以在K22上试试。祝好。

P.S:KSDK是越改越烂了。

496 Views
jorge_a_vazquez
NXP Employee
NXP Employee

Hi chaoxi cai

Unfortunately this is no possible, even if you aren't using a FreeRTOS drivers, you need to specify the number of data words that you going to receive before it can continue. You could define just 1, and this function will receive just 1 byte everytime you call it.


Hope this information helps you
Have a great day,
Jorge Alcala

0 Kudos