Microcontroller: 1-wire Interface, SPI Interface - IIIT
Microcontroller: 1-wire Interface, SPI Interface - IIIT
Microcontroller: 1-wire Interface, SPI Interface - IIIT
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>Microcontroller</strong>: 1-<strong>wire</strong> <strong>Interface</strong>,<br />
<strong>SPI</strong> <strong>Interface</strong><br />
Amarjeet Singh<br />
February 5, 2012
Logistics<br />
Website updated with lecture slides from last 2 lectures<br />
Assignment-3<br />
Any problem<br />
Assignment-4<br />
Final assignment – and probably requires maximum effort<br />
Make sure to build upon your previous assignments<br />
Link for Hex file for boot loader given on the course website<br />
2
Students Presentations – After Mid<br />
Sem<br />
Student presentations on specialization topics in Cyber Physical<br />
Systems<br />
Will share the list of topics with spreadsheet with everyone<br />
Mandatory for CSE-537 students<br />
Select one of the topics that you want to present by this weekend<br />
and assign it to yourself in the spreadsheet<br />
If CSE-337 students also present, their summary evaluation will<br />
also carry 5 marks only<br />
Presentations will start after mid semester<br />
I will post the schedule after you all have selected the papers<br />
All need to submit 1 page summary on the same paper before the<br />
class (through email)<br />
Each group need to submit one summary only<br />
3
Revision from last two classes<br />
For the 16-bit RTC in xMega:<br />
What is the highest resolution obtained with 32.768 KHz clock<br />
With a resolution of 1 second, what is the maximum timeout<br />
period<br />
How can you use the two Analog Comparator modules in xMega to<br />
check if a signal is within a range<br />
What is the maximum ADC resolution in xMega<br />
How many maximum single ended signals can be supported using<br />
ADC block in xMega<br />
What is the reference voltage given to the negative channel for:<br />
Single ended signal unsigned mode<br />
Single ended signal signed mode<br />
Differential signal (signed)<br />
4
Revision from last two classes<br />
What limits the sampling rate of ADC<br />
How is propagation delay given for ADC block in xMega<br />
What are things to consider when selecting a sensor to interface<br />
with your microcontroller<br />
What is the function of voltage regulators<br />
What are some common types of voltage regulators<br />
Where and why are decoupling capacitors used<br />
Where and why are pull up/down resistors used<br />
5
Revision from last two classes<br />
Why is it important to take a look at DC characteristics while<br />
interconnecting two ICs<br />
I2C protocol<br />
How many lines<br />
What is the packet format<br />
Why is it not suitable for peer to peer communication<br />
6
1-Wire <strong>Interface</strong><br />
Online tutorial by Maxim<br />
http://www.maximintegrated.com/products/1-<strong>wire</strong>/flash/overview/index.cfm<br />
7
DS18S20: 1-Wire <strong>Interface</strong><br />
Temperature Sensor from Maxim<br />
9-bit temperature value<br />
0.5 degree celsius accuracy from -10 to +85<br />
Can derive power directly from the data line<br />
Unique 64-bit code that allows multiple temperature sensors to<br />
be connected on the same line – e.g. temperature monitoring in<br />
HVAC<br />
8
DS18S20: Function Commands<br />
DS18S20 Transaction:<br />
Initialization<br />
ROM Command (followed by any required data exchange)<br />
DS18S20 Function Command (followed by any required data<br />
exchange)<br />
9
DS18S20: Operation Example 1<br />
Multiple DS18S20 on the same line (in parasitic mode)<br />
Master initiates a temperature conversion in a specific sensor<br />
Master reads the scratchpad to recalculate the CRC and verify the<br />
data<br />
10
DS18S20: Operation Example 2<br />
Single DS18S20 on the bus (in parasitic mode)<br />
Master writes to T H and T L registers in scratchpad and then reads<br />
the scratchpad to verify the values<br />
Master then copies scratchpad into EEPROM<br />
11
DS2482: I2C to 1-<strong>wire</strong><br />
DS2482-100: I2C to 1-<strong>wire</strong> bridge device<br />
<strong>Interface</strong>s with standard or fast I2C masters to perform bidirectional<br />
conversion between I2C master and downstream 1-Wire<br />
slave devices<br />
Relative to 1-Wire slave devices, it acts as 1-Wire master<br />
12
<strong>SPI</strong> Signals<br />
Four main signals:<br />
Master Out Slave In (MOSI)<br />
Master In Slave Out (MISO)<br />
Serial Clock (SCK)<br />
Chip Select (CS)<br />
Since there is a separate CS<br />
for each device on board,<br />
<strong>SPI</strong> does not scale up well in<br />
comparison with I2C<br />
MOSI: Generated by master, received by slave<br />
Also labeled as Serial Input (SI) or Serial Data In (SDI)<br />
MISO: Generated by slave, under control by the master<br />
Also labeled as Serial Output (SO) or Serial Data Out (SDO)<br />
Chip Select (Slave Select) generated using spare I/O of master<br />
13
<strong>SPI</strong> Communication<br />
Master configures SCK with frequency less than or equal to<br />
maximum frequency supported by slave device (1-70 MHz)<br />
Master pulls the CS low<br />
Full duplex data transfer:<br />
Both master and slave contain shift registers: Master starts the<br />
transfer by writing to its <strong>SPI</strong> shift register<br />
As master transfers the byte to the slave on MOSI, slave transfers the<br />
contents of its shift register back to the master on MISO<br />
After 5 bits are<br />
transferred what<br />
is the state of TX<br />
Buffer<br />
Both the write and the read performed simultaneously<br />
For write only operation, read byte is ignored<br />
For read only operation, a dummy byte is written to initiate slave<br />
transmission<br />
14
<strong>SPI</strong>: Modes of Operation<br />
Four modes of operation depending on clock polarity and clock phase<br />
Low clock polarity (CPOL = 0): SCK is low when idle and toggles high<br />
during transfer<br />
High clock polarity (CPOL = 1): Reverse of low clock polarity<br />
Clock phase zero (CPHA = 0): MOSI and MISO are valid on<br />
rising/falling edge of SCK for low/high clock polarity respectively<br />
Clock phase zero and low clock polarity<br />
How does the timing diagram<br />
change for CPOL = 1<br />
15
<strong>SPI</strong>: Modes of Operation<br />
Clock phase one (CPHA = 1): MOSI and MISO are valid on<br />
falling/rising edge of SCK for low/high clock polarity respectively<br />
Clock phase one and low clock polarity<br />
<strong>SPI</strong> Mode 0: CPOL = 0, CPHA = 0; <strong>SPI</strong> Mode 1: CPOL = 0, CPHA = 1;<br />
<strong>SPI</strong> Mode 2: CPOL = 1, CPHA = 0; <strong>SPI</strong> Mode 3: CPOL = 1, CPHA = 1<br />
Most common modes: <strong>SPI</strong> Mode 0 and 3 (data sampled on positive<br />
clock edge)<br />
16
<strong>SPI</strong>: Modes of Operation<br />
17
<strong>SPI</strong>: Interfacing External Flash<br />
Atmel AT25DF641: 64 Mbit Serial Flash Memory<br />
Supports <strong>SPI</strong> mode 0 and 3<br />
Works at 75 MHz<br />
Low power dissipation: 5 mA (typical) active read current<br />
100,000 Program/Erase cycles<br />
18
<strong>SPI</strong>: Interfacing External Flash<br />
Atmel AT25DF641: 64 Mbit Serial Flash Memory<br />
Supports <strong>SPI</strong> mode 0 and 3<br />
Works at 75 MHz<br />
Low power dissipation: 5 mA (typical) active read current<br />
100,000 Program/Erase cycles<br />
Which <strong>SPI</strong> mode does this waveform represent<br />
19
<strong>SPI</strong>: Key Observations<br />
4 lines required: MOSI, MISO, SCK, CS<br />
Allows simultaneous read and write making it more efficient<br />
Higher data rate: Up to 4 Mbps or more<br />
Multiple devices can be connected simultaneously but with only a<br />
single master<br />
Device selection based on Chip Select: Implies an extra pin for<br />
each device on the master chip<br />
More efficient in point to point connection: Why<br />
No acknowledgement mechanism to confirm data receipt<br />
20
<strong>SPI</strong> vs I2C<br />
<strong>SPI</strong> more suited for applications that are thought as data streams (as<br />
opposed to reading/writing address locations in slave devices)<br />
Gains efficiency in applications that take advantage of its duplex<br />
capability e.g. codec (that requires sending samples in and out)<br />
Due to lack of built-in device addressing, <strong>SPI</strong> requires more hardware<br />
resources when more than one slave device is attached<br />
But <strong>SPI</strong> more efficient and simpler in point-to-point links<br />
Cost and complexity of I2C does not scale with number of devices<br />
With its collision detection and acknowledgement scheme, I2C is a<br />
true multi-master bus<br />
21