What is USART?
USART stands for Universal Synchronous/Asynchronous Receiver/Transmitter, and it is a communication interface module available in the Atmega328P microcontroller. The USART module allows the Atmega328P microcontroller to communicate with other devices, such as other microcontrollers, computers, or peripherals, using serial communication protocols.
The USART module in the Atmega328P microcontroller supports both synchronous and asynchronous serial communication.
Transmitting and Receiving Data using UART communication in Arduino/ATmega328p/ATmega2560?
Transmitting and receiving data using UART (USART) communication in Arduino, Atmega328P, or Atmega2560 microcontrollers involves several steps such as configuration of the UART module, setting the communication parameters including baud rate and data format, and using appropriate functions to send and receive data.
Configure UART: Set the UART registers to configure the communication parameters such as baud rate, data format, and interrupt settings. The specific registers and settings may vary depending on the microcontroller used (Atmega328P or Atmega2560) and the Arduino board (Uno, Mega, etc.) you are using. E.g.- In Arduino, you can use the Serial.begin() function to configure the UART settings.
Sending Data: To send data over UART, you can use the appropriate write functions provided by the UART library. E.g.- In Arduino, you can use the Serial.write() function to send data as bytes or the Serial.print() function to send data as human-readable ASCII characters.
Receiving Data: To receive data over UART, you can use the appropriate read functions provided by the UART library. E.g.- In Arduino, you can use the Serial.read() function to read a single byte of data from the UART buffer, or the Serial.readString() function to read a string of characters terminated by a specific delimiter.
Four modes of clock operations USART supports
o Asynchronous Normal Mode
o Asynchronous Double Speed Mode
o Synchronous Master Mode
o Synchronous Slave Mode
The meaning of “9600 baud” in the serial port context
"9600 baud" refers to the baud rate or symbol rate, which is the rate at which data is transmitted or received over a serial communication channel. The Baud rate represents the number of symbols (usually bits) transmitted per second.
A baud rate of 9600 means that 9600 symbols (usually bits) are transmitted or received per second.
It's important to ensure that both the transmitting and receiving devices are configured with the same baud rate, otherwise, the communication may be unreliable or fail altogether.
Code for ATmega328/ATmega2560 – Communicate using USART
#include
<avr/io.h>
#include
<util/delay.h>
int
main (void)
{
// initial configuration
UCSR0B |= (1<<TXEN0); // Enable the
transmitter
UCSR0C |= (1<<UPM01); // Parity mode
enable, set even parity
UBRR0L = 0x67; // set baud rate
while(1) {
while(!(UCSR0A & (1<<UDRE0))) //
check data is transmitted
{
}
UDR0 = 'A'; // set data to data register
_delay_ms(1000); // delay for 1 sec
}
}
Reference
1.
Author Cadence PCB Solutions et al. (2023) Usart
vs. UART: What's the difference?, USART vs. UART: What's the Difference?
Available at:
https://resources.pcb.cadence.com/blog/usart-vs-uart-whats-the-difference
(Accessed: April 20, 2023).
2.
Baud rate and its importance (2021) GeeksforGeeks.
GeeksforGeeks. Available at:
https://www.geeksforgeeks.org/baud-rate-and-its-importance/ (Accessed: April
20, 2023).
Comments
Post a Comment