yefj
Advanced Member level 5
Hello,I am trying to understand the logic of this code for EFM32 USART.I have a putty on my PC where i can send a letter each minute or each hour.
How exactly this loop will work? in each iteration it expects some data to be recieved,what will happen if in a certain itteration no data will be recieved but on the next itteration it will get "G" for example?
Thanks.
How exactly this loop will work? in each iteration it expects some data to be recieved,what will happen if in a certain itteration no data will be recieved but on the next itteration it will get "G" for example?
Thanks.
Code:
while (1)
{
// Read a line from the UART
for (i = 0; i < BUFFER_SIZE - 1 ; i++ )
{
buffer[i] = USART_Rx(USART1);
if (buffer[i] == '\r')
{
break; // Breaking on CR prevents it from being counted in the number of bytes
}
}
// Echo the line back, adding CRLF
for (j = 0; j < i ; j ++ )
{
USART_Tx(USART1, buffer[j]);
}
USART_Tx(USART1, '\r');
USART_Tx(USART1, '\f');
}
}