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

USART serial communication interface. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

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

Detailed Description

USART serial communication interface.

This file provides functions for initializing and using the USART (Universal Synchronous/Asynchronous Receiver/Transmitter) peripheral for serial communication. It supports byte transmission/reception, string printing, and formatted output.

Author
Roybel Carbonell Camejo
Date
2026-04-29
Note
All functions are blocking by design for simplicity
See also
CPU.h For F_CPU and BAUD configuration

Definition in file USART.h.

Function Documentation

◆ initUSART()

void initUSART ( void  )

Initializes the USART peripheral for serial communication.

Configures the USART with the following settings:

  • Asynchronous mode
  • Baud rate defined by BAUD macro (from CPU.h)
  • 8 data bits
  • 1 stop bit
  • No parity
  • Transmitter and receiver enabled
Note
Must be called before any other USART functions
Warning
Baud rate calculation depends on F_CPU macro from CPU.h
See also
CPU.h For F_CPU and BAUD definitions

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
Examples
/home/luka/WORK/Programming/ARDUINO/AVR-Square-Wave-Organ/src/main.c.

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.

Transmits each character of the string sequentially until the null terminator ('\0') is reached.

Parameters
StringPointer to the null-terminated string to transmit
Note
Function is blocking - waits for each byte to be transmitted
Warning
String must be properly null-terminated to avoid buffer overrun
See also
transmitByte For single byte transmission
Examples
/home/luka/WORK/Programming/ARDUINO/AVR-Square-Wave-Organ/src/main.c.

Referenced by main().

Here is the caller graph for this function:

◆ receiveByte()

uint8_t receiveByte ( void  )

Receives a single byte from USART.

Waits for a byte to be received on the USART RX line and returns it. Function blocks until data is available.

Returns
uint8_t The received byte (0-255)
Note
Blocking function - will wait indefinitely for incoming data
Warning
Ensure the transmitter is sending data to avoid infinite wait

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
Examples
/home/luka/WORK/Programming/ARDUINO/AVR-Square-Wave-Organ/src/main.c.

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.

Sends one byte of data through the USART TX line. Function blocks until the transmission is complete.

Parameters
dataThe byte (0-255) to transmit
Note
Useful for sending raw binary data
See also
printString For sending strings
printByte For sending bytes as formatted text

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
Examples
/home/luka/WORK/Programming/ARDUINO/AVR-Square-Wave-Organ/src/main.c.

Definition at line 71 of file USART.c.

Referenced by main(), and printString().

Here is the caller graph for this function: