IOT lecture7-serial-spi-and-i2c
IOT lecture7-serial-spi-and-i2c
2
Four clocking “modes”
•Two phases
•Two polarities
clocking:
there is no During transfers with slaves A
and B, Master must
7
SPI timing
diagram
5
SPI Pros and Cons
• Pros:
– Fast and easy
• Fast for point-to-point connections
• Easily allows streaming/Constant data inflow
• No addressing/Simple to implement
– Everyone supports it
• Cons:
– SS makes multiple slaves very complicated
– No acknowledgement ability
– No inherent arbitration
– No flow control
5
Communication with the
accelerometer
• Read acceleration values and configure
interrupts
I2C bus (in
Pros
our
• Two wires bus that can connect multiple
projects) peripherals with the MCU
Cons
• Two lines
– Serial data line (SDA)
– Serial clock line (SCL)
SDA
SCL
Data line stable; Change
Data valid of data
allowed
10 of 40
Start and Stop Conditions
• A transition of the data line while
the clock line is high is defined as
either a start or a stop condition.
• Both start and stop conditions are
generated by the bus master
• The bus is considered busy after a SD SD
start condition, until a stop A A
Start Stop
Conditio Condition
n
11 of 40
2
IC Addressing
12 of 40
I2C-Connected
System
• Example I2C-connected
system with two
microcontrollers
• (Source: I2C
Specification, Philips)
Who is the master?
• master-transmitters
• master-receivers
15
An I2C “transactions” involves the following bits
<S><A6:A0><R/W><A><D7:D0><A><F>
Exercise: Bus
bit rate vs Which of these actually carries useful data?
rate
16
How to operate the accelerometer?
Accel
I2C register 1
MCU I2C register 2
….
Springs
https://www.youtube.com/watch?v=eqZgxR6eRjo