I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf ·...
Transcript of I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf ·...
![Page 1: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/1.jpg)
1
I/O Interfacing Standards
for External Devices
![Page 2: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/2.jpg)
2
Common Digital I/O Interfacing
Standards for External Devices
•Serial Port
•PS/2
•SPI, SCI, SI, and SDIO
•I2C
•Audio AC97
•USB
•Firewire
•GPIO
•PWM
•CAN bus
![Page 3: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/3.jpg)
3
Serial communication
• Can support high speed communication
• Support Synchronous, Asynchronous, and
Iso-synchronous
![Page 4: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/4.jpg)
4
General Purpose Input/Output
(GPIO)
• Sometimes it is called bus expander
• GPIO is an interface available on
microcontrollers/microprocessors
• It can act as input or output
• GPIO often are arranged into group of 8
pins
• GPIO port is often individually configurable
![Page 5: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/5.jpg)
5
GPIO interface
![Page 6: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/6.jpg)
6
GPIO Advantage
• Lower power about 1 A
• Can fit in small package
• Lower Cost
• Faster time to market
![Page 7: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/7.jpg)
Pull-up Pull-down resistors
• Makes the circuitry susceptible to noise
• Without the input, the logic state is
unknown
• Pull-up resistor pulls the terminal to the
voltage supply
• Pull-down resistor pulls the terminal to the
ground
7
![Page 8: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/8.jpg)
Pull-up resistors
8
![Page 9: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/9.jpg)
Input example
9
Pull-Up
Pull-Down
![Page 10: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/10.jpg)
Raspberry Pi
• Provide Pull-up resistors inside the board
10
![Page 11: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/11.jpg)
Pin naming
• Board mode/BCM mode
11
![Page 12: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/12.jpg)
LED Light up
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT)
Print "All Set in Python! Let's Blink“
for i in range(1,10):
GPIO.output(17,GPIO.HIGH)
sleep(1)
GPIO.output(17,GPIO.LOW)
sleep(0.5)
GPIO.cleanup()
12
![Page 13: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/13.jpg)
13
RS232C
• RS232C communication is between Data
Terminal Equipment (DTE) e.g. computer
and Data Communication Equipment
(DCE) e.g. modem
• RS232C (Recommend Standard for
Number 232C) specify communication
standard such as voltage level, terminating
resistances, cable length etc.
![Page 14: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/14.jpg)
14
RS232C port connection
![Page 15: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/15.jpg)
15
RS-232 Serial Interface
• Transmit and Receive data lines
• No clock signal exchanged – Sender and
receiver need to have same baud rate
• Baud rate is the clock rate of the bits
• Normal Bits: Start, 8 Data, Stop
• Voltage levels: a 0 is >3V and a 1 is <-3V
• Special RS232 voltage level converter
chips are typically used in interface
![Page 16: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/16.jpg)
16
RS-232 standard
• Data rate from 20 kbps to over 1 Mbps
• Range up to 50 feet maximum
• It is robust interface up to 115,200 baud rate (pulse per second)
• Voltage as high/low as 15 Volt
• Single-ended means communication is over a single wire reference to ground
• There are 9 pins (DB-9) and 25 pins format (DB-25)
![Page 17: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/17.jpg)
17
RS-232 signal
1
0
![Page 18: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/18.jpg)
18
RS-232 single ended uni-direction
![Page 19: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/19.jpg)
19
RS-232 (DB9) male connector
Pin 1: Carrier Detect (CD)
Pin 2: Receive Data (RD)
Pin 3: Transmit Data (TD)
Pin 4: Data Terminal Ready (DTR)
Pin 5: Ground (GND)
Pin 6: Data Set Ready (DSR)
Pin 7: Request to Send (RTS)
Pin 8: Clear to Send (CTS)
Pin 9: Ring Indicator (RI)
![Page 20: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/20.jpg)
20
Connect computer-modem
![Page 21: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/21.jpg)
21
From DTE-DCE
![Page 22: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/22.jpg)
22
Connect two PC directly
![Page 23: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/23.jpg)
23
RS232 Handshaking
Assume modem wants to send data to PC
• RI indicate data available
• When modem connects, modem will send DCD signal at time t0
• Modem will send DSR signal at time t1 when it receive data to send
• PC will response with DTR at time t2
• Modem will send RTS at time t3
• PC response with CTS at time t4
RTS and CTS can also be sent again during the transaction
![Page 24: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/24.jpg)
24
UART
• UART is the name for the hardware used
for a RS-232 Serial Interface
• UART – Universal Asynchronous Receiver
Transmitter
• Early PCs had a UART chip, but this
functionality is now found inside a larger
chip that also contains other I/O features
![Page 25: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/25.jpg)
25
UART transmission
![Page 26: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/26.jpg)
26
UART initial communication
• Need to know how fast the data bits are coming
• Need to know where the starts bit begins
• Then, we know when to sample
![Page 27: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/27.jpg)
27
UART communication
• Non-return to zero. In the idle state, the logic state is 1.
• Start bit: transition to 0
• Data bit consists of start bit, 8 bit data, P-bit and stop bit
• Data bits can be changed to 5,6,7, and 8 bits
• The stop bit can be for a minimum of 1.5T, 2T instead of T, when T is normal interval
• P bit can be priority or for other purpose
• Stop bit: transition to 1
![Page 28: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/28.jpg)
28
RS-232C Serial interface
transmission of an 8-bit data value
0 0 0 0 1 0 1 0
Start
Bit
0 1 2 3 4 5 6 7 Stop
BitData Bit number
Mark (1)
Space (0)
0x50 = ASCII “P”
LSB MSB
![Page 29: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/29.jpg)
29
UART output 8 bits in 10T
![Page 30: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/30.jpg)
30
UART output 7 bits in 9T
![Page 31: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/31.jpg)
31
UART output 6 bits in 8T
![Page 32: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/32.jpg)
32
UART output 8 bit in 11T
![Page 33: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/33.jpg)
Raspberry Pi UART
• Since we use 0 and 3.3 V logic levels in Pi
(not the +/-12 V used by RS-232), we
need a 3.3 V to RS-232 level converter.
• Another option is to use USB to RS-232
converter
33
![Page 34: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/34.jpg)
Rapberry Pi Setup
• Default configurationSpeed (baud rate): 115200
Bits: 8
Parity: None
Stop Bits: 1
Flow Control: None
• Checking the serial portls –l /dev/ttyS0, /dev/ttyS1
Or
ls –l /dev/ttyUSB0, /dev/ttyUSB1
34
![Page 35: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/35.jpg)
Python Installation
• Install Python Serial Port
35
sudo apt-get install python-serial
![Page 36: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/36.jpg)
Serial Port Programming
36
![Page 37: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/37.jpg)
Run the program
• To run the program
python serialtest.py
• Output
37
![Page 38: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/38.jpg)
Read Data from Serial Port
• Example of the Program
38
![Page 39: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/39.jpg)
39
Keyboard interface to serial
interface to Microcontroller
![Page 40: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/40.jpg)
40
Keyboard interface
• KBINT is an interrupt from keyboard controller
• TxD is serial UART data output
• Bounce creates on pressing
– Each bounce creates a false pulse
• Scan clock generates clock to keep checking key press for each interval
• Encoder is used to encode keyboard output
![Page 41: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/41.jpg)
41
Personal System 2 (PS/2) Interface
• IBM standard from an early PC
• Used in low-cost keyboards and mice
• Two signal lines: clock & data
• Keyboard sends key scan codes
• Mouse sends 3 byte data packets
• 11bits sent: Start, 8 Data, Parity, Stop
• Can also send commands to Mouse and Keyboard
• Uses Open Collector TTL bus signals– 1 Pull-up resistor
– Device can only force signal low
• Small microcontroller used in a PS/2 device
![Page 42: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/42.jpg)
42
PS/2 Keyboard Transmission of a
Keyboard Scan Code
PS/2 Clock
PS/2 Data
Start 0 1 1 0 1 0 0 0 Parity Stop Bit Data Bits (low to high) Bit Bit
Scan code 16H for “1” key
![Page 43: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/43.jpg)
43
Serial Peripheral Interface (SPI)
• Developed by Motorola in the 1980s
• Works like a shift register for input and output
• 4 signals: clock, shift-in, shift-out, and chip enable
• Chip enable turns on a tri-state driver on each slave devices shift-out pin
• Two setup modes: one large shift register with chip enables all connected or independent shift registers each with a chip enable
• Common in A/D and D/A chips
![Page 44: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/44.jpg)
44
Shift register
Data 0P1
BufferWrite Data
07 …
Shift clock TxD
startstop
![Page 45: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/45.jpg)
45
SPI
• Full duplex synchronous communication
• Four signals are used : SS’, MISO,MOSI, SCLK
• SS’ signal is used to decide whether this device
is slave or not (0 is slave)
• SPI device clock rates can range from 30 kHz to
3 MHz
![Page 46: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/46.jpg)
46
SPI signals
![Page 47: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/47.jpg)
47
SPI connection
![Page 48: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/48.jpg)
48
The two SPI slave device
configuration options.
Master
CS0
CS1
CS2
SCLK
SDO
SDI
Slave
Slave
Slave
SDI SDO
SDI
SDO
SDI
SDO
Master
CS0
CS1
CS2
SCLK
SDO
SDI
Slave 0
Slave 1
Slave 2
SDI SDO
SDO
SDO
SDI
SDI
![Page 49: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/49.jpg)
49
SPI programming
• Program clock rate
• Program master or slave devices
• Program negative/positive edge value
![Page 50: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/50.jpg)
50
Serial Connect Interface (SCI)
• UART asynchronous port
• Full-duplex mode
• SCI programmable for reception and
transmission
• SCI is available in 68HC11, and 68HC12
![Page 51: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/51.jpg)
51
SCI full duplex signals
![Page 52: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/52.jpg)
52
SCI
• SCI baud rates are fixed with prescaling
bits
• Baud rate is selectable among 32 possible
value
• Support wake-up feature to wake up the
other side
![Page 53: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/53.jpg)
53
Serial Interface (SI)
• Support both Synchronous and
Asynchronous transfer
• For Asynchronous, UART10T and
UART11T is supported
• For Synchronous, Universal Synchronous
Receiver and Transmitter
• SI is internal serial I/O for 8051
![Page 54: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/54.jpg)
54
SI transfer in synchronous and
asynchronous mode
![Page 55: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/55.jpg)
55
SI mode 0: Synchronous mode
![Page 56: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/56.jpg)
56
SI modes
• Mode 0: Half duplex synchronous mode
• Mode 1,2,3: Asynchronous mode with
different setup for baudrate
![Page 57: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/57.jpg)
SPI Programming
• Simple SPI Setup on Raspberry Pi
57
![Page 58: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/58.jpg)
SPI Port
• Enable SPI
/etc/modprobe.d/raspi-blacklist.conf
Add '#' in front of the line spi-bcm2708. Save the file.
• Rebootsudo reboot
• Check the device
lsmod
• Add Python library for SPI
sudo apt-get update
sudo apt-get install python-dev 58
![Page 59: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/59.jpg)
Add Python SPI Wrapper
mkdir python-spi
cd python-spi
wget https://raw.github.com/doceme/py-
spidev/master/setup.py
wget https://raw.github.com/doceme/py-
spidev/master/spidev_module.c
sudo python setup.py install
59
![Page 60: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/60.jpg)
Python Code
import spidev
import time
spi = spidev.SpiDev()
spi.open(0,0)
while True:
resp = spi.xfer2([0x00])
print resp[0]
time.sleep(1)
60
![Page 61: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/61.jpg)
Output
61
spi.open(0,0) will open bus 0, CE0
spi.xfer2 will keep CE asserted and read
data from slave
![Page 62: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/62.jpg)
MCP3008
• ADC sensor: 10 bits data reading
• Provide SPI Interface
62
![Page 63: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/63.jpg)
Circuit Connection
63
![Page 64: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/64.jpg)
SPI Command
• Data flow:
– Start bit
– Control bit (4-bit length)
– Wait
• spi.xfer() is for active high
chip
• spi.xfer2() is for active low
chip
64
![Page 65: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/65.jpg)
xfer2 command• Send and receive the array of data
• For MCP 3008, the first command is 1.
• Next, we send the channel that we want to read the data
• Finally, we send the blank signal
• Read MCP3008 manual, for more details
65
![Page 66: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/66.jpg)
66
import spidev
import time
import os
#start the SPI bus by opening the spi port
spi = spidev.SpiDev() spi.open(0,0)
#SPI port 0 opened and Device Chip Select set to 0
#function to read the channels of MCP3008
def readadc(channel):
value = spi.xfer2([1,(8+channel)<<4,0])
read = ((value[1]&3) << 8) + value[2]
return read
while True:
#creating the list for the different values of each channels
datalist = []
for i in range(0,8):
#read channel one by one using range of 0 to 8
data = readadc(i)
#append data into the datalist created
datalist.append(data)
#convert temperature value from data received
temperature = ((data * 330)/float(1023))-50
print temperature
![Page 67: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/67.jpg)
Receive Data
ADC Data is 10 bits
• Received data = 00000000 01000010 01100010
value[0] = 00000000
value[1] = 01000010
value[2] = 01100010
Final data = (value[1] & 3) << 8 + value[2] = 61067
![Page 68: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/68.jpg)
68
Secure Digital Input Output (SDIO)
• From Secure Digital Association (over 700
companies) started from 3 companies in
1999 (Panasonic, Sandisk, Toshiba)
• Create a new memory card called SD
format for IO
• SDIO card has become popular in mobile
devices, PDA, digital cameras and
embedded systems
![Page 69: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/69.jpg)
69
SD card
• Based on SD
technology
• SDHC (Secure Digital
High Capacity)
is the extension
of SD card
![Page 70: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/70.jpg)
70
SDIO
• SD card size: 0.14cm x 2.4 cm x 3.2 cm
• SDIO host controller inside the card
• Controller may include SPI controller to support
SPI mode
• Can have up to 8 logical function inside SDIO
host controller
• Provide additional memory in SD format
• Functions include several protocol such as IrDA,
Wi-fi, Ethernet, GPS, Bluetooth, RFID
![Page 71: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/71.jpg)
71
SDIO Function and card
• Up to 8 logical functions
• CRC data check during transfer
• Retransmission on error
• Support data transfer in block of bytes
• Data rate from 20 Mbps to 100 Mbps
![Page 72: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/72.jpg)
72
Inter IC (I2C) bus
• Developed by Philips in 1980s
• Low pin count serial interface used to connect
chips on a circuit board
• Also used by Intel in the PC motherboard
System Management Bus (SMB)
• 7 bit address
• 1 bit Read/Write
• 8 Data bits
• Probably have one in your TV
![Page 73: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/73.jpg)
73
I2C
• ICs mutually network through a common
synchronize serial bus
• I2C bus also support I/O interconnect
• 400 kbps up to 2 meters and 100 kbps for
longer distances
• Version 2 support up to 2.4 MHz
• Version 4 support 5MHz Ultra Fast Mode
![Page 74: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/74.jpg)
74
Serial I/O I2C bus
![Page 75: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/75.jpg)
75
Distributed I2C bus connection
![Page 76: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/76.jpg)
76
I2C bus protocol
• The bus has two lines – one is for clock and another one is bidirectional data
• It is a Master and Slave system
• Master can address 127 slaves at an instances
• Number of Masters can be connected on the bus
• However, only one Master can be active at a time (use bus arbitration)
• Each devices has 7-bit address
• Master controls the clock, but a slave can slow clock down by drive the clock low (clock stretching)
![Page 77: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/77.jpg)
77
I2C communication
![Page 78: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/78.jpg)
78
I2C bus protocol
![Page 79: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/79.jpg)
79
I2C interface serial transmission
of an 8-bit data value
1 2 7 8 1 29 8 93-7
ACK
ACK Signalfrom Slave
Byte Complete Clock Line HeldLow while serviced
ACK
START STOP
SDA
SCL
S P
ACK Signalfrom Receiver
MSB
3-6
Address Data
R/W
![Page 80: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/80.jpg)
80
I2C bus field
• First field – similar to start bit in UART
• Second field – 7 bit address field
• Third field – 1 bit control field define read/write’
• Fourth field – 1 bit control field whether the present data is an acknowledgement from slave
• Firth field – 8 bit data field (MSB first)
• Six field – 1 bit control field NACK (negative acknowledgement) to tell slave that the acknowledgement is not required
• Seven field -1 bit stop bit similar to UART
![Page 81: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/81.jpg)
81
Microprocessor sends data
1. The microprocessor sends an I2C start sequence.
2. The microprocessor serially clocks out the 7-bit I2C address of the slave with the R/W’ bit set Low (i.e., write operation)
3. The slave set ACK signal
4. The microprocessor serially clocks out the 8-bit data value(s).
5. If the ACK is used to tell that the receiver get the data
6. The microprocessor sends a stop sequence.
(The microprocessor can keep sending the data as it wishes, bus owner)
![Page 82: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/82.jpg)
82
Microprocessor reads data
1. The microprocessor sends a start sequence.
2. The microprocessor serially clocks out the 7-bit I2C address of the slave with the R/W’ bit set High.
3. The slave set ACK signal
4. The microprocessor serially clocks in the 8-bit data value(s) off the bus from the slave.
5. If the ACK is used to tell that the Master get the data, and the slave should keep sending next data
6. The microprocessor sends a stop sequence.
(The microprocessor can keep reading the data as it wishes. If the ACK is set to 0, the slave will stop sending the data)
![Page 83: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/83.jpg)
Enable I2C on Pi
• Enabling the I2C Portsudo raspi-config
83
![Page 84: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/84.jpg)
Enable I2C on Pi
• Enabling the I2C on old Raspbianin /etc/modules Add lines
i2c-bcm2708
i2c-dev
Edit module blacklist in /etc/modprobe.d/raspi-blacklist.conf
Add # to i2c-bcm2708
• Install I2C utilitiessudo apt-get install python-smbus i2c-tools
sudo reboot
84
![Page 85: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/85.jpg)
Checking for connected devices
• Check the status for I2C0 or I2C1 portsudo i2cdetect -y 0
//or
sudo i2cdetect -y 1
7 bits I2C address of all
found devices will be shown
85
![Page 86: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/86.jpg)
Example of the code#!/usr/bin/python
import smbus
bus = smbus.SMBus(1)
# 0 = /dev/i2c-0 (port I2C0), 1 = /dev/i2c-1 (port I2C1)
# DEVICE_ADDRESS = 0x15
#7 bit address (will be left shifted to add the read write bit)
DEVICE_REG_MODE1 = 0x00
DEVICE_REG_LEDOUT0 = 0x1d
#Write a single register
bus.write_byte_data(DEVICE_ADDRESS, DEVICE_REG_MODE1,
0x80)
#Write an array of registers
ledout_values = [0xff, 0xff, 0xff, 0xff, 0xff, 0xff]
bus.write_i2c_block_data(DEVICE_ADDRESS,
DEVICE_REG_LEDOUT0, ledout_values) 86
![Page 87: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/87.jpg)
Raspberry Pi Connection
87
![Page 88: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/88.jpg)
Example of I2C message
88
![Page 89: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/89.jpg)
Example: ADC using I2C
• ADC device (4 channels)
89
![Page 90: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/90.jpg)
Circuit Connection
90
![Page 91: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/91.jpg)
91
#data_adc.py
import wiringpi2
import time
DEBUG=False
LIGHT=0;TEMP=1;EXT=2;POT=3
ADC_CH=[LIGHT,TEMP,EXT,POT]
ADC_ADR=0x48
ADC_CYCLE=0x04
BUS_GAP=0.25
DATANAME=["0:Light","1:Temperature", "2:External","3:Potentiometer" ]
class device:
# Constructor:
def __init__(self,addr=ADC_ADR):
self.NAME = DATANAME
self.i2c = wiringpi2.I2C()
self.devADC=self.i2c.setup(addr)
pwrup = self.i2c.read(self.devADC) #flush powerup value
if DEBUG==True and pwrup!=-1:
print("ADC Ready")
self.i2c.read(self.devADC) #flush first value
time.sleep(BUS_GAP)
self.i2c.write(self.devADC,ADC_CYCLE)
time.sleep(BUS_GAP)
self.i2c.read(self.devADC) #flush first value
def getName(self):
return self.NAME
def getNew(self):
data=[]
for ch in ADC_CH:
time.sleep(BUS_GAP)
data.append(self.i2c.read(self.devADC))
return data
![Page 92: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/92.jpg)
def main():
ADC = device(ADC_ADR)
print (str(ADC.getName()))
for i in range(10):
dataValues = ADC.getNew()
print (str(dataValues))
time.sleep(1)
if __name__=='__main__':
main()
92
![Page 93: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/93.jpg)
93
Questions?
• What’s the speed and distance of I2C
(version 1)?
• I2C is?
– Master-slave -Peer-to-Peer -Broadcast
• How can the device initiate the talk to the
master?
![Page 94: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/94.jpg)
94
Universal Serial Bus (USB)
• Developed by IBM, Intel, Microsoft, DEC, NEC, and Northern telecom
• Serial Synchronous communication
• Seven bit address code
• Connecting from the device to the host computer is called upstream port
• Connecting from host computer to the device is called downstream port
• Tree (star) topology is used when the host is the root of the tree, a hub is used to make a sub-branch of the tree
• www.usb.org
![Page 95: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/95.jpg)
95
USB Mini Hub
![Page 96: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/96.jpg)
96
USB
• There are two interface type: type A and
type B
• Type A: plug on the upstream end (PC)
• Type B: plug on the downstream end
(device)
• Both types are polarized (cannot be
inserted in the wrong way)
• Cannot connects two PCs with USB
![Page 97: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/97.jpg)
97
USB interface
![Page 98: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/98.jpg)
98
Universal Serial Bus (USB)
• 1-bit serial sent over twisted pair wire
• Data transfer is in term of packet
• USB Packets contain address and data
• Up to 127 devices on bus
• Special purpose low-cost USB single chip
microcontrollers are used.
• Length is limited to a few feet – a bus and not a
network
• Data D+ or D- line can operate up to 3.3 volt
![Page 99: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/99.jpg)
99
USB applications
• Flash memory cards
• Pen-like memory devices
• Digital cameras
• Printers
• Mouse-device
• Pocket-PC
• Video games
• Scanners
![Page 100: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/100.jpg)
100
USB
• Serial transmission between host and
serial devices
• The data transfer is of four types
– Controlled data transfer – Bulk data transfer
– Interrupt driven data - Iso-Synchronous
transfer
• Maximum 127 devices can connect a host
![Page 101: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/101.jpg)
101
USB
Standards:
• USB1.1 ( a low speed 1.5 Mbps 3 meter
channel and high speed 12 Mbps 25
meters)
• USB 2.0 (high speed 480 Mbps 25 meter
channel
• USB 3.1 (can transfer up to 10 Gbit/s)
• Wireless USB (high speed 480 Mbps 3m)
![Page 102: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/102.jpg)
102
Host connection to the devices or
node
• Using USB port driving software and host
controller
• Host computer or system has a host
controller, which connect to a root hub
• A hub is one that connects to other nodes
or hubs
• A tree-like topology
![Page 103: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/103.jpg)
103
USB bus
![Page 104: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/104.jpg)
104
USB bus
![Page 105: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/105.jpg)
105
Dual Role Devices (DRDs)
• A device can be used as either USB host
or USB device.
• For example, a USB camera is USB host
when connects with a printer and is a USB
device when connects with a computer
![Page 106: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/106.jpg)
106
Hub connection
• The root hub connects to the hub and
node at level 1
• A hub at level 1 connects to the hub and
node at level 2
• Only the nodes are presented at the last
level
• USB hubs can have up to 5 levels
![Page 107: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/107.jpg)
107
USB device features
• Can be hot plugged (attached), configured and
used, reset, reconfigured and used
• Bandwidth sharing with other devices: Host
schedules the sharing of bandwidth among the
attached devices at an instance
• Can be attached and reattached
• Attaching and detaching USB device or host
without rebooting
• A device can be bus-powered or self-powered
![Page 108: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/108.jpg)
108
A low-cost USB Microcontroller
is typically used in USB Devices
USB
Connector
+5V
D+
D-
GND
USB
Transceiver
Serial
Interface
Engine
(SIE)
bytes
bytes USB
Interface
Program & Data
(RAM & ROM)
General
Purpose
Microprocessor
I/O Ports
![Page 109: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/109.jpg)
109
USB Data Rates
• USB 2.0 – Up to 480 Mbps
• USB 1.0 – 12 Mbps and 1.5 Mbps
• USB 2.0 supports USB 1.0 devices
• Needed higher USB 2.0 data rates for
external drives and video
• USB 3.0 is 10x USB 2.0
![Page 110: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/110.jpg)
110
USB Enumeration
• Hot pluggable – longer power and ground
(outer) pins on USB connector
• At power up, software (OS) can read
product and vendor ID codes (PID/VID)
• Codes are used to locate device driver
• The required Device Driver is loaded
• The new device is assigned its USB
address (0..127) with a command
![Page 111: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/111.jpg)
111
USB protocol
• USB bus cable has 4 wires: 1 for 5 V, 2 for
twisted pairs, 1 for ground
• Non Return To zero (NRZ) signal is used
• Synchronization clock encoded by
inserting synchronous code (SYNC) field
between each USB packet
• A polled bus
![Page 112: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/112.jpg)
112
USB protocol
• Host controller regularly polls the presence of the device
• The device does a handshaking through a handshaking packet
• A CRC field in a data packet permits error detection
• Least significant bit first
• Changing voltage on Data signal can change the speed
![Page 113: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/113.jpg)
113
USB Data format
Four different format support:
• Bulk asynchronous mode: transfer non-
critical data
• Isochronous mode: critical data
• Interrupt: from device to host
• Control: from host to control bus and send
request to devices
![Page 114: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/114.jpg)
114
USB Packets
• Contain a packet type
• USB Address and Endpoint fields
• Each device can have several endpoints
• Endpoint is a hardware buffer between the USB Serial Interface Engine (SIE) and the firmware running on the microcontroller (typically 8-64 bytes)
• CRC error code checked and Ack sent back
![Page 115: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/115.jpg)
115
USB Data Packet
• Sync bit
• Packet Identifier (PID)
• Device address
• Data
• Cyclic Redundancy Check (CRC)
Data is transmitted LSB bit first
![Page 116: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/116.jpg)
116
USB Data Packet
![Page 117: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/117.jpg)
117
Endpoint
![Page 118: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/118.jpg)
118
The USB Serial Interface Engine
(SIE) handles USB packets
Token Packet H/S PktData Packet Token Packet H/S PktData Packet
Payload
Data
O
U
T
A
D
D
R
E
N
D
P
C
R
C
5
D
A
T
A
1
A
C
K
C
R
C
1
6
Payload
Data
O
U
T
A
D
D
R
E
N
D
P
C
R
C
5
D
A
T
A
0
A
C
K
C
R
C
1
6
D+
USB
Transceiver
Serial
Interface
Engine
(SIE)D-
Payload
Data
Payload
Data
A
C
K
![Page 119: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/119.jpg)
119
Communication support
• Stream with no USB defined protocol
• Default control for provide access
• Message for control function for the device
![Page 120: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/120.jpg)
120
Serial Interface Engine (SIE)
• Special hardware unit that handles
sending and receiving high speed serial
USB packets
• Serial data rates needed are too high to
handle using only software running on the
microcontroller
• Microcontroller only transfers bytes to/from
endpoints in the SIE
![Page 121: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/121.jpg)
121
USB Software
• OS typically has a USB driver that handles
enumeration and loads driver for device
• Some common USB device drivers may
be provided with OS (storage, serial,
keyboard, mouse)
• Most other devices need a device driver
from the manufacturer
![Page 122: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/122.jpg)
122
Figure 3.9 A USB protocol analyzer captures and displays the USB packets exchanged with a USB
Flash Drive (www.usbdeveloper.com) .
![Page 123: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/123.jpg)
123
Wireless USB
• Wireless extension of USB 2.0 and it operates at
ultra wide band 3.1 GHz to 10.6 GHz
frequencies
• For short range personal area network (high
speed 480 Mbps 3 meter or 110 Mbps 10 meter
channel)
• FCC has recommend a host wire adapter and a
device wire adapter
• Wireless USB also supports dual-role devices
![Page 124: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/124.jpg)
Python Interface
• It treats USB like UART communication:
#!/usr/bin/python
import serial
ser = serial.Serial('/dev/ttypUSB0', 4800, timeout = 1)
x = ser.read(1200)
print x
124
![Page 125: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/125.jpg)
125
Questions?
• What’s the maximum speed and distance
of USB v2?
• Why USB can send the data in higher
speed and better distance than I2C?
• What’re other advantages/disadvantages
comparing with I2C?
![Page 126: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/126.jpg)
126
Firewire
• It was initiated by Apple Inc.and developed by IEEE 1394 working group
• IEEE 1394a and IEEE 1394b standard
• IEEE 1394a is up to 400 Mbps
• IEEE 1394b is up to 800 Mbps
• Serial isochronous transfer or asynchronous transfer
• Transfer data at a guarantee rate
• Also used in real-time device and video conference
![Page 127: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/127.jpg)
127
Firewire application
• Multimedia streaming devices
• Digital Video cameras
• Digital camcorders
• Digital Video Disks (DVDs)
• Music system multimedia peripherals
• Some harddisk drives
• Some high-speed printers
![Page 128: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/128.jpg)
128
isochronous or asynchronous
• Isochronous
– time-critical
– error-tolerant data
• asynchronous
– data isn’t error-tolerant
– not time-critical
![Page 129: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/129.jpg)
129
Firewire
![Page 130: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/130.jpg)
130
Firewire interface
• Six pin configuration (Firewire400):
power, ground, two twisted pair sets
• Nine pin configuration (Firewire800):
two additional ground shield
![Page 131: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/131.jpg)
131
Firewire features
• Can interface up to 63 external devices
• Support plug and play and hot plugging
• Provides self-powered and bus powered support
• Twisted pairs
• Support multiple-host per bus
![Page 132: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/132.jpg)
132
Daisy Chain configuration
• Can be up to 16 hop
• For Firewire800, up to 400 meter long
![Page 133: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/133.jpg)
133
Another Firewire connection
![Page 134: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/134.jpg)
134
Serial Firewire Bus
![Page 135: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/135.jpg)
135
Data link layer
![Page 136: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/136.jpg)
136
Firewire protocol layers
![Page 137: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/137.jpg)
137
Comparison with USB
• Although USB 2.0 can run at higher rate
than Firewire400, in practice, USB 2.0
rarely exceeds 280 Mbps
• This is because for USB, host controller
has to manage low-level USB protocol
whereas Firewire delegates the task to the
interface hardware
• Simpler bus network
![Page 138: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/138.jpg)
138
USB vs. Firewire
![Page 139: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/139.jpg)
139
Questions?
• What’s the maximum speed and distance of
Firewire?
• Why Firewire is faster?
• What is the similarity and difference comparing
with USB?
• What do you think about USBv3 and Firewirev2?
![Page 140: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/140.jpg)
140
Audio standard
• PCM
• AC97
• MP3
• WMA
![Page 141: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/141.jpg)
141
Pulse Code Modulation (PCM)
• PCM is an audio format
• PCM is a digital
representation of analog
signal where the
magnitude of the signal
is sampled regularly by
uniformed interval
![Page 142: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/142.jpg)
142
Audio
• For PCs, AC 97 is a common audio
standard
• Needs analog signals so A/D and D/A
hardware is used inside the Audio IC
• Analog mixers can add analog signals
from different sources
• Audio driver typically provided with OS
![Page 143: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/143.jpg)
143
Figure 3.9 Realtek ALC202 AC97 Device Block Diagram
![Page 144: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/144.jpg)
144
Pulse Width Modulation (PWM)
• PWM is a way for controlling analog circuits with digital output
• By controlling analog circuit digitally, system cost and power consumption can be reduced
• Used in audio, motor control, telecommunication
• The duty cycle is the proportional of the on time to the regular interval or period
![Page 145: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/145.jpg)
145
PWM with 10%, 50%, and 90%
duty cycle
![Page 146: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/146.jpg)
146
PWM Signal
![Page 147: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/147.jpg)
147
CAN and LIN Bus
• Serial Buses Developed for Automotive Industry in mid 1980s – More advanced than RS232 Serial
• CAN is used to connect car subsystem processors together, has multiple bus masters, & uses 2 wires
• LIN is used to connect a processor with it’s smart sensors, a single master, & uses only 1 wire
• LIN used at lower levels along with CAN at higher levels in the system
• Both are now found in other embedded devices
![Page 148: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/148.jpg)
148
CAN bus
• Two wires, half duplex, high-speed network
system
• Can link up to 2032 devices
• Up to 1 Mbps thus facilitates real-time control
• Sophisticated error detection features
• CAN 2.0 A uses 11 bit identifiers
• CAN 2.0 B uses 29 bit identifiers
• ECU = Engine Control Unit
![Page 149: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/149.jpg)
149
Car Body Network with CAN & LIN
CAN
CAN
Power Train
Light
Sub-Bus
ITS
Window Lift
InteriorLight
Lock
Mirror
Lock
Mirror
Lock
Lock
Seat
Htng
Seat
Htng
Instruments
Central
Body Ctrl
Climate
Universal Motor
Universal Panel
Light
Roof
1 backbone, 13 nodes8 subnets, 1-8 local nodes52 nodes total
St-Wheel Panel
x6
Htng
Htng
Seat
Wiper
Trunk
WHtg
Universal Light
![Page 150: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/150.jpg)
150
Controller Area Network (CAN)
• Messages contain a message number and
not an address
• Lower number messages have priority
• Each devices checks the message
number to see if it needs to handle the
message
• Data rates up to 1M Baud
• Special CAN chips are available
![Page 151: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/151.jpg)
151
CAN 2.0 A message format
![Page 152: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/152.jpg)
152
CAN 2.0 B message format
![Page 153: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/153.jpg)
153
CAN controller topology
![Page 154: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/154.jpg)
154
Advantages of CAN bus
• Protocol is highly reliable and error
resistant
• World-wide accept standard
• Multi-master topology
• Sophisticated error detection
• Short latency time for high priority
messages (real-time systems)
![Page 155: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/155.jpg)
155
Local Interconnect Network (LIN)
• Can be implemented with a UART and
microcontroller firmware
• Data rates up to 20K Baud
• Only one bus master
• Lower cost, lower data rates, and 1 less
wire than CAN
![Page 156: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/156.jpg)
156
Sync
Break
Sync
Field
Ident
Field
Data
Field
Data
Field
Data
Field
Data
Field
Check-
Sum
Field
Message Frame
Header Response
Interframe
Space or
BreakInterbyte Space
In_Frame Response Space
Figure 3.16 A Typical LIN Frame Consisting of Synch Break, Synch Field, Identifier, Data Field and
Checksum.
![Page 157: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/157.jpg)
157
Figure 3.13 The Tektronix DPO7000 1-4 Channel Oscilloscope is an embedded device that runs
Windows XP. The display above is from an optional software package for the oscilloscope that
decodes and displays SPI bus signals. Images courtesy of Prodigy Test Solutions.
![Page 158: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/158.jpg)
158
Figure 3.14 The Tektronix DPO7000 1-4 Channel Oscilloscope is an embedded device that runs
Windows XP. The display above is from an optional software package for the oscilloscope that
decodes and displays I2C bus signals. Images courtesy of Prodigy Test Solutions.
![Page 159: I/O Interfacing Standards for External Devicesesl.ait.ac.th/courses/AT81.14/class8n.pdf · Standards for External Devices •Serial Port •PS/2 •SPI, SCI, SI, and SDIO •I2C •Audio](https://reader034.fdocuments.us/reader034/viewer/2022051811/60204bd3567dfd683d2ecd73/html5/thumbnails/159.jpg)
Questions?
159