How to receive packets on the MCU's serial port?
- by itisravi
Hello,
Consider this code running on my microcontroller unit(MCU):
while(1){
do_stuff;
if(packet_from_PC)
send_data_via_gpio(new_packet); //send via general purpose i/o pins
else
send_data_via_gpio(default_packet);
do_other_stuff;
}
The MCU is also interfaced to a PC via a UART.Whenever the PC sends data to the MCU, the *new_packet* is sent,
otherwise the *default_packet* is sent.Each packet can be 5 or more bytes with a pre defined packet structure.
My question is:
1.Should i receive the entire packet from PC using inside the UART interrut service routine (ISR)? In this case, i have to implement
a state machine inside the ISR to assemble the packet (which can be lengthy with if-else or switch-case blocks).
2.Detect a REQUEST command (one byte)from the PC in my ISR set a flag, diable UART interrupt alone and form the packet in my while(1) loop by polling the UART?