SlideShare una empresa de Scribd logo
1 de 15
E l e c t r o n i c s E n g g S o c i e t y Page 1
Interfacing Micro-controller
with PC
Electronics Engineering
Society
IT-BHU
E l e c t r o n i c s E n g g S o c i e t y Page 2
Contents
Introduction
PC – Serial Port
RS-232 Protocol
Theory of Operation
Setting UART in micro-controller
Hyper Terminal
E l e c t r o n i c s E n g g S o c i e t y Page 3
Introduction:
There are many ways to interface your microcontroller to computer. The
easiest way is to useUART i.e. Universal Asynchronous Receiver
Transmitter.It is a way of communication between the microcontroller and
the computer system or another microcontroller.
Data exchange can be done using serial or parallel techniques. In parallel
communication, the complete byte of data is sent at one time with each bit
having a separated dedicated data line. This method is very fast but not
cost effective. On the other hand serial communication is somewhat slower
as every bit of data is sent serially one by one but is cost effective as only
two data lines i.e. transmitter and receiver lines are required (of course a
ground line is also required in addition to these two). Serial data
communication can be further divided into two categories - synchronous
and asynchronous. In synchronous communication transmitter and
receiver are synchronised by a clock whereas in asynchronous system no
clock pulse is shared between receiver and transmitter. As the name
suggests UART is an example of asynchronous communication. Since no
common clock is shared, a known data transfer rate (baud rate) must be
agreed upon prior to data transmission i.e. the receiving UART needs to
know the transmitting UART’s baud rate (and conversely the transmitter
needs to know the receiver’s baud rate).
Interfacing ATMEGA-16 with PC
E l e c t r o n i c s E n g g S o c i e t y Page 4
Serial Communication in PC – The
Serial Port:
Figure 1.1: Serial Port of a computer
We will be using Serial Port for communication between the
microcontroller and the computer. A serial port has 9 pins as shown. If you
have a laptop, then most probably there won’t be a serial port. Then you
can use a USB to serial Converter.
If you have to transmit one byte of data, the serial port will transmit 8 bits
as one bit at a time. The advantage is that a serial port needs only one wire
to transmit the 8 bits.
E l e c t r o n i c s E n g g S o c i e t y Page 5
RS-232 Protocol:
The standard used for serial communication is RS-232 (Recommended
Standard 232). The standard defines voltage levels that correspond to
logical zero and logical one level. Voltages between plus and minus 3 to 15
volts are allowed voltages.Logic one is defined as a negative voltage; the
signal condition is called marking, and has the functional significance of
OFF. Logic zero is positive; the signal condition is spacing, and has the
function ON.Voltage between plus or minus 3 volts near zero are not
allowed. This is not the voltage level at which our microcontroller works.
We have two different machines with two different ways to define 0 & 1
and we want to exchange information between them. Consider
microcontroller as a French and Computer's Serial Port as an Indian person
(obviously no common language in between!). If they want to exchange
information they basically need a mediator who knows both the language.
In other words, we need a device which can convert serial port’s voltage
level to that of CMOS( i.e. logic 1 = +5V and logic 0 = 0V). This task is carried
out by an IC MAX 232, which is always used with four 10uF capacitors. The
circuit is shown:
E l e c t r o n i c s E n g g S o c i e t y Page 6
Figure 1.2: MAX 232 circuit
Theory of Operation:
Figure 1.3illustrates a basic UART data packet. While no data is being
transmitted,logic 1 must be placed in the Tx line. A data packet is composed
of 1 start bit, which is always a logic 0, followed by a programmable
number of data bits (typically between 6 to 8), an optional parity bit, and a
programmable number of stop bits (typically 1). The stop bit must always
be logic 1.
Most UART uses 8bits for data, no parity and 1 stop bit. Thus, it takes 10
bits to transmit a byte of data.
E l e c t r o n i c s E n g g S o c i e t y Page 7
Figure 1.3: Basic UART Frame Format
BAUD Rate: This parameter specifies the desired baud rate (bits per
second) of the UART. Most typical standard baud rates are: 300, 1200,
2400, 9600, 19200, etc. However, any baud rate can be used. This
parameter affects both the receiver and the transmitter. The default is 2400
(bauds).
In the UART protocol, the transmitter and the receiver do not share a clock
signal. That is, a clock signal does not emanate from one UART transmitter
to the other UART receiver. Due to this reason the protocol is said to be
asynchronous.
Since no common clock is shared, a known data transfer rate (baud rate)
must be agreed upon prior to data transmission. That is, the receiving
UART needs to know the transmitting UART’s baud rate (and conversely
the transmitter needs to know the receiver’s baud rate, if any). In almost all
cases the receiving and transmitting baud rates are the same. The
transmitter shifts out the data starting with the LSB first.
Once the baud rate has been established (prior to initial communication),
both the transmitter and the receiver’s internal clock is set to the same
frequency (though not the same phase). The receiver "synchronizes" its
E l e c t r o n i c s E n g g S o c i e t y Page 8
internal clock to that of the transmitter’s at the beginning of every data
packet received. This allows the receiver to sample the data bit at the bit-
cell centre.
A key concept in UART design is that UART’s internal clock runs at much
faster rate than the baud rate. For example, the popular 16450 UART
controller runs its internal clock at 16 times the baud rate. This allows the
UART receiver to sample the incoming data with granularity of 1/16 the
baud-rate period. This "oversampling" is critical since the receiver adds
about 2 clock-ticks in the input data synchronizer uncertainty. The
incoming data is not sampled directly by the receiver, but goes through a
synchronizer which translates the clock domain from the transmitter’s to
that of the receiver. Additionally, the greater the granularity, the receiver
has greater immunity with the baud rate error.
The receiver detects the start bit by detecting the transition from logic 1 to
logic 0 (note that while the data line is idle, the logic level is high). In the
case of 16450 UART, once the start-bit is detected, the next data bit’s
"centre" can be assured to be 24 ticks minus 2 (worse case synchronizer
uncertainty) later. From then on, every next data bit centre is 16 clock ticks
later. Figure 2 illustrates this point.
Once the start bit is detected, the subsequent data bits are assembled in a
de-serializer. Error condition maybe generated if the parity/stop bits are
incorrect or missing.
E l e c t r o n i c s E n g g S o c i e t y Page 9
Figure 1.3: Data sampling points by the UART Receiver
Using UART in microcontroller:
The USART has to be initialized before any communication can take place.
The initialization process normally consists of setting the baud rate, setting
frame format and enabling theTransmitter or the Receiver depending on
the usage.Setting these in ATMEGA16 requires knowledge about USART
registers (UCSR, UBRR and UDR) and their programming. Here our CV-AVR
code wizard comes to our help. It generates codes for initialising USART in
ATMEGA16 automatically! So you need not mess with the AVR Registers.
All you have to do is to click some check-boxes and the code wizard will
generate all the initialisation codes.
E l e c t r o n i c s E n g g S o c i e t y Page 10
Using CV-AVR Code Wizard:
Create a new project in CV-AVR as usual using code wizard and click on
USART tab.Now depending upon your requirement, you can either check
receiver, transmitter or both.
You get a list of options to select from for the baud rate. Baud Rate is the
unit of data transfer, defined as bits per second. We will select 9600 as it is
fair enough for our purpose, and default setting in most of the applications
(like Matlab, Docklight, etc.). Keep the communication parameters as
default, i.e., 8 data, 1 stop and no parity and mode asynchronous. You also
have option of enabling Rx and Tx Interrupt functions. Enabling them will
E l e c t r o n i c s E n g g S o c i e t y Page 11
generate an interrupt on reception and transmission completion. But as
we don’t need an interrupt at this point we will not enable interrupts here.
Once you generate and save the code, all the register values are set by
CVAVR and you only need to know some of the C functions to transfer data.
Some of them are:
1.putchar: Sends one character to the buffer that can be received by
receiving device.e.g.
putchar(‘a’); //sends character a to the buffer
putchar(‘F’); //sends character F to the buffer
2. getchar: To receive one character from the buffer, which might have
been sent by the other uC or the computer. E.g., if we have already defined a
variable char c, then
c = getchar();// receives the character from buffer and save it in variable c
Similarly, there are functions like puts() and gets() that work on string in
similar fashion.
Hyper-Terminal:
To communicate with the computer, you need a terminal where you can
send data through keyboard and the received data can be displayed on the
screen. There are many softwares which provide such terminal, but we will
be using Hyper-terminal. Its evaluation version is free for download on
internet, which is sufficient for our purpose.
You can download the evaluation version of hyper-terminal from
http://www.hilgraeve.com/htpe/support/htpe7.exe
E l e c t r o n i c s E n g g S o c i e t y Page 12
To use hyper-terminal, just click on its icon from programs folder in
your start menu. In the new connection dialog box that appears, enter a
name for your connection and click OK.
Figure 1.4
In the next dialog box enter the com port on which your usb to serial
connector is working and click OK. To find out the COM port on which your
serial connector is working, check the Device Manager in System
Properties.
Note: The COM port changes every time you plug-in the connector.
E l e c t r o n i c s E n g g S o c i e t y Page 13
Figure 1.5
In the dialog box that appears enter the values for baud rate, character size
of uart data frame, parity bits, number of stop bits and flow control. These
values should be same as that you have configured in your microcontroller.
However, most of the systems use 9600 baud-rate, 8 data bits and no
parity. If you are also using this configuration, click RESTORE DEFAULT
button.
E l e c t r o n i c s E n g g S o c i e t y Page 14
Figure 1.6
Click on OK and you are ready to send and receive data over serial port.
Type anything on the keyboard and it will be transmitted over uart.
Anything received over UART will appear on the screen.
E l e c t r o n i c s E n g g S o c i e t y Page 15
Figure 1.7
If you have any suggestion that you would like to share with us feel free to
contact at:
akash.singh.ece10@itbhu.ac.in
Akash Singh
Electronics Engg.
IT BHU

Más contenido relacionado

La actualidad más candente

Arrow Devices USB 2.0 Concepts
Arrow Devices USB 2.0 ConceptsArrow Devices USB 2.0 Concepts
Arrow Devices USB 2.0 ConceptsArrow Devices
 
Imx53 uart- GUIDE BOOK
Imx53 uart- GUIDE BOOKImx53 uart- GUIDE BOOK
Imx53 uart- GUIDE BOOKShahrukh Javed
 
Verification of uart ip core using uvm
Verification of uart ip core using uvmVerification of uart ip core using uvm
Verification of uart ip core using uvmeSAT Publishing House
 
Serial communication in LPC2148
Serial communication in LPC2148Serial communication in LPC2148
Serial communication in LPC2148sravannunna24
 
Serial Communication Part-16
Serial Communication Part-16Serial Communication Part-16
Serial Communication Part-16Techvilla
 
Micro c lab8(serial communication)
Micro c lab8(serial communication)Micro c lab8(serial communication)
Micro c lab8(serial communication)Mashood
 
UART(universal asynchronous receiver transmitter ) PPT
UART(universal asynchronous receiver transmitter ) PPTUART(universal asynchronous receiver transmitter ) PPT
UART(universal asynchronous receiver transmitter ) PPTSai_praneeth
 
Fpga implementation of utmi with usb 2.O
Fpga implementation of  utmi  with usb 2.O Fpga implementation of  utmi  with usb 2.O
Fpga implementation of utmi with usb 2.O Mathew George
 
Uart driver nov13
Uart driver nov13Uart driver nov13
Uart driver nov13abinaya m
 
UART Communication
UART CommunicationUART Communication
UART Communicationdattatraya1
 
FPGA IMPLIMENTATION OF UART CONTTROLLER
FPGA IMPLIMENTATION OF UART CONTTROLLERFPGA IMPLIMENTATION OF UART CONTTROLLER
FPGA IMPLIMENTATION OF UART CONTTROLLERVarun Kambrath
 
Fun and Easy UART - How the UART Protocol Works
Fun and Easy UART - How the UART Protocol WorksFun and Easy UART - How the UART Protocol Works
Fun and Easy UART - How the UART Protocol WorksRitesh Kanjee
 
Asynchronous Serial Communication and standards
Asynchronous Serial Communication and standardsAsynchronous Serial Communication and standards
Asynchronous Serial Communication and standardsMathivanan Natarajan
 
Serial Communication
Serial CommunicationSerial Communication
Serial CommunicationUshaRani289
 

La actualidad más candente (20)

Arrow Devices USB 2.0 Concepts
Arrow Devices USB 2.0 ConceptsArrow Devices USB 2.0 Concepts
Arrow Devices USB 2.0 Concepts
 
Imx53 uart- GUIDE BOOK
Imx53 uart- GUIDE BOOKImx53 uart- GUIDE BOOK
Imx53 uart- GUIDE BOOK
 
Uart
UartUart
Uart
 
Verification of uart ip core using uvm
Verification of uart ip core using uvmVerification of uart ip core using uvm
Verification of uart ip core using uvm
 
Serial communication in LPC2148
Serial communication in LPC2148Serial communication in LPC2148
Serial communication in LPC2148
 
Serial Communication Part-16
Serial Communication Part-16Serial Communication Part-16
Serial Communication Part-16
 
Micro c lab8(serial communication)
Micro c lab8(serial communication)Micro c lab8(serial communication)
Micro c lab8(serial communication)
 
UART(universal asynchronous receiver transmitter ) PPT
UART(universal asynchronous receiver transmitter ) PPTUART(universal asynchronous receiver transmitter ) PPT
UART(universal asynchronous receiver transmitter ) PPT
 
Uart
UartUart
Uart
 
Fpga implementation of utmi with usb 2.O
Fpga implementation of  utmi  with usb 2.O Fpga implementation of  utmi  with usb 2.O
Fpga implementation of utmi with usb 2.O
 
Uart driver nov13
Uart driver nov13Uart driver nov13
Uart driver nov13
 
Uart 16550
Uart 16550Uart 16550
Uart 16550
 
UART
UARTUART
UART
 
UART Communication
UART CommunicationUART Communication
UART Communication
 
NAVEEN UART BATCH 43
NAVEEN UART BATCH 43NAVEEN UART BATCH 43
NAVEEN UART BATCH 43
 
Naveen UART BATCH 43
Naveen UART BATCH 43Naveen UART BATCH 43
Naveen UART BATCH 43
 
FPGA IMPLIMENTATION OF UART CONTTROLLER
FPGA IMPLIMENTATION OF UART CONTTROLLERFPGA IMPLIMENTATION OF UART CONTTROLLER
FPGA IMPLIMENTATION OF UART CONTTROLLER
 
Fun and Easy UART - How the UART Protocol Works
Fun and Easy UART - How the UART Protocol WorksFun and Easy UART - How the UART Protocol Works
Fun and Easy UART - How the UART Protocol Works
 
Asynchronous Serial Communication and standards
Asynchronous Serial Communication and standardsAsynchronous Serial Communication and standards
Asynchronous Serial Communication and standards
 
Serial Communication
Serial CommunicationSerial Communication
Serial Communication
 

Destacado (8)

ЮУрГУ Прикладная информатика
ЮУрГУ Прикладная информатикаЮУрГУ Прикладная информатика
ЮУрГУ Прикладная информатика
 
Proiect spm
Proiect spmProiect spm
Proiect spm
 
Mco_mulllti
Mco_mulllti Mco_mulllti
Mco_mulllti
 
ASA Conference Brochure
ASA Conference BrochureASA Conference Brochure
ASA Conference Brochure
 
Impact of Driver Training on Fuel Efficiency - Jaspal Singh
Impact of Driver Training on Fuel Efficiency - Jaspal SinghImpact of Driver Training on Fuel Efficiency - Jaspal Singh
Impact of Driver Training on Fuel Efficiency - Jaspal Singh
 
ЛЮДИ-БРЕНДЫ
ЛЮДИ-БРЕНДЫЛЮДИ-БРЕНДЫ
ЛЮДИ-БРЕНДЫ
 
Tips For PM Prosperity
Tips For PM ProsperityTips For PM Prosperity
Tips For PM Prosperity
 
Basic Technical Analysis
Basic Technical AnalysisBasic Technical Analysis
Basic Technical Analysis
 

Similar a Tutorial

Serial Port Device Driver
Serial Port Device DriverSerial Port Device Driver
Serial Port Device DriverEmblogic
 
Serial Communication In Atmega 16
Serial Communication In Atmega 16Serial Communication In Atmega 16
Serial Communication In Atmega 16Suren Kumar
 
UART Serial Communication Module Design and Simulation Based on VHDL
UART Serial Communication Module Design and Simulation Based on VHDLUART Serial Communication Module Design and Simulation Based on VHDL
UART Serial Communication Module Design and Simulation Based on VHDLIJERA Editor
 
Implementation of Universal Asynchronous Receiver and Transmitter
Implementation of Universal Asynchronous Receiver and TransmitterImplementation of Universal Asynchronous Receiver and Transmitter
Implementation of Universal Asynchronous Receiver and TransmitterIJERA Editor
 
Firmware implementation of UART using Bare metal programming
Firmware implementation of UART using Bare metal programmingFirmware implementation of UART using Bare metal programming
Firmware implementation of UART using Bare metal programmingIRJET Journal
 
AN INTRODUCTION TO SERIAL PORT INTERFACING
AN INTRODUCTION TO SERIAL PORT INTERFACINGAN INTRODUCTION TO SERIAL PORT INTERFACING
AN INTRODUCTION TO SERIAL PORT INTERFACINGTotal Project Solutions
 
Universal Asynchronous Receive and transmit IP core
Universal Asynchronous Receive and transmit IP coreUniversal Asynchronous Receive and transmit IP core
Universal Asynchronous Receive and transmit IP coreAneesh Raveendran
 
Data Encoding for Wireless Transmission
Data Encoding for Wireless TransmissionData Encoding for Wireless Transmission
Data Encoding for Wireless TransmissionSean McQuay
 
Unit 3 devices&buses
Unit 3 devices&busesUnit 3 devices&buses
Unit 3 devices&busesPavithra S
 
Serial Communication Interface with Error Detection
Serial Communication Interface with Error DetectionSerial Communication Interface with Error Detection
Serial Communication Interface with Error Detectioniosrjce
 
Synthesis & FPGA Implementation of UART IP Soft Core
Synthesis & FPGA Implementation of UART IP Soft CoreSynthesis & FPGA Implementation of UART IP Soft Core
Synthesis & FPGA Implementation of UART IP Soft Coreijsrd.com
 
EXIDE PPT TEMPLATE.pptx
EXIDE PPT TEMPLATE.pptxEXIDE PPT TEMPLATE.pptx
EXIDE PPT TEMPLATE.pptxNaveenK365392
 
Lecture 10 (serial communication)
Lecture 10 (serial communication)Lecture 10 (serial communication)
Lecture 10 (serial communication)cairo university
 
Universal Serial Communication Interface
Universal Serial Communication InterfaceUniversal Serial Communication Interface
Universal Serial Communication InterfaceSandesh Agrawal
 
Embedded Communications Protocols UNIT 3PDF.pdf
Embedded Communications Protocols UNIT 3PDF.pdfEmbedded Communications Protocols UNIT 3PDF.pdf
Embedded Communications Protocols UNIT 3PDF.pdfkanyaakiran
 

Similar a Tutorial (20)

Serial Port Device Driver
Serial Port Device DriverSerial Port Device Driver
Serial Port Device Driver
 
Serial Communication In Atmega 16
Serial Communication In Atmega 16Serial Communication In Atmega 16
Serial Communication In Atmega 16
 
UART Serial Communication Module Design and Simulation Based on VHDL
UART Serial Communication Module Design and Simulation Based on VHDLUART Serial Communication Module Design and Simulation Based on VHDL
UART Serial Communication Module Design and Simulation Based on VHDL
 
Implementation of Universal Asynchronous Receiver and Transmitter
Implementation of Universal Asynchronous Receiver and TransmitterImplementation of Universal Asynchronous Receiver and Transmitter
Implementation of Universal Asynchronous Receiver and Transmitter
 
Firmware implementation of UART using Bare metal programming
Firmware implementation of UART using Bare metal programmingFirmware implementation of UART using Bare metal programming
Firmware implementation of UART using Bare metal programming
 
AN INTRODUCTION TO SERIAL PORT INTERFACING
AN INTRODUCTION TO SERIAL PORT INTERFACINGAN INTRODUCTION TO SERIAL PORT INTERFACING
AN INTRODUCTION TO SERIAL PORT INTERFACING
 
Universal Asynchronous Receive and transmit IP core
Universal Asynchronous Receive and transmit IP coreUniversal Asynchronous Receive and transmit IP core
Universal Asynchronous Receive and transmit IP core
 
Uart wiki
Uart wikiUart wiki
Uart wiki
 
Data Encoding for Wireless Transmission
Data Encoding for Wireless TransmissionData Encoding for Wireless Transmission
Data Encoding for Wireless Transmission
 
USART
USARTUSART
USART
 
Unit 3 devices&buses
Unit 3 devices&busesUnit 3 devices&buses
Unit 3 devices&buses
 
Serial Communication Interface with Error Detection
Serial Communication Interface with Error DetectionSerial Communication Interface with Error Detection
Serial Communication Interface with Error Detection
 
M010617376
M010617376M010617376
M010617376
 
Lecture 10 _serial_communication
Lecture 10 _serial_communicationLecture 10 _serial_communication
Lecture 10 _serial_communication
 
Synthesis & FPGA Implementation of UART IP Soft Core
Synthesis & FPGA Implementation of UART IP Soft CoreSynthesis & FPGA Implementation of UART IP Soft Core
Synthesis & FPGA Implementation of UART IP Soft Core
 
EXIDE PPT TEMPLATE.pptx
EXIDE PPT TEMPLATE.pptxEXIDE PPT TEMPLATE.pptx
EXIDE PPT TEMPLATE.pptx
 
Lecture 10 (serial communication)
Lecture 10 (serial communication)Lecture 10 (serial communication)
Lecture 10 (serial communication)
 
Universal Serial Communication Interface
Universal Serial Communication InterfaceUniversal Serial Communication Interface
Universal Serial Communication Interface
 
Embedded Communications Protocols UNIT 3PDF.pdf
Embedded Communications Protocols UNIT 3PDF.pdfEmbedded Communications Protocols UNIT 3PDF.pdf
Embedded Communications Protocols UNIT 3PDF.pdf
 
8251 USART
8251 USART8251 USART
8251 USART
 

Último

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 

Último (20)

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

Tutorial

  • 1. E l e c t r o n i c s E n g g S o c i e t y Page 1 Interfacing Micro-controller with PC Electronics Engineering Society IT-BHU
  • 2. E l e c t r o n i c s E n g g S o c i e t y Page 2 Contents Introduction PC – Serial Port RS-232 Protocol Theory of Operation Setting UART in micro-controller Hyper Terminal
  • 3. E l e c t r o n i c s E n g g S o c i e t y Page 3 Introduction: There are many ways to interface your microcontroller to computer. The easiest way is to useUART i.e. Universal Asynchronous Receiver Transmitter.It is a way of communication between the microcontroller and the computer system or another microcontroller. Data exchange can be done using serial or parallel techniques. In parallel communication, the complete byte of data is sent at one time with each bit having a separated dedicated data line. This method is very fast but not cost effective. On the other hand serial communication is somewhat slower as every bit of data is sent serially one by one but is cost effective as only two data lines i.e. transmitter and receiver lines are required (of course a ground line is also required in addition to these two). Serial data communication can be further divided into two categories - synchronous and asynchronous. In synchronous communication transmitter and receiver are synchronised by a clock whereas in asynchronous system no clock pulse is shared between receiver and transmitter. As the name suggests UART is an example of asynchronous communication. Since no common clock is shared, a known data transfer rate (baud rate) must be agreed upon prior to data transmission i.e. the receiving UART needs to know the transmitting UART’s baud rate (and conversely the transmitter needs to know the receiver’s baud rate). Interfacing ATMEGA-16 with PC
  • 4. E l e c t r o n i c s E n g g S o c i e t y Page 4 Serial Communication in PC – The Serial Port: Figure 1.1: Serial Port of a computer We will be using Serial Port for communication between the microcontroller and the computer. A serial port has 9 pins as shown. If you have a laptop, then most probably there won’t be a serial port. Then you can use a USB to serial Converter. If you have to transmit one byte of data, the serial port will transmit 8 bits as one bit at a time. The advantage is that a serial port needs only one wire to transmit the 8 bits.
  • 5. E l e c t r o n i c s E n g g S o c i e t y Page 5 RS-232 Protocol: The standard used for serial communication is RS-232 (Recommended Standard 232). The standard defines voltage levels that correspond to logical zero and logical one level. Voltages between plus and minus 3 to 15 volts are allowed voltages.Logic one is defined as a negative voltage; the signal condition is called marking, and has the functional significance of OFF. Logic zero is positive; the signal condition is spacing, and has the function ON.Voltage between plus or minus 3 volts near zero are not allowed. This is not the voltage level at which our microcontroller works. We have two different machines with two different ways to define 0 & 1 and we want to exchange information between them. Consider microcontroller as a French and Computer's Serial Port as an Indian person (obviously no common language in between!). If they want to exchange information they basically need a mediator who knows both the language. In other words, we need a device which can convert serial port’s voltage level to that of CMOS( i.e. logic 1 = +5V and logic 0 = 0V). This task is carried out by an IC MAX 232, which is always used with four 10uF capacitors. The circuit is shown:
  • 6. E l e c t r o n i c s E n g g S o c i e t y Page 6 Figure 1.2: MAX 232 circuit Theory of Operation: Figure 1.3illustrates a basic UART data packet. While no data is being transmitted,logic 1 must be placed in the Tx line. A data packet is composed of 1 start bit, which is always a logic 0, followed by a programmable number of data bits (typically between 6 to 8), an optional parity bit, and a programmable number of stop bits (typically 1). The stop bit must always be logic 1. Most UART uses 8bits for data, no parity and 1 stop bit. Thus, it takes 10 bits to transmit a byte of data.
  • 7. E l e c t r o n i c s E n g g S o c i e t y Page 7 Figure 1.3: Basic UART Frame Format BAUD Rate: This parameter specifies the desired baud rate (bits per second) of the UART. Most typical standard baud rates are: 300, 1200, 2400, 9600, 19200, etc. However, any baud rate can be used. This parameter affects both the receiver and the transmitter. The default is 2400 (bauds). In the UART protocol, the transmitter and the receiver do not share a clock signal. That is, a clock signal does not emanate from one UART transmitter to the other UART receiver. Due to this reason the protocol is said to be asynchronous. Since no common clock is shared, a known data transfer rate (baud rate) must be agreed upon prior to data transmission. That is, the receiving UART needs to know the transmitting UART’s baud rate (and conversely the transmitter needs to know the receiver’s baud rate, if any). In almost all cases the receiving and transmitting baud rates are the same. The transmitter shifts out the data starting with the LSB first. Once the baud rate has been established (prior to initial communication), both the transmitter and the receiver’s internal clock is set to the same frequency (though not the same phase). The receiver "synchronizes" its
  • 8. E l e c t r o n i c s E n g g S o c i e t y Page 8 internal clock to that of the transmitter’s at the beginning of every data packet received. This allows the receiver to sample the data bit at the bit- cell centre. A key concept in UART design is that UART’s internal clock runs at much faster rate than the baud rate. For example, the popular 16450 UART controller runs its internal clock at 16 times the baud rate. This allows the UART receiver to sample the incoming data with granularity of 1/16 the baud-rate period. This "oversampling" is critical since the receiver adds about 2 clock-ticks in the input data synchronizer uncertainty. The incoming data is not sampled directly by the receiver, but goes through a synchronizer which translates the clock domain from the transmitter’s to that of the receiver. Additionally, the greater the granularity, the receiver has greater immunity with the baud rate error. The receiver detects the start bit by detecting the transition from logic 1 to logic 0 (note that while the data line is idle, the logic level is high). In the case of 16450 UART, once the start-bit is detected, the next data bit’s "centre" can be assured to be 24 ticks minus 2 (worse case synchronizer uncertainty) later. From then on, every next data bit centre is 16 clock ticks later. Figure 2 illustrates this point. Once the start bit is detected, the subsequent data bits are assembled in a de-serializer. Error condition maybe generated if the parity/stop bits are incorrect or missing.
  • 9. E l e c t r o n i c s E n g g S o c i e t y Page 9 Figure 1.3: Data sampling points by the UART Receiver Using UART in microcontroller: The USART has to be initialized before any communication can take place. The initialization process normally consists of setting the baud rate, setting frame format and enabling theTransmitter or the Receiver depending on the usage.Setting these in ATMEGA16 requires knowledge about USART registers (UCSR, UBRR and UDR) and their programming. Here our CV-AVR code wizard comes to our help. It generates codes for initialising USART in ATMEGA16 automatically! So you need not mess with the AVR Registers. All you have to do is to click some check-boxes and the code wizard will generate all the initialisation codes.
  • 10. E l e c t r o n i c s E n g g S o c i e t y Page 10 Using CV-AVR Code Wizard: Create a new project in CV-AVR as usual using code wizard and click on USART tab.Now depending upon your requirement, you can either check receiver, transmitter or both. You get a list of options to select from for the baud rate. Baud Rate is the unit of data transfer, defined as bits per second. We will select 9600 as it is fair enough for our purpose, and default setting in most of the applications (like Matlab, Docklight, etc.). Keep the communication parameters as default, i.e., 8 data, 1 stop and no parity and mode asynchronous. You also have option of enabling Rx and Tx Interrupt functions. Enabling them will
  • 11. E l e c t r o n i c s E n g g S o c i e t y Page 11 generate an interrupt on reception and transmission completion. But as we don’t need an interrupt at this point we will not enable interrupts here. Once you generate and save the code, all the register values are set by CVAVR and you only need to know some of the C functions to transfer data. Some of them are: 1.putchar: Sends one character to the buffer that can be received by receiving device.e.g. putchar(‘a’); //sends character a to the buffer putchar(‘F’); //sends character F to the buffer 2. getchar: To receive one character from the buffer, which might have been sent by the other uC or the computer. E.g., if we have already defined a variable char c, then c = getchar();// receives the character from buffer and save it in variable c Similarly, there are functions like puts() and gets() that work on string in similar fashion. Hyper-Terminal: To communicate with the computer, you need a terminal where you can send data through keyboard and the received data can be displayed on the screen. There are many softwares which provide such terminal, but we will be using Hyper-terminal. Its evaluation version is free for download on internet, which is sufficient for our purpose. You can download the evaluation version of hyper-terminal from http://www.hilgraeve.com/htpe/support/htpe7.exe
  • 12. E l e c t r o n i c s E n g g S o c i e t y Page 12 To use hyper-terminal, just click on its icon from programs folder in your start menu. In the new connection dialog box that appears, enter a name for your connection and click OK. Figure 1.4 In the next dialog box enter the com port on which your usb to serial connector is working and click OK. To find out the COM port on which your serial connector is working, check the Device Manager in System Properties. Note: The COM port changes every time you plug-in the connector.
  • 13. E l e c t r o n i c s E n g g S o c i e t y Page 13 Figure 1.5 In the dialog box that appears enter the values for baud rate, character size of uart data frame, parity bits, number of stop bits and flow control. These values should be same as that you have configured in your microcontroller. However, most of the systems use 9600 baud-rate, 8 data bits and no parity. If you are also using this configuration, click RESTORE DEFAULT button.
  • 14. E l e c t r o n i c s E n g g S o c i e t y Page 14 Figure 1.6 Click on OK and you are ready to send and receive data over serial port. Type anything on the keyboard and it will be transmitted over uart. Anything received over UART will appear on the screen.
  • 15. E l e c t r o n i c s E n g g S o c i e t y Page 15 Figure 1.7 If you have any suggestion that you would like to share with us feel free to contact at: akash.singh.ece10@itbhu.ac.in Akash Singh Electronics Engg. IT BHU