LPC54618 how to configure USART to receive uncertainty number of data without use ctimer?
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!
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.
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!
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.
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!
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.
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!
> ...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.