I am just trying to toggle on Board LED and listen to incoming Data from the terminal window at the same time, but the whole Loop function hangs when it reachs the fgets()
, until I send something the the terminal window then it continues to loop. There must be something like "if Serial available , then start to read ?? Here is my Code, I'm new in Atmel studio
#include <asf.h>
#include <string.h>
char incomingData [256];
// /**
// * \brief Configure UART for debug message output.
// */
static void configure_console(void)
{
const usart_serial_options_t uart_serial_options = {
.baudrate = CONF_UART_BAUDRATE,
#ifdef CONF_UART_CHAR_LENGTH
.charlength = CONF_UART_CHAR_LENGTH,
#endif
.paritytype = CONF_UART_PARITY,
#ifdef CONF_UART_STOP_BITS
.stopbits = CONF_UART_STOP_BITS,
#endif
};
// /* Configure console UART. */
sysclk_enable_peripheral_clock(CONSOLE_UART_ID);
stdio_serial_init(CONF_UART, &uart_serial_options);
}
int main (void)
{
/* Insert system clock initialization code here (sysclk_init()). */
board_init();
sysclk_init();
configure_console();
/* Insert application code here, after the board has been initialized. */
gpio_set_pin_low(LED0_GPIO);
while (1)
{
printf("Hello\r\n");
gpio_toggle_pin(LED0_GPIO);
fgets(incomingData,sizeof(incomingData),stdin);
printf("%s\r\n",incomingData);
}
}