LPC54618 how to configure USART to receive uncertainty number of data?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

LPC54618 how to configure USART to receive uncertainty number of data?

1,762 次查看
Xiaoyh
Contributor III

    LPC54618 how to configure USART to receive uncertainty number of data without use                ctimer? 

0 项奖励
回复
9 回复数

1,738 次查看
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello yang1,

Yes, you can use UART interrupt to receive as frank said.

 

 

0 项奖励
回复

1,719 次查看
Xiaoyh
Contributor III

Thank you for your reply !  When I receive a frank data, MCU Whether there is an interrupt flag to detect that a frame has been received?

                                                                                                                                 Thank you!

0 项奖励
回复

1,754 次查看
frank_m
Senior Contributor III

What would one need a timer for when receiving asynchronous serial data ? I don't know what you mean.

Just use the receive interrupt of the USART. See section 25.6.4 of the MCU user manual.

UART/USART is inherently unsafe, so you would need a protocol with a message start or end character, or both. Else you run the risk of losing synchronisation.

0 项奖励
回复

1,748 次查看
Xiaoyh
Contributor III

Thank you for your reply!As you said,the MCU usart just to receive certainty number of data?when uncertainty number of Serial datas coming,how can I know how many datas had received?

                                                                                                                     thank you!

 

0 项奖励
回复

1,746 次查看
frank_m
Senior Contributor III

You get an interrupt for every byte/character you receive.

> how can I know how many datas had received?

You don't, unless you count the characters received.

 

0 项奖励
回复

1,720 次查看
Xiaoyh
Contributor III

   Thank you for your reply! I want to receive to a frank data and go to usart IRQ to detect reveive  complete flag and then use DMA  move the received data to a self-defined buff fifo!

                                                                                                                                        THANK YOU!

0 项奖励
回复

1,717 次查看
frank_m
Senior Contributor III

No, it does not work that way. Either UART interrupt or DMA.

For reception per DMA, one connects a DMA channel to UART reception, and configures a specific number of characters to transfer. Finally you configure a DMA "finished" interrupt that notifies you whenever the specified amount of data had been received.

This approach does not work well with messages of unknown size, nor does it deal well with missed / corrupted characters.

I always used the UART RXNE interrupt for reception, and handled the buffer in the interrupt routine.

0 项奖励
回复

1,712 次查看
Xiaoyh
Contributor III

Thank you for your reply ! Does you receive data for a character once in your  usart receive irq,and how can you know a frame data received complete? I can't use the way to receive data becase I use many usarts to received data and they  will occupancy  cpu  resources  !

                                                                                                                   thank you!                                                                      

0 项奖励
回复

1,706 次查看
frank_m
Senior Contributor III

> ...and how can you know a frame data received complete?

Only you can know that. This is part of the protocol you run.

A text-based protocol often uses '\r', '\n', or both to terminate a sequence, like NMEA183. Binary protocols like Modbus RTU use pause times, and have no such character.

> I can't use the way to receive data becase I use many usarts to received data and they  will occupancy  cpu  resources  !

You will have to use your CPU time for something.

At moderate baudrates and proper design, the time spent in handlers will not have much consequence.

OTOH, with fixed-size DMA reception, you will have an uncertain delay between actual transmission and reaction in your application. It is only delivered to your main loop when a multiple of your DMA size is received, which usually happens at the next transmission.

I am not totally sure about the LPC UART peripheral, but UARTs in other Cortex M stop reception if an error occurs (overflow, noise, parity, etc). You would need to clear this error condition manually to re-enable reception. In my experience, this does not mix well with DMA or any blockwise reception method.

0 项奖励
回复