Serial Musical Organ 1.0
Buzzer controller and musical organ
Loading...
Searching...
No Matches
Functions
USART.c File Reference

Implementation of USART serial communication functions. More...

#include "includes/CPU.h"
#include <avr/io.h>
#include "includes/USART.h"
#include <util/setbaud.h>
Include dependency graph for USART.c:

Go to the source code of this file.

Functions

void initUSART (void)
 Initializes the USART peripheral.
 
void transmitByte (uint8_t data)
 Transmits a single byte over USART.
 
uint8_t receiveByte (void)
 Receives a single byte from USART.
 
void printString (const char *String)
 Sends a null-terminated string over USART.
 

Detailed Description

Implementation of USART serial communication functions.

This file contains the implementation for initializing and using the USART peripheral on AVR microcontrollers. It provides functions for byte transmission/reception, string output, and formatted printing.

Author
Roybel Carbonell Camejo
Date
2026-04-29
Note
Uses setbaud.h header for automatic baud rate calculation
See also
USART.h For function interfaces

Definition in file USART.c.

Function Documentation

◆ initUSART()

void initUSART ( void  )

Initializes the USART peripheral.

Initializes the USART peripheral for serial communication.

Configures the USART with baud rate from setbaud.h calculations, enables transmitter and receiver, and sets frame format to 8 data bits, 1 stop bit, no parity.

Note
The setbaud.h header uses F_CPU and BAUD macros from CPU.h
Warning
Baud rate error checking should be performed at compile time
See also
CPU.h For F_CPU and BAUD definitions
<util/setbaud.h> For baud rate calculation macros

Definition at line 34 of file USART.c.

Referenced by main().

Here is the caller graph for this function:

◆ printString()

void printString ( const char *  String)

Sends a null-terminated string over USART.

Iterates through each character in the string and transmits it one by one until the null terminator is reached.

Parameters
StringPointer to the null-terminated string to transmit
Note
Blocking - each character waits for transmission to complete
Warning
String must be properly null-terminated

Definition at line 105 of file USART.c.

References transmitByte().

Here is the call graph for this function:

◆ receiveByte()

uint8_t receiveByte ( void  )

Receives a single byte from USART.

Waits for a byte to be received (RXC flag set), then returns the received data from the UDR register.

Returns
uint8_t The received byte (0-255)
Note
Blocking function - waits indefinitely for incoming data
Warning
Ensure data is available before calling to avoid infinite loop

Definition at line 88 of file USART.c.

Referenced by main().

Here is the caller graph for this function:

◆ transmitByte()

void transmitByte ( uint8_t  data)

Transmits a single byte over USART.

Waits for the transmit data register to be empty, then loads the data into the UDR register for transmission.

Parameters
dataThe byte to transmit (0-255)
Note
Blocking function - waits until transmission buffer is ready
Warning
If called too frequently, may cause data loss

Definition at line 71 of file USART.c.

Referenced by main(), and printString().

Here is the caller graph for this function: