lecture7 - intercomponent busses
TRANSCRIPT
-
7/28/2019 Lecture7 - Intercomponent Busses
1/62
1. SEPTEMBER 2011
NAVN NAVNESEN
INTERCOMPONENT BUSSES
9.OCTOBER 2012
MDL ETIADE 2012
VERSITyUNIMDL ETIADE 2012
-
7/28/2019 Lecture7 - Intercomponent Busses
2/62
SUBJECTS
SPI
I2C I2C example: LM75 temperature sensor.1-wire
-
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
. I2SCodeVision setup
-
7/28/2019 Lecture7 - Intercomponent Busses
3/62
SPI (SERIAL PERIPHERAL INTERFACE)
Introduced by Motorola.
Well suited for fast data rates (data streaming).Primitive (no error checks).Addressing multiple slaves extents HW.
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
.Normally only one master.Multi-master possible, but troublesome.
No speed limit is stated in the standard
-
7/28/2019 Lecture7 - Intercomponent Busses
4/62
SPI: SHIFT REGISTER BASED
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
-
7/28/2019 Lecture7 - Intercomponent Busses
5/62
SPI: MASTER AND SLAVE
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
CPOL=clockpolarity
CPHA=clockphase
-
7/28/2019 Lecture7 - Intercomponent Busses
6/62
SPI SLAVE
SS
SCLK
MOSI MISO
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
-
7/28/2019 Lecture7 - Intercomponent Busses
7/62
SLAVES IN PARALLEL
CONFIGURATION
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
-
7/28/2019 Lecture7 - Intercomponent Busses
8/62
SLAVES IN SERIAL CONFIGURATION
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
-
7/28/2019 Lecture7 - Intercomponent Busses
9/62
SPI PRODUCTS
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
-
7/28/2019 Lecture7 - Intercomponent Busses
10/62
MEGA16: SPI INTERFACE
Mega16 has HARDWARE for SPI interface.
Registers:SPI Control Register SPCRSPI Status Re ister SPSR
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
SPI Data Register SPDR
-
7/28/2019 Lecture7 - Intercomponent Busses
11/62
I2C (IIC)
Inter IC bus (Introduced by Philips).
Suited for medium data rates.Limited range (often locally at PCB). Inbuild addressing (minor HW demands).
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
.Real time qualified (respons times can be calculated).Speed 100kbit/s (many devices support up to 400kbit/s)
-
7/28/2019 Lecture7 - Intercomponent Busses
12/62
I2C TOPOLOGY
Each node has its own uni ue address (or ID).
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
By sending a START command,
each node isable to become the bus master.
-
7/28/2019 Lecture7 - Intercomponent Busses
13/62
I2C MASTER: START + ADDRESS
All other nodes now enters a state of listening.
Then the master sends the address of the slave, it
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
The address is 7 bits.
The last bit (R/W) informs the slave, whether the master
wants to read or to write.
-
7/28/2019 Lecture7 - Intercomponent Busses
14/62
I2C SLAVE: ACK
After having received the STARTcammand and the
address, all slaves compares the addresswith their own
address:
* If no address match, the STOP command is awaited.
* If the addressmatches, the slave sends an ACK:
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
SDA
SCL
The slave holds SDA low and
generates an SCL -pulse.
- Subsequently the master regains bus control -
-
7/28/2019 Lecture7 - Intercomponent Busses
15/62
I2C MASTER: SENDS / RECEIVES DATA
1. Master sends data:
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
During reception (2) the slave controls SDA,but the master controls SCL.
The slave is only allowed to change SDAwhile SCL is high.
-
7/28/2019 Lecture7 - Intercomponent Busses
16/62
I2C MASTER: ACKAFTER EACH
BYTE RECEIVED
Following each byte received from a slave, the master
MUST send an ACK (except
after
the last byte).
Master sets SDA low and
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
SCL
generates a clockpulse.Then the slave regains
control over SDA.
Following the last received byte, the master sends the
STOP command (freeing the bus again).
-
7/28/2019 Lecture7 - Intercomponent Busses
17/62
MASTER: STOP
Sent by the master, when it has finished sending /receiving
data.
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
Received by all slaves, now knowing the bus is again free.
STOP can be sent at any time (even in the middle of a data
transmission).
In all cases STOP means END of transmission.
-
7/28/2019 Lecture7 - Intercomponent Busses
18/62
I2C BUS HARDWARE
SCL and SDAare bi-directional.
Open drain => External pull-up necessary!
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
-
7/28/2019 Lecture7 - Intercomponent Busses
19/62
RESERVED ADDRESSES
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
10-bit addressering is possible (new standard).
In this case 2 bytes are sent as address:
11110AAx + AAAAAAAA.
(8-bit nodes ignores 10-bit addressing).
-
7/28/2019 Lecture7 - Intercomponent Busses
20/62
I2C BUS ARBITRATION
If a master is unable to set an output high (it always test for this), it looses
the bus control.
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
,
Until the yellowmarking, bothmasters think, they own the bus.
ThenCPU2 surrenders (until STOP).
-
7/28/2019 Lecture7 - Intercomponent Busses
21/62
I2C EXAMPLE: LM75
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
-
7/28/2019 Lecture7 - Intercomponent Busses
22/62
LM75: BLOCK DIAGRAM
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
-
7/28/2019 Lecture7 - Intercomponent Busses
23/62
LM75 ADDRESS
LM75 is always a slave (not capable of being a master).
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
The address(7 bit) is composed
of 4 constant bits and
the external pin settings (A2-A0).
-
7/28/2019 Lecture7 - Intercomponent Busses
24/62
LM75: TEMPERATURE DATA FORMAT
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
2complement format.
LSB = 0,5deg
. Celsius.
-
7/28/2019 Lecture7 - Intercomponent Busses
25/62
LM75: REGISTER STRUCTURE
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
-
7/28/2019 Lecture7 - Intercomponent Busses
26/62
LM75: POINTER REGISTER
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
-
7/28/2019 Lecture7 - Intercomponent Busses
27/62
LM75: TEMPERATURE REGISTERS
9.OCTOBER 2012
MDL ETIADE 2012
-
7/28/2019 Lecture7 - Intercomponent Busses
28/62
LM75: CONFIGURATION REGISTER
9.OCTOBER 2012
MDL ETIADE 2012
-
7/28/2019 Lecture7 - Intercomponent Busses
29/62
LM75: I2C TIMING, 2 BYTE READING
9.OCTOBER 2012
MDL ETIADE 2012
-
7/28/2019 Lecture7 - Intercomponent Busses
30/62
LM75: I2C TIMING, 1 BYTE READING
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
-
7/28/2019 Lecture7 - Intercomponent Busses
31/62
LM75: I2C TIMING
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
-
7/28/2019 Lecture7 - Intercomponent Busses
32/62
MEGA16: I2C INTERFACE
Mega16 has HARDWARE for I2C interface.This is called the Two Wire Serial Interface.
Dedicated pins for SDA and SCL.
Registers:
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
TWI Control Register TWCRTWI Status Register TWSRTWI Data Register TWDR
TWI (Slave) Address Register TWAR
-
7/28/2019 Lecture7 - Intercomponent Busses
33/62
CODEVISION: I2C LIBRARY
CodeVision comes with a library for interfacing I2Cdevices (uses BIT BANGING).
Any port pins can be used.
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
-
7/28/2019 Lecture7 - Intercomponent Busses
34/62
CODEVISION: I2C LIBRARY
FUNCTIONS
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
-
7/28/2019 Lecture7 - Intercomponent Busses
35/62
CODEVISION: LM75 LIBRARY
CodeVision comes with a library for interfacing the I2Cdevice LM75 (uses BIT BANGING).
Any port pins can be used.
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
-
7/28/2019 Lecture7 - Intercomponent Busses
36/62
CODEVISION: LM75 LIBRARY
FUNCTIONS
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
-
7/28/2019 Lecture7 - Intercomponent Busses
37/62
1-WIRE
Introduced by Dallas Semiconductor corp.Only 1 wire (+ground + optionally power).
Cheaper than I2C.Only suited for low data rates.Limited range (often locally at the PCB).
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
.
See good presentation at:
http://www.maximintegrated.com/products/1-wire/flash/overview/index.cfm
-
7/28/2019 Lecture7 - Intercomponent Busses
38/62
1 WIRE TOPOLOGY
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
Notice the inbuild capacitor (800pF).
Possibility ofmany slaves.
-
7/28/2019 Lecture7 - Intercomponent Busses
39/62
1-WIRE: SEQUENCE OF INITIALIZING
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
Master sends the RESET pulse.
All slaves responds by sending a Presence Pulse.
This tells the master, that at least one slave is present and ready to
communicate. But the master will not know if several slaves are
connected
-
7/28/2019 Lecture7 - Intercomponent Busses
40/62
1-WIRE:WRITE
To write a 1, themaster pulls the line
low and releases itagain. After 15s theslave will read the bus
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
.To Write a 0, themaster keeps the linelow for 60s
40
-
7/28/2019 Lecture7 - Intercomponent Busses
41/62
1-WIRE: READ
To read a bit, the master pulls the line lowand releases it. If the slave keeps it low
after 15s it means 0, if the slave releasesit, it means 1
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
41
-
7/28/2019 Lecture7 - Intercomponent Busses
42/62
1-WIRE: IN GENERAL
Normal sequence:
1. Master sends RESET and awaits Presence Pulse.
2. Master sends an 8-bit read command.
3. Master reads one or more bytes from the slave.4. Often, the last byte will be CRC, only to be used if desirable.
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
Each slave has its own unique 64 bit address.
This can be searched by the master (complex algorithm).
-
7/28/2019 Lecture7 - Intercomponent Busses
43/62
DS1820: 1-WIRE TEMPERATURE
SENSOR
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
-
7/28/2019 Lecture7 - Intercomponent Busses
44/62
DS1820 TEMPERATURE REGISTER
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
-
7/28/2019 Lecture7 - Intercomponent Busses
45/62
DS1820: ALARM REGISTERS
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
-
7/28/2019 Lecture7 - Intercomponent Busses
46/62
DS1820: POWER
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
S 820 OM CO
-
7/28/2019 Lecture7 - Intercomponent Busses
47/62
DS1820: ROM CODE
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
DS1820 MEMORY MAP
-
7/28/2019 Lecture7 - Intercomponent Busses
48/62
DS1820: MEMORY MAP
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
DS1820 SEQUENCE OF
-
7/28/2019 Lecture7 - Intercomponent Busses
49/62
DS1820: SEQUENCE OF
TRANSACTIONS
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
DS1820 COMMANDS
-
7/28/2019 Lecture7 - Intercomponent Busses
50/62
DS1820: COMMANDS
ROM Commands:
FunctionCommands:
The bus master uses a ROM command to address the DS18S20 with which it
wishes to communicate,
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
MEGA16 1 WIRE INTERFACE
-
7/28/2019 Lecture7 - Intercomponent Busses
51/62
MEGA16: 1-WIRE INTERFACE
Mega16 has NO HARDWARE for 1-wire interface.But CodeVision comes with has a 1-wire library.
This library uses bit banging (any port pin can be used).
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
, -
(many timing requirement to be met).
CODEVISION 1 WIRE LIBRARY
-
7/28/2019 Lecture7 - Intercomponent Busses
52/62
CODEVISION: 1-WIRE LIBRARY
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
CODEVISION: DS1820 LIBRARY
-
7/28/2019 Lecture7 - Intercomponent Busses
53/62
CODEVISION: DS1820 LIBRARY
CodeVision comes with a library for interfacing the 1-wire device DS1820 (uses BIT BANGING).Any port pin can be used.
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
CODEVISION: DS1820 LIBRARY
-
7/28/2019 Lecture7 - Intercomponent Busses
54/62
CODEVISION: DS1820 LIBRARY
FUNCTIONS
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
I2S
-
7/28/2019 Lecture7 - Intercomponent Busses
55/62
I2S
Inter-IC SoundOnly used for digital audio streaming (as far as I know)Streaming from master to slaveNo feedback from slave to master at all
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
Multiple slaves can be connected in parallel and listento the streamSupported by almost all audio ADC/DACs and mostdigital signal processors
55
I2S
-
7/28/2019 Lecture7 - Intercomponent Busses
56/62
I2S
I2S consists of three wires:- Word clock-Bit clock-Data
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
44.1kHz
The bit clock is 64 times word clock
Normally there are 24 or 32 bits per. channel and twochannels per word.
56
I2S TIMING
-
7/28/2019 Lecture7 - Intercomponent Busses
57/62
I2S TIMING
From the ADMP441 datasheet
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
57
CODEVISION SETUP
-
7/28/2019 Lecture7 - Intercomponent Busses
58/62
CODEVISION SETUP
Create a new project.
Select No to the
question about using
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
58
z r v
project
CODEVISION SETUP
-
7/28/2019 Lecture7 - Intercomponent Busses
59/62
CODEVISION SETUP
Add your *.c files. If you
have not written them
yet, they can be
created using
file>new>source
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
59
this dialog
CODEVISION SETUP
-
7/28/2019 Lecture7 - Intercomponent Busses
60/62
CODEVISION SETUP
Go to C compiler.
Select yourmicrocontroller
(Mega16) and your clock(3,6864MHz for STK500)
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
60
CODEVISION SETUP
-
7/28/2019 Lecture7 - Intercomponent Busses
61/62
CODEVISION SETUP
Go to After Build
Select Program the Chip
PressOK
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
61
CODEVISION SETUP
-
7/28/2019 Lecture7 - Intercomponent Busses
62/62
CODEVISION SETUP
Press programmer settings
and select your COM-port
9.OCTOBER 2012
MDL ETIADE 2012MDL ETIADE 2012
62