Minimal UART Logger Over GPIO

Serial logging is a powerful tool in embedded systems. When limited by hardware, this note describes how to implement a minimal UART logger using only one TX GPIO pin and a USB-to-Serial adapter.

Hardware Requirements

Basic UART Output on ATmega (AVR)

Configure UART in software if no hardware USART is available:

void uart_init(void) {
  UBRRH = 0;
  UBRRL = 51; // 9600 baud at 8 MHz
  UCSRB = (1 << TXEN);
  UCSRC = (1 << URSEL) | (3 << UCSZ0);
}

void uart_putc(char c) {
  while (!(UCSRA & (1 << UDRE)));
  UDR = c;
}

void uart_puts(const char* s) {
  while (*s) uart_putc(*s++);
}
  

Testing the Output

  1. Connect TX pin of the MCU to RX of the USB-TTL adapter.
  2. Open a terminal on your PC:
    screen /dev/ttyUSB0 9600
  3. Watch for logs in real-time.

Applications

← Back to Notes