SlideShare a Scribd company logo
1 of 25
Download to read offline
CSE 477 Serial Communication 1
Serial Communication
❚ RS-232 (standard serial line)
❙ Point-to-point, full-duplex
❙ Synchronous or asynchronous
❙ Flow control
❙ Variable baud (bit) rates
❙ Cheap connections (low-quality and few wires)
CSE 477 Serial Communication 2
start
bit
8 data
bits
parity
bit
stop
bit
Serial data format
❚ Variations: parity bit; 1, 1.5, or 2 stop bits
CSE 477 Serial Communication 3
all wires active low
"0" = -12v, "1" = 12v
special driver chips that
generate ±12v from 5v
RS-232 wires
❚ TxD – transmit data
❚ TxC – transmit clock
❚ RTS – request to send: Handshake
❚ CTS – clear to send : Handshake
❚ RxD – receive data
❚ RxC – receive clock
❚ DSR – data set ready: Handshake
❚ DTR – data terminal ready: Handshake
❚ Ground
CSE 477 Serial Communication 4
Transfer modes
❚ Synchronous
❙ clock signal wire is used by both receiver and sender to sample data
❚ Asynchronous
❙ no clock signal in common
❙ data must be oversampled (16x is typical) to find bit boundaries
❚ Flow control
❙ handshaking signals to control rate of transfer
CLK
CSE 477 Serial Communication 5
baud rate
generator
terminal
RxD
TxD
RxC
TxC
baud rate
generator
async
modem
RxD
TxD
DSR
DTR
CTS
RTS
RxC
TxC
phone line
interface
phone
line
sync
modem
RxD
TxD
DSR
DTR
CTS
RTS
RxC
TxC
phone line
interface
phone
line
Typical connections
❚ Terminal
❚ Asynchronous modem
Synchronous modem
CSE 477 Serial Communication 6
8051 Serial Interface
❚ TxD: Port 3, pin 1
❙ Transmit data shifted out
❚ RxD: Port 3, pin 0
❙ Receive data shifted in
❚ Full duplex: both operate in parallel
❚ We will use Mode 1 only
❙ asynchronous
❙ 10 bit transfer: 1 start, 8 data, 1 stop
❙ Look at documentation for other modes
❚ Clock for serial shift provided by timer 1
❙ i.e. programmable baud rate
❙ takes away a timer from other uses
CSE 477 Serial Communication 7
Serial Port Control Register (SCON)
❚ Configures the serial interface
CSE 477 Serial Communication 8
Baud Rate Generator
❚ Use timer 1 overflow to generate serial data clock
❙ serial clock is 16x oversampled, i.e. baud rate x16
❙ SMOD bit (PCON register)
❘ 0: divides baud rate by 2
❚ Typical timer 1 setup
❙ auto-reload timer
❙ reload value determines overflow clock rate
❚ Baud rate calculation
❙ Clocks between overflows = clocks
❙ Overflow frequency =
❙ Baud rate (assuming SMOD = 1)
❙ Baud rate =
❙ Max Baud rate =
❙ TH1 value for 9600 baud =
CSE 477 Serial Communication 9
8051 Serial Interface Transmitter
CSE 477 Serial Communication 10
Sending Serial Data
❚ Transmission is initiated by a write to SBUF
❙ start, data and stop bits shifted out automatically
❙ TI (transmit interrupt) set when stop bit goes
❘ indicates that interface is ready for next character
❘ TI can be polled, or used to interrupt
❘ must reset it in the software
CSE 477 Serial Communication 11
8051 Serial Receiver Interface
CSE 477 Serial Communication 12
Receiving Serial Data
❚ Reception is initiated by a 1-0 transition - a start bit
❙ data is sampled and shifted in automatically
❙ on the stop bit, the 8 data bits are loaded into SBUF
❘ same address, but different register and sending SBUF
❙ RI (receive interrupt) set when SBUF is loaded
❘ indicates a character is ready
• next character can start entering before SBUF is read
• must read SBUF before next character arrives
❘ RI can be polled, or used to interrupt
❘ must be reset in the software
CSE 477 Serial Communication 13
Serial Interface Interrupts
❚ RI and TI share the same interrupt
❙ Interrupt #4
❚ Interrupt routine must look at RI and TI to see which caused
the interrupt
❚ Routine must reset RI or TI before returning
❙ If both RI and TI are on, another interrupt will happen right away
❙ Which bit do you check first?
CSE 477 Serial Communication 14
Baud Rate Generator
❚ Use timer 1 overflow to generate serial data clock
❙ serial clock is 16x oversampled, i.e. baud rate x16
❙ SMOD bit (PCON register)
❘ 0: divides baud rate by 2
❚ Typical timer 1 setup
❙ auto-reload timer
❙ reload value determines overflow clock rate
❚ Baud rate calculation
❙ Clocks between overflows = 12 x (256-TH1) clocks
❙ Overflow frequency = Fclk/Clocks-between-overflows
❙ Baud rate (assuming SMOD = 1)
❘ 1/16 x overflow-frequency
❙ Baud rate = 24MHz / (16 x 12 x (256-TH1))
❙ Max Baud rate = 125KHz
❙ TH1 value for 9600 baud = 13
CSE 477 Serial Communication 15
getchar() / putchar()
❚ c = getchar()
❙ returns the character in the buffer, if there is one
❙ returns NULL otherwise
❙ could check for error (character overrun)
❚ r = putchar(c)
❙ sends the character to the serial port, if it is not busy
❙ returns c for normal operation, NULL if port was busy
❚ Simple operation, no need for interrupts
while ((c = getchar) == NULL) { };
while (putchar(c) == NULL) { };
❚ Polling doesn’t allow us to do anything else
❚ If we are busy, we might miss a character
CSE 477 Serial Communication 16
getchar() / putchar() (Part 2)
❚ We’ll add a 1-character buffer for both input and output
❚ getchar()
❙ interrupt when a new character arrives
❙ if the buffer is empty, place character in buffer
❙ otherwise, set error flag (new function to check for errors)
❙ getchar() now looks at the buffer for a character
❙ otherwise the same as before
❚ putchar()
❙ interrupt when a character has been sent
❙ if the buffer has a character, send it to the serial port
❙ putchar() now puts the character into the buffer
❙ otherwise the same as before
❙ what if the buffer is empty when interrupt occurs?
❘ new character to buffer will not be sent
❚ Complication: one interrupt routine for both input and output
CSE 477 Serial Communication 17
getchar() / putchar() (Part 2)
Serial
Port
input
buffer
output
buffer
Main
program
getchar()
putchar()
Interrupt routine
Interrupt routine
Input
character
Output
character
CSE 477 Serial Communication 18
getchar() / putchar() (Part 3)
❚ The 1-character buffer gives us some time to read/write
❙ but not a lot
❚ Extend the 1-character buffers to 32 characters buffers
❙ now we can go away for a long time and not miss incoming characters
❙ we can write out lots of characters and not wait for them all to go
❚ Each buffer now becomes a queue
❙ standard circular queue
❘ 33 character vector (why 33?)
❘ head, tail pointers
❙ initialize on startup
❚ getchar()
❙ interrupt routine writes characters to buffer, getchar() reads
❚ putchar()
❙ putchar() writes characters to buffer, getchar() reads
CSE 477 Serial Communication 19
getchar() / putchar() (Part 3)
Serial
Port
input buffer
output buffer
Main
program
getchar()
putchar()
Interrupt routine
Interrupt routine
Input
character
Output
character
CSE 477 Serial Communication 20
+5v
device
1
device
2
device
n
SCL
SDA
Inter-Integrated Circuit Bus (I2C)
❚ Modular connections on a printed circuit board
❚ Multi-point connections (needs addressing)
❚ Synchronous transfer (but adapts to slowest device)
❚ Similar to Controller Area Network (CAN) protocol
used in automotive applications
CSE 477 Serial Communication 21
SDA
SCL
START STOP
Serial data format
❚ SDA going low while SCL high signals start of data
❚ SDA going high while SCL high signals end of data
❚ SDA can change when SCL low
❚ SCL high (after start and before end) signals that a data bit can
be read
CSE 477 Serial Communication 22
SDA
SCL
1 3 4 5 6 7 8 ack2
Byte transfer
❚ Byte followed by a 1 bit acknowledge from receiver
❚ Open-collector wires
❙ sender allows SDA to rise
❙ receiver pulls low to acknowledge after 8 bits
❚ Multi-byte transfers
❙ first byte contains address of receiver
❙ all devices check address to determine if following data is for them
❙ second byte usually contains address of sender
CSE 477 Serial Communication 23
clk 1
clk 2
SCL
Clock synchronization
❚ Synchronous data transfer with variable speed devices
❙ go as fast as the slowest device involved in transfer
❚ Each device looks at the SCL line as an input as well as driving it
❙ if clock stays low even when being driven high then another device
needs more time, so wait for it to finish before continuing
❙ rising clock edges are synchronized
CSE 477 Serial Communication 24
Arbitration
❚ Devices can start transmitting at any time
❙ wait until lines are both high for some minimum time
❙ multiple devices may start together - clocks will be synchronized
❚ All senders will think they are sending data
❙ possibly slowed down by receiver (or another sender)
❙ each sender keeps watching SDA - if ever different
(driving high, but its really low) then there is another driver
❙ sender that detects difference gets off the bus and aborts
message
❚ Device priority given to devices with
early 0s in their address
CSE 477 Serial Communication 25
Inter-Integrated Circuit Bus (I2C)
❚ Supports data transfers from 0 to 400KHz
❚ Philips (and others) provide many devices
❙ microcontrollers with built-in interface
❙ A/D and D/A converters
❙ parallel I/O ports
❙ memory modules
❙ LCD drivers
❙ real-time clock/calendars
❙ DTMF decoders
❙ frequency synthesizers
❙ video/audio processors

More Related Content

What's hot

Raspberry Pi - Lecture 3 Embedded Communication Protocols
Raspberry Pi - Lecture 3 Embedded Communication ProtocolsRaspberry Pi - Lecture 3 Embedded Communication Protocols
Raspberry Pi - Lecture 3 Embedded Communication ProtocolsMohamed Abdallah
 
Serial Communication
Serial CommunicationSerial Communication
Serial CommunicationUshaRani289
 
RIP (routing information protocol)
RIP (routing information protocol)RIP (routing information protocol)
RIP (routing information protocol)Netwax Lab
 
I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)Varun Mahajan
 
Micro c lab8(serial communication)
Micro c lab8(serial communication)Micro c lab8(serial communication)
Micro c lab8(serial communication)Mashood
 
CCNA ppt Day 5
CCNA ppt Day 5CCNA ppt Day 5
CCNA ppt Day 5VISHNU N
 
Sereial com. ppt
Sereial com. pptSereial com. ppt
Sereial com. pptgaurav5345
 
CCNA ppt Day 9
CCNA ppt Day 9CCNA ppt Day 9
CCNA ppt Day 9VISHNU N
 
EIGRP (enhanced interior gateway routing protocol)
EIGRP (enhanced interior gateway routing protocol)EIGRP (enhanced interior gateway routing protocol)
EIGRP (enhanced interior gateway routing protocol)Netwax Lab
 
Serial peripheral Interface - Embedded System Protocol
Serial peripheral Interface - Embedded System ProtocolSerial peripheral Interface - Embedded System Protocol
Serial peripheral Interface - Embedded System ProtocolAditya Porwal
 
SATA Introduction
SATA IntroductionSATA Introduction
SATA IntroductionGene Chang
 
Computer network (16)
Computer network (16)Computer network (16)
Computer network (16)NYversity
 

What's hot (20)

I2 c protocol
I2 c protocolI2 c protocol
I2 c protocol
 
Lpc2148 i2c
Lpc2148 i2cLpc2148 i2c
Lpc2148 i2c
 
Raspberry Pi - Lecture 3 Embedded Communication Protocols
Raspberry Pi - Lecture 3 Embedded Communication ProtocolsRaspberry Pi - Lecture 3 Embedded Communication Protocols
Raspberry Pi - Lecture 3 Embedded Communication Protocols
 
Serial Communication
Serial CommunicationSerial Communication
Serial Communication
 
RIP (routing information protocol)
RIP (routing information protocol)RIP (routing information protocol)
RIP (routing information protocol)
 
I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)I2C Bus (Inter-Integrated Circuit)
I2C Bus (Inter-Integrated Circuit)
 
Spi
SpiSpi
Spi
 
Micro c lab8(serial communication)
Micro c lab8(serial communication)Micro c lab8(serial communication)
Micro c lab8(serial communication)
 
I2C
I2CI2C
I2C
 
CCNA ppt Day 5
CCNA ppt Day 5CCNA ppt Day 5
CCNA ppt Day 5
 
Serial data transfer
Serial data transferSerial data transfer
Serial data transfer
 
SPI Bus Protocol
SPI Bus ProtocolSPI Bus Protocol
SPI Bus Protocol
 
Sereial com. ppt
Sereial com. pptSereial com. ppt
Sereial com. ppt
 
CCNA ppt Day 9
CCNA ppt Day 9CCNA ppt Day 9
CCNA ppt Day 9
 
EIGRP (enhanced interior gateway routing protocol)
EIGRP (enhanced interior gateway routing protocol)EIGRP (enhanced interior gateway routing protocol)
EIGRP (enhanced interior gateway routing protocol)
 
Serial peripheral Interface - Embedded System Protocol
Serial peripheral Interface - Embedded System ProtocolSerial peripheral Interface - Embedded System Protocol
Serial peripheral Interface - Embedded System Protocol
 
12 mt06ped019
12 mt06ped019 12 mt06ped019
12 mt06ped019
 
i2c
i2ci2c
i2c
 
SATA Introduction
SATA IntroductionSATA Introduction
SATA Introduction
 
Computer network (16)
Computer network (16)Computer network (16)
Computer network (16)
 

Similar to Microcontrollers iii

MicrocontrollersIII.ppt
MicrocontrollersIII.pptMicrocontrollersIII.ppt
MicrocontrollersIII.pptssuserfb92ae
 
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
 
Peripherals and interfacing
Peripherals  and interfacingPeripherals  and interfacing
Peripherals and interfacingRAMPRAKASHT1
 
One-Wire-Serial-Communication.pdf
One-Wire-Serial-Communication.pdfOne-Wire-Serial-Communication.pdf
One-Wire-Serial-Communication.pdfshamtekawambwa1
 
Unit 3 devices&buses
Unit 3 devices&busesUnit 3 devices&buses
Unit 3 devices&busesPavithra S
 
Lecture 10 (serial communication)
Lecture 10 (serial communication)Lecture 10 (serial communication)
Lecture 10 (serial communication)cairo university
 
The presentation is about USART and serial communication
The presentation is about USART and serial communicationThe presentation is about USART and serial communication
The presentation is about USART and serial communicationsinaankhalil
 
Serial Communication & Embedded System Interface
Serial Communication & Embedded System InterfaceSerial Communication & Embedded System Interface
Serial Communication & Embedded System InterfaceKUET
 
Serial Communication In Atmega 16
Serial Communication In Atmega 16Serial Communication In Atmega 16
Serial Communication In Atmega 16Suren Kumar
 

Similar to Microcontrollers iii (20)

MicrocontrollersIII.ppt
MicrocontrollersIII.pptMicrocontrollersIII.ppt
MicrocontrollersIII.ppt
 
MicrocontrollersIII (1).ppt
MicrocontrollersIII (1).pptMicrocontrollersIII (1).ppt
MicrocontrollersIII (1).ppt
 
MicrocontrollersIII.ppt
MicrocontrollersIII.pptMicrocontrollersIII.ppt
MicrocontrollersIII.ppt
 
AN INTRODUCTION TO SERIAL PORT INTERFACING
AN INTRODUCTION TO SERIAL PORT INTERFACINGAN INTRODUCTION TO SERIAL PORT INTERFACING
AN INTRODUCTION TO SERIAL PORT INTERFACING
 
ES UNIT3.pptx
ES UNIT3.pptxES UNIT3.pptx
ES UNIT3.pptx
 
Lecture 10 _serial_communication
Lecture 10 _serial_communicationLecture 10 _serial_communication
Lecture 10 _serial_communication
 
Pentium processor
Pentium processorPentium processor
Pentium processor
 
UART
UARTUART
UART
 
020419.pdf
020419.pdf020419.pdf
020419.pdf
 
Pci
PciPci
Pci
 
Peripherals and interfacing
Peripherals  and interfacingPeripherals  and interfacing
Peripherals and interfacing
 
One-Wire-Serial-Communication.pdf
One-Wire-Serial-Communication.pdfOne-Wire-Serial-Communication.pdf
One-Wire-Serial-Communication.pdf
 
Unit 3 devices&buses
Unit 3 devices&busesUnit 3 devices&buses
Unit 3 devices&buses
 
Lecture 10 (serial communication)
Lecture 10 (serial communication)Lecture 10 (serial communication)
Lecture 10 (serial communication)
 
The presentation is about USART and serial communication
The presentation is about USART and serial communicationThe presentation is about USART and serial communication
The presentation is about USART and serial communication
 
NAVEEN UART BATCH 43
NAVEEN UART BATCH 43NAVEEN UART BATCH 43
NAVEEN UART BATCH 43
 
lesson01.ppt
lesson01.pptlesson01.ppt
lesson01.ppt
 
Serial Communication & Embedded System Interface
Serial Communication & Embedded System InterfaceSerial Communication & Embedded System Interface
Serial Communication & Embedded System Interface
 
Serial Communication In Atmega 16
Serial Communication In Atmega 16Serial Communication In Atmega 16
Serial Communication In Atmega 16
 
Peripheral devices
Peripheral devicesPeripheral devices
Peripheral devices
 

Recently uploaded

On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 

Recently uploaded (20)

On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 

Microcontrollers iii

  • 1. CSE 477 Serial Communication 1 Serial Communication ❚ RS-232 (standard serial line) ❙ Point-to-point, full-duplex ❙ Synchronous or asynchronous ❙ Flow control ❙ Variable baud (bit) rates ❙ Cheap connections (low-quality and few wires)
  • 2. CSE 477 Serial Communication 2 start bit 8 data bits parity bit stop bit Serial data format ❚ Variations: parity bit; 1, 1.5, or 2 stop bits
  • 3. CSE 477 Serial Communication 3 all wires active low "0" = -12v, "1" = 12v special driver chips that generate ±12v from 5v RS-232 wires ❚ TxD – transmit data ❚ TxC – transmit clock ❚ RTS – request to send: Handshake ❚ CTS – clear to send : Handshake ❚ RxD – receive data ❚ RxC – receive clock ❚ DSR – data set ready: Handshake ❚ DTR – data terminal ready: Handshake ❚ Ground
  • 4. CSE 477 Serial Communication 4 Transfer modes ❚ Synchronous ❙ clock signal wire is used by both receiver and sender to sample data ❚ Asynchronous ❙ no clock signal in common ❙ data must be oversampled (16x is typical) to find bit boundaries ❚ Flow control ❙ handshaking signals to control rate of transfer CLK
  • 5. CSE 477 Serial Communication 5 baud rate generator terminal RxD TxD RxC TxC baud rate generator async modem RxD TxD DSR DTR CTS RTS RxC TxC phone line interface phone line sync modem RxD TxD DSR DTR CTS RTS RxC TxC phone line interface phone line Typical connections ❚ Terminal ❚ Asynchronous modem Synchronous modem
  • 6. CSE 477 Serial Communication 6 8051 Serial Interface ❚ TxD: Port 3, pin 1 ❙ Transmit data shifted out ❚ RxD: Port 3, pin 0 ❙ Receive data shifted in ❚ Full duplex: both operate in parallel ❚ We will use Mode 1 only ❙ asynchronous ❙ 10 bit transfer: 1 start, 8 data, 1 stop ❙ Look at documentation for other modes ❚ Clock for serial shift provided by timer 1 ❙ i.e. programmable baud rate ❙ takes away a timer from other uses
  • 7. CSE 477 Serial Communication 7 Serial Port Control Register (SCON) ❚ Configures the serial interface
  • 8. CSE 477 Serial Communication 8 Baud Rate Generator ❚ Use timer 1 overflow to generate serial data clock ❙ serial clock is 16x oversampled, i.e. baud rate x16 ❙ SMOD bit (PCON register) ❘ 0: divides baud rate by 2 ❚ Typical timer 1 setup ❙ auto-reload timer ❙ reload value determines overflow clock rate ❚ Baud rate calculation ❙ Clocks between overflows = clocks ❙ Overflow frequency = ❙ Baud rate (assuming SMOD = 1) ❙ Baud rate = ❙ Max Baud rate = ❙ TH1 value for 9600 baud =
  • 9. CSE 477 Serial Communication 9 8051 Serial Interface Transmitter
  • 10. CSE 477 Serial Communication 10 Sending Serial Data ❚ Transmission is initiated by a write to SBUF ❙ start, data and stop bits shifted out automatically ❙ TI (transmit interrupt) set when stop bit goes ❘ indicates that interface is ready for next character ❘ TI can be polled, or used to interrupt ❘ must reset it in the software
  • 11. CSE 477 Serial Communication 11 8051 Serial Receiver Interface
  • 12. CSE 477 Serial Communication 12 Receiving Serial Data ❚ Reception is initiated by a 1-0 transition - a start bit ❙ data is sampled and shifted in automatically ❙ on the stop bit, the 8 data bits are loaded into SBUF ❘ same address, but different register and sending SBUF ❙ RI (receive interrupt) set when SBUF is loaded ❘ indicates a character is ready • next character can start entering before SBUF is read • must read SBUF before next character arrives ❘ RI can be polled, or used to interrupt ❘ must be reset in the software
  • 13. CSE 477 Serial Communication 13 Serial Interface Interrupts ❚ RI and TI share the same interrupt ❙ Interrupt #4 ❚ Interrupt routine must look at RI and TI to see which caused the interrupt ❚ Routine must reset RI or TI before returning ❙ If both RI and TI are on, another interrupt will happen right away ❙ Which bit do you check first?
  • 14. CSE 477 Serial Communication 14 Baud Rate Generator ❚ Use timer 1 overflow to generate serial data clock ❙ serial clock is 16x oversampled, i.e. baud rate x16 ❙ SMOD bit (PCON register) ❘ 0: divides baud rate by 2 ❚ Typical timer 1 setup ❙ auto-reload timer ❙ reload value determines overflow clock rate ❚ Baud rate calculation ❙ Clocks between overflows = 12 x (256-TH1) clocks ❙ Overflow frequency = Fclk/Clocks-between-overflows ❙ Baud rate (assuming SMOD = 1) ❘ 1/16 x overflow-frequency ❙ Baud rate = 24MHz / (16 x 12 x (256-TH1)) ❙ Max Baud rate = 125KHz ❙ TH1 value for 9600 baud = 13
  • 15. CSE 477 Serial Communication 15 getchar() / putchar() ❚ c = getchar() ❙ returns the character in the buffer, if there is one ❙ returns NULL otherwise ❙ could check for error (character overrun) ❚ r = putchar(c) ❙ sends the character to the serial port, if it is not busy ❙ returns c for normal operation, NULL if port was busy ❚ Simple operation, no need for interrupts while ((c = getchar) == NULL) { }; while (putchar(c) == NULL) { }; ❚ Polling doesn’t allow us to do anything else ❚ If we are busy, we might miss a character
  • 16. CSE 477 Serial Communication 16 getchar() / putchar() (Part 2) ❚ We’ll add a 1-character buffer for both input and output ❚ getchar() ❙ interrupt when a new character arrives ❙ if the buffer is empty, place character in buffer ❙ otherwise, set error flag (new function to check for errors) ❙ getchar() now looks at the buffer for a character ❙ otherwise the same as before ❚ putchar() ❙ interrupt when a character has been sent ❙ if the buffer has a character, send it to the serial port ❙ putchar() now puts the character into the buffer ❙ otherwise the same as before ❙ what if the buffer is empty when interrupt occurs? ❘ new character to buffer will not be sent ❚ Complication: one interrupt routine for both input and output
  • 17. CSE 477 Serial Communication 17 getchar() / putchar() (Part 2) Serial Port input buffer output buffer Main program getchar() putchar() Interrupt routine Interrupt routine Input character Output character
  • 18. CSE 477 Serial Communication 18 getchar() / putchar() (Part 3) ❚ The 1-character buffer gives us some time to read/write ❙ but not a lot ❚ Extend the 1-character buffers to 32 characters buffers ❙ now we can go away for a long time and not miss incoming characters ❙ we can write out lots of characters and not wait for them all to go ❚ Each buffer now becomes a queue ❙ standard circular queue ❘ 33 character vector (why 33?) ❘ head, tail pointers ❙ initialize on startup ❚ getchar() ❙ interrupt routine writes characters to buffer, getchar() reads ❚ putchar() ❙ putchar() writes characters to buffer, getchar() reads
  • 19. CSE 477 Serial Communication 19 getchar() / putchar() (Part 3) Serial Port input buffer output buffer Main program getchar() putchar() Interrupt routine Interrupt routine Input character Output character
  • 20. CSE 477 Serial Communication 20 +5v device 1 device 2 device n SCL SDA Inter-Integrated Circuit Bus (I2C) ❚ Modular connections on a printed circuit board ❚ Multi-point connections (needs addressing) ❚ Synchronous transfer (but adapts to slowest device) ❚ Similar to Controller Area Network (CAN) protocol used in automotive applications
  • 21. CSE 477 Serial Communication 21 SDA SCL START STOP Serial data format ❚ SDA going low while SCL high signals start of data ❚ SDA going high while SCL high signals end of data ❚ SDA can change when SCL low ❚ SCL high (after start and before end) signals that a data bit can be read
  • 22. CSE 477 Serial Communication 22 SDA SCL 1 3 4 5 6 7 8 ack2 Byte transfer ❚ Byte followed by a 1 bit acknowledge from receiver ❚ Open-collector wires ❙ sender allows SDA to rise ❙ receiver pulls low to acknowledge after 8 bits ❚ Multi-byte transfers ❙ first byte contains address of receiver ❙ all devices check address to determine if following data is for them ❙ second byte usually contains address of sender
  • 23. CSE 477 Serial Communication 23 clk 1 clk 2 SCL Clock synchronization ❚ Synchronous data transfer with variable speed devices ❙ go as fast as the slowest device involved in transfer ❚ Each device looks at the SCL line as an input as well as driving it ❙ if clock stays low even when being driven high then another device needs more time, so wait for it to finish before continuing ❙ rising clock edges are synchronized
  • 24. CSE 477 Serial Communication 24 Arbitration ❚ Devices can start transmitting at any time ❙ wait until lines are both high for some minimum time ❙ multiple devices may start together - clocks will be synchronized ❚ All senders will think they are sending data ❙ possibly slowed down by receiver (or another sender) ❙ each sender keeps watching SDA - if ever different (driving high, but its really low) then there is another driver ❙ sender that detects difference gets off the bus and aborts message ❚ Device priority given to devices with early 0s in their address
  • 25. CSE 477 Serial Communication 25 Inter-Integrated Circuit Bus (I2C) ❚ Supports data transfers from 0 to 400KHz ❚ Philips (and others) provide many devices ❙ microcontrollers with built-in interface ❙ A/D and D/A converters ❙ parallel I/O ports ❙ memory modules ❙ LCD drivers ❙ real-time clock/calendars ❙ DTMF decoders ❙ frequency synthesizers ❙ video/audio processors