Skip to content

brgman/avr-uart-debug

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AVR Pin Debugging Utility

This utility provides functions to print pin states and debug AVR microcontrollers in a Linux terminal via UART. It allows developers to inspect register values and individual pin statuses easily.

Map of pins

Functions

1. print_binary(const char* register_name, uint8_t value)

Prints the binary representation of an 8-bit AVR register or pin value to the terminal.

  • Parameters:
    • register_name: A string (e.g., "PINB") to label the output for clarity.
    • value: The 8-bit value (e.g., PINB) to be displayed in binary format.
  • Output: Prints the register name followed by its binary value (e.g., PINB: 10110011).
  • Example:
    print_binary("PINB", PINB);
    Output in terminal:
    PINB: 10110011
    

2. printf(const char* format, ...)

Standard C-style formatted output function, redirected to UART for terminal display.

  • Parameters:
    • format: A format string (e.g., "PD2 status: %d\n") specifying the output format.
    • ...: Additional arguments (e.g., pin_value) to be formatted.
  • Output: Prints formatted text to the terminal via UART.
  • Example:
    printf("PD2 status: %d\n", pin_value);
    Output in terminal:
    PD2 status: 1
    

Setup Instructions

To use this utility, initialize UART and redirect the standard output to the UART interface:

  1. Include the UART utility: Include the uart.c file, which contains the UART initialization and output functions.

    #include "uart.c"
  2. Initialize UART: Call uart_init() to configure the UART module with the appropriate baud rate and settings.

    uart_init();
  3. Redirect stdout to UART: Set the standard output stream (stdout) to the UART output stream (uart_output) to send all printf outputs to the terminal.

    stdout = &uart_output;

Example Code

#include <avr/io.h>
#include "uart.c"

int main(void) {
    // Initialize UART
    uart_init();
    stdout = &uart_output;

    // Example usage
    print_binary("PINB", PINB); // Print PINB register in binary
    printf("PD2 status: %d\n", (PIND & (1 << PD2)) >> PD2); // Print PD2 pin status

    while (1) {
        // Your application code
    }
    return 0;
}

Notes

  • Ensure uart.c is in your project directory and configured for your AVR microcontroller (e.g., correct baud rate, clock frequency).
  • The pin_value used in printf should be derived from the appropriate register (e.g., PIND & (1 << PD2) for PD2).
  • This utility assumes a Linux terminal with a serial monitor (e.g., minicom, screen) configured to receive UART output.
  • Verify your AVR’s clock frequency and UART settings match the uart.c implementation to avoid communication issues.

About

Functions to print pin states and debug AVR microcontrollers in a Linux terminal via UART

Topics

Resources

Stars

Watchers

Forks