SlideShare a Scribd company logo
3
Most read
10
Most read
19
Most read
SERIAL COMMUNICATION IN ATMEGA 16 Suren Kumar @ embedautomation.com
Lets get started Wiki:- S erial  Port  is a serial communication physical interface through which information transfers in or out one bit at a time (contrast parallel port). Throughout most of the history of personal computers, data transfer through serial ports connected the computer to devices such as terminals and various peripherals. While such interfaces as Ethernet, FireWire, and USB all send data as a serial stream, the term "serial port" usually identifies hardware more or less compliant to the RS-232 standard, intended to interface with a modem or with a similar communication device.
Basics of Serial Communication Computers transfer data in two ways: parallel and serial. In parallel data transfer, several data bits are transferred simultaneously, e.g. to printers and hard disks. In serial data transfer, a single data bit is transferred at one time. Advantages of serial communications: longer distances, easier to synchronize, fewer IO pins, and lower cost. Serial communications often require - Shift registers: convert a byte to serial bits and vice versa. - Modems: modulate/demodulate serial bits to/from audio tones.
Shift Registers In digital circuits, a  shift register  is a group of flip flops set up in a linear fashion which have their inputs and outputs connected together in such a way that the data is shifted down the line when the circuit is activated.
Modem Modem (from modulator-demodulator) is a device that modulates an analog carrier signal to encode digital information, and also demodulates such a carrier signal to decode the transmitted information.  The goal is to produce a signal that can be transmitted easily and decoded to reproduce the original digital data. Modems can be used over any means of transmitting analog signals, from driven diodes to radio.
Synchronous and Asynchronous Synchronous serial communications - The clocks of the sender and receiver are synchronized. - A block of characters, enclosed by synchronizing bytes, is sent at a time. - Faster transfer and less overhead. Asynchronous serial communications - The clocks of the sender and receiver are not synchronized. - One character (8 or 7 bits) is sent at a time, enclosed between a start bit and one or two stop bits. A parity bit may be included.
Serial Communication Terminology Baud rate: the number of bits sent per second (bps). Baud rate is the number of signal changes per second. Parity bit: a single bit that is sent together with data bits to make the total number of 1’s even (for even parity) or odd (for odd parity);used for error checking. Start bit: to indicate the start of a character. Its typical value is 0. Stop bit: to indicate the end of a character. Its typical value is 1.
Data Framing Example
Pin Out of Serial Port
Serial Communication in ATMEGA 16 ATmega16 provides three subsystems for serial communications. - Universal Synchronous & Asynchronous Serial Receiver & Transmitter (USART) - Serial Peripheral Interface (SPI) - Two-wire Serial Interface (TWI) USART: - Supports full-duplex mode between a receiver and transmitter. - Typically used in asynchronous communication. - Start bit and stop bit are used for each byte of data.
Serial Communication in ATMEGA 16 Max 232:-  As we know for serial port we require TIA/EIA-232-F voltage level i.e. it can accept ±30-V.  MAX232 has a capacitive voltage generator to supply TIA/EIA-232-F voltage levels from a single 5-V supply.  Each receiver converts TIA/EIA-232-F inputs to 5-V TTL/CMOS levels.
Schematic of ATMEGA 16 with Serial Port
Serial USART – An Overview USART of the ATmega16 supports - baud rates from 960bps up to 57.6kbps, - character size: 5 to 9 bits, - 1 start bit, - 1 or 2 stop bits, - parity bit (optional, can be even or odd parity).
Block Diagram of USART - Datasheet
Serial USART – Hardware Elements USART Clock Generator: - to provide clock source. - to set baud rate using UBRR register. USART Transmitter: - to send a character through TxD pin. - to handle start/stop bit framing, parity bit, shift register. USART Receiver: - to receive a character through RxD pin. - to perform the reverse operation of the transmitter. USART Registers: - to configure, control and monitor the serial USART.
USART Baud Rate Registers The UBRRH Register shares the same I/O location as the UCSRC Register. See the “Accessing UBRRH/ UCSRC Registers” on page 155 section which describes how to access this register. •  Bit 15 – URSEL: Register Select :-  This bit selects between accessing the UBRRH or the UCSRC Register. It is read as zero when reading UBRRH. The URSEL must be zero when writing the UBRRH. •  Bit 14:12 – Reserved Bits :-  These bits are reserved for future use. For compatibility with future devices, these bit must be written to zero when UBRRH is written. •  Bit 11:0 – UBRR11:0: USART Baud Rate Register :-  This is a 12-bit register which contains the USART baud rate. The UBRRH contains the four most significant bits, and the UBRRL contains the 8 least significant bits of the USART baud rate. Ongoing transmissions by the transmitter and receiver will be corrupted if the baud rate is changed. Writing UBRRL will trigger an immediate update of the baud rate prescaler.
USART Baud Rate Registers Example: Find UBRR registers for baud rate of 1200bps, assuming system clock is 1MHz. Ans: UBRR = 1000000/(16 × 1200) ─ 1 = 51d = 0033H. Therefore, UBRRH = 00H and UBRRL = 33H. C code UBRRH = 0x00; UBRRL = 0x33;
USART Control & Status Register A  Read the registers USCRA,USCRB,USCRC from the DataSheet. There is no substitute other than reading datasheet to learn microcontroller
USART Data Register Register UDR is the buffer for characters sent or received through the serial port. To start sending a character, write it to UDR. unsigned char data; data = ‘a’; UDR = data; // start sending character To check a received character, read it from UDR. unsigned char data; data = UDR; // this will clear UDR
Serial USART – Main Tasks Initializing the serial port. Sending a character. Receiving a character. Sending/receiving formatted strings.
Initializing Serial Port Set USART communication parameter (data bit, stop bit, parity bit) Enable transmitter and reciever Set USART for asynchronous mode Set Baud Rate
Initializing Serial Port - Example Initialize serial port of ATmega16 to baud rate 1200, no parity, 1 stop bit, 8 data bits. Assume a clock speed of 1MHz. void USART_init(void){ // Normal speed, disable multi-proc UCSRA = 0b00000000; // Enable Tx and Rx, disable interrupts UCSRB = 0b00011000; // Asynchronous mode, no parity, 1 stop bit, 8 data bits UCSRC = 0b10000110; // Baud rate 1200bps, assuming 1MHz clock UBRRL = 0x33; UBRRH = 0x00; }
Sending a character Has UDRE flag been set to 1? (Register UCSRA) Write the character to register UDR for transmission Student Task: Write C code to send a character through the Serial Port:
Receiving a Character  Has RXC flag been set to 1? (Register USCRA) Read the received character from register UDR unsigned char USART_receive(void){ // wait until RXC flag is set to logic 1 ……………………………… . return (UDR); // Read the received character from UDR }

More Related Content

PDF
ARM CORTEX M3 PPT
PPTX
PPT
Static and Dynamic Read/Write memories
PPT
Uart
ODP
APB protocol v1.0
PPTX
Behavioral modelling in VHDL
PPT
I2C Protocol
PDF
SRAM Design
ARM CORTEX M3 PPT
Static and Dynamic Read/Write memories
Uart
APB protocol v1.0
Behavioral modelling in VHDL
I2C Protocol
SRAM Design

What's hot (20)

PDF
SPI Protocol
PPTX
Stacks & subroutines 1
PPTX
PPTX
Bus Structure, Memory and I/O Interfacing
PPTX
I2c protocol - Inter–Integrated Circuit Communication Protocol
PPTX
Communication protocols
PPTX
Convolutional codes
PPTX
Low noise amplifier
PPTX
Minimum mode and Maximum mode Configuration in 8086
PPTX
AXI Protocol.pptx
PPTX
Serial Peripheral Interface
PPTX
Lpc 1768 timers
PDF
Router 1X3 – RTL Design and Verification
PPT
PDF
Combinational and sequential logic
PPT
Error Detection And Correction
PPTX
Quadrature phase shift keying
PPTX
Introduction to arm processor
DOCX
301378156 design-of-sram-in-verilog
PPT
I2 c
SPI Protocol
Stacks & subroutines 1
Bus Structure, Memory and I/O Interfacing
I2c protocol - Inter–Integrated Circuit Communication Protocol
Communication protocols
Convolutional codes
Low noise amplifier
Minimum mode and Maximum mode Configuration in 8086
AXI Protocol.pptx
Serial Peripheral Interface
Lpc 1768 timers
Router 1X3 – RTL Design and Verification
Combinational and sequential logic
Error Detection And Correction
Quadrature phase shift keying
Introduction to arm processor
301378156 design-of-sram-in-verilog
I2 c
Ad

Viewers also liked (20)

PPTX
Input Output programming in AVR microcontroller
PPTX
Introduction to AVR Microcontroller
PPTX
Servo motor and AVR Atmel Atmega 16
PPT
Embedded System
PPTX
Relay and AVR Atmel Atmega 16
PPTX
embedded system and AVR
PPSX
Programming ATmega microcontroller using Embedded C
PPT
AVR Fundamentals
PPTX
AVR programming - BASICS
PPTX
DOCX
digital clock atmega16
DOCX
project report on embedded system
PDF
07 Analogue to Digital Converter(ADC).2016
PPT
Curiosity Rover
DOC
SenthilkumarCV
PDF
J012336467
PDF
Portfolio - Revised
PPTX
Fundamentals of embedded system and electronics
DOCX
Persistence of Vision Display
PPTX
Timer & Interrupt Atmega16
Input Output programming in AVR microcontroller
Introduction to AVR Microcontroller
Servo motor and AVR Atmel Atmega 16
Embedded System
Relay and AVR Atmel Atmega 16
embedded system and AVR
Programming ATmega microcontroller using Embedded C
AVR Fundamentals
AVR programming - BASICS
digital clock atmega16
project report on embedded system
07 Analogue to Digital Converter(ADC).2016
Curiosity Rover
SenthilkumarCV
J012336467
Portfolio - Revised
Fundamentals of embedded system and electronics
Persistence of Vision Display
Timer & Interrupt Atmega16
Ad

Similar to Serial Communication In Atmega 16 (20)

PDF
Lecture 3 - Serial Communicationkahfag.pdf
PPT
AN INTRODUCTION TO SERIAL PORT INTERFACING
DOCX
Tutorial
PDF
Universal asynchronous receiver_transmitter_uart_rs232
PPT
Serial Communication Part-16
PPTX
The presentation is about USART and serial communication
PDF
Embedded Communications Protocols UNIT 3PDF.pdf
PPTX
Universal Serial Communication Interface
PDF
MPS W8-L2L3 Programming AVR Serial Port Ia (in C).pdf
PDF
Serial Port Device Driver
PPT
8051 microcontroller notes continuous
PPS
Robotix Tutorial 8
PPTX
Serial communication in LPC2148
PDF
Firmware implementation of UART using Bare metal programming
PDF
Device Operation using PC by Arduino (1).pdf
PPTX
Serial Communication Uart soc
PPT
Gsm presentation
PPT
Gsm presentation
Lecture 3 - Serial Communicationkahfag.pdf
AN INTRODUCTION TO SERIAL PORT INTERFACING
Tutorial
Universal asynchronous receiver_transmitter_uart_rs232
Serial Communication Part-16
The presentation is about USART and serial communication
Embedded Communications Protocols UNIT 3PDF.pdf
Universal Serial Communication Interface
MPS W8-L2L3 Programming AVR Serial Port Ia (in C).pdf
Serial Port Device Driver
8051 microcontroller notes continuous
Robotix Tutorial 8
Serial communication in LPC2148
Firmware implementation of UART using Bare metal programming
Device Operation using PC by Arduino (1).pdf
Serial Communication Uart soc
Gsm presentation
Gsm presentation

Recently uploaded (20)

PPTX
sap open course for s4hana steps from ECC to s4
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Encapsulation theory and applications.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPT
Teaching material agriculture food technology
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Approach and Philosophy of On baking technology
sap open course for s4hana steps from ECC to s4
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Review of recent advances in non-invasive hemoglobin estimation
MIND Revenue Release Quarter 2 2025 Press Release
Encapsulation theory and applications.pdf
MYSQL Presentation for SQL database connectivity
Diabetes mellitus diagnosis method based random forest with bat algorithm
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Empathic Computing: Creating Shared Understanding
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Reach Out and Touch Someone: Haptics and Empathic Computing
Per capita expenditure prediction using model stacking based on satellite ima...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Electronic commerce courselecture one. Pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Teaching material agriculture food technology
Building Integrated photovoltaic BIPV_UPV.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Approach and Philosophy of On baking technology

Serial Communication In Atmega 16

  • 1. SERIAL COMMUNICATION IN ATMEGA 16 Suren Kumar @ embedautomation.com
  • 2. Lets get started Wiki:- S erial Port is a serial communication physical interface through which information transfers in or out one bit at a time (contrast parallel port). Throughout most of the history of personal computers, data transfer through serial ports connected the computer to devices such as terminals and various peripherals. While such interfaces as Ethernet, FireWire, and USB all send data as a serial stream, the term "serial port" usually identifies hardware more or less compliant to the RS-232 standard, intended to interface with a modem or with a similar communication device.
  • 3. Basics of Serial Communication Computers transfer data in two ways: parallel and serial. In parallel data transfer, several data bits are transferred simultaneously, e.g. to printers and hard disks. In serial data transfer, a single data bit is transferred at one time. Advantages of serial communications: longer distances, easier to synchronize, fewer IO pins, and lower cost. Serial communications often require - Shift registers: convert a byte to serial bits and vice versa. - Modems: modulate/demodulate serial bits to/from audio tones.
  • 4. Shift Registers In digital circuits, a shift register is a group of flip flops set up in a linear fashion which have their inputs and outputs connected together in such a way that the data is shifted down the line when the circuit is activated.
  • 5. Modem Modem (from modulator-demodulator) is a device that modulates an analog carrier signal to encode digital information, and also demodulates such a carrier signal to decode the transmitted information. The goal is to produce a signal that can be transmitted easily and decoded to reproduce the original digital data. Modems can be used over any means of transmitting analog signals, from driven diodes to radio.
  • 6. Synchronous and Asynchronous Synchronous serial communications - The clocks of the sender and receiver are synchronized. - A block of characters, enclosed by synchronizing bytes, is sent at a time. - Faster transfer and less overhead. Asynchronous serial communications - The clocks of the sender and receiver are not synchronized. - One character (8 or 7 bits) is sent at a time, enclosed between a start bit and one or two stop bits. A parity bit may be included.
  • 7. Serial Communication Terminology Baud rate: the number of bits sent per second (bps). Baud rate is the number of signal changes per second. Parity bit: a single bit that is sent together with data bits to make the total number of 1’s even (for even parity) or odd (for odd parity);used for error checking. Start bit: to indicate the start of a character. Its typical value is 0. Stop bit: to indicate the end of a character. Its typical value is 1.
  • 9. Pin Out of Serial Port
  • 10. Serial Communication in ATMEGA 16 ATmega16 provides three subsystems for serial communications. - Universal Synchronous & Asynchronous Serial Receiver & Transmitter (USART) - Serial Peripheral Interface (SPI) - Two-wire Serial Interface (TWI) USART: - Supports full-duplex mode between a receiver and transmitter. - Typically used in asynchronous communication. - Start bit and stop bit are used for each byte of data.
  • 11. Serial Communication in ATMEGA 16 Max 232:- As we know for serial port we require TIA/EIA-232-F voltage level i.e. it can accept ±30-V. MAX232 has a capacitive voltage generator to supply TIA/EIA-232-F voltage levels from a single 5-V supply. Each receiver converts TIA/EIA-232-F inputs to 5-V TTL/CMOS levels.
  • 12. Schematic of ATMEGA 16 with Serial Port
  • 13. Serial USART – An Overview USART of the ATmega16 supports - baud rates from 960bps up to 57.6kbps, - character size: 5 to 9 bits, - 1 start bit, - 1 or 2 stop bits, - parity bit (optional, can be even or odd parity).
  • 14. Block Diagram of USART - Datasheet
  • 15. Serial USART – Hardware Elements USART Clock Generator: - to provide clock source. - to set baud rate using UBRR register. USART Transmitter: - to send a character through TxD pin. - to handle start/stop bit framing, parity bit, shift register. USART Receiver: - to receive a character through RxD pin. - to perform the reverse operation of the transmitter. USART Registers: - to configure, control and monitor the serial USART.
  • 16. USART Baud Rate Registers The UBRRH Register shares the same I/O location as the UCSRC Register. See the “Accessing UBRRH/ UCSRC Registers” on page 155 section which describes how to access this register. • Bit 15 – URSEL: Register Select :- This bit selects between accessing the UBRRH or the UCSRC Register. It is read as zero when reading UBRRH. The URSEL must be zero when writing the UBRRH. • Bit 14:12 – Reserved Bits :- These bits are reserved for future use. For compatibility with future devices, these bit must be written to zero when UBRRH is written. • Bit 11:0 – UBRR11:0: USART Baud Rate Register :- This is a 12-bit register which contains the USART baud rate. The UBRRH contains the four most significant bits, and the UBRRL contains the 8 least significant bits of the USART baud rate. Ongoing transmissions by the transmitter and receiver will be corrupted if the baud rate is changed. Writing UBRRL will trigger an immediate update of the baud rate prescaler.
  • 17. USART Baud Rate Registers Example: Find UBRR registers for baud rate of 1200bps, assuming system clock is 1MHz. Ans: UBRR = 1000000/(16 × 1200) ─ 1 = 51d = 0033H. Therefore, UBRRH = 00H and UBRRL = 33H. C code UBRRH = 0x00; UBRRL = 0x33;
  • 18. USART Control & Status Register A Read the registers USCRA,USCRB,USCRC from the DataSheet. There is no substitute other than reading datasheet to learn microcontroller
  • 19. USART Data Register Register UDR is the buffer for characters sent or received through the serial port. To start sending a character, write it to UDR. unsigned char data; data = ‘a’; UDR = data; // start sending character To check a received character, read it from UDR. unsigned char data; data = UDR; // this will clear UDR
  • 20. Serial USART – Main Tasks Initializing the serial port. Sending a character. Receiving a character. Sending/receiving formatted strings.
  • 21. Initializing Serial Port Set USART communication parameter (data bit, stop bit, parity bit) Enable transmitter and reciever Set USART for asynchronous mode Set Baud Rate
  • 22. Initializing Serial Port - Example Initialize serial port of ATmega16 to baud rate 1200, no parity, 1 stop bit, 8 data bits. Assume a clock speed of 1MHz. void USART_init(void){ // Normal speed, disable multi-proc UCSRA = 0b00000000; // Enable Tx and Rx, disable interrupts UCSRB = 0b00011000; // Asynchronous mode, no parity, 1 stop bit, 8 data bits UCSRC = 0b10000110; // Baud rate 1200bps, assuming 1MHz clock UBRRL = 0x33; UBRRH = 0x00; }
  • 23. Sending a character Has UDRE flag been set to 1? (Register UCSRA) Write the character to register UDR for transmission Student Task: Write C code to send a character through the Serial Port:
  • 24. Receiving a Character Has RXC flag been set to 1? (Register USCRA) Read the received character from register UDR unsigned char USART_receive(void){ // wait until RXC flag is set to logic 1 ……………………………… . return (UDR); // Read the received character from UDR }