- •1 Microcontroller Basics
- •1.1 Introduction
- •1.2 Frequently Used Terms
- •1.3 Notation
- •1.4 Exercises
- •2 Microcontroller Components
- •2.1 Processor Core
- •2.1.1 Architecture
- •2.1.2 Instruction Set
- •2.1.3 Exercises
- •2.2 Memory
- •2.2.1 Volatile Memory
- •2.2.3 Accessing Memory
- •2.2.4 Exercises
- •2.3 Digital I/O
- •2.3.1 Digital Input
- •2.3.2 Digital Output
- •2.3.3 Exercises
- •2.4 Analog I/O
- •2.4.1 Digital/Analog Conversion
- •2.4.2 Analog Comparator
- •2.4.3 Analog/Digital Conversion
- •2.4.4 Exercises
- •2.5 Interrupts
- •2.5.1 Interrupt Control
- •2.5.2 Interrupt Handling
- •2.5.3 Interrupt Service Routine
- •2.5.4 Exercises
- •2.6 Timer
- •2.6.1 Counter
- •2.6.2 Input Capture
- •2.6.3 Output Compare
- •2.6.4 Pulse Width Modulation
- •2.6.5 Exercises
- •2.7 Other Features
- •2.7.1 Watchdog Timer
- •2.7.2 Power Consumption and Sleep
- •2.7.3 Reset
- •2.7.4 Exercises
- •3 Communication Interfaces
- •3.1 SCI (UART)
- •3.3.1 Data Transmission
- •3.3.2 Speed Control Through Slave
- •3.3.4 Extended Addresses
- •3.4 Exercises
- •Index
3.4. EXERCISES |
87 |
If you are implementing this in a bit-banging solution, do not forget that after setting SCL to high (by setting the pin to input), you must wait for the rising edge on SCL before you can start the timer that will set SCL to low again.
3.3.3Multi-Master Mode
For a multi-master system to work, we need some means to control bus access and to synchronize the multiple clock signals. The IIC bus specification utilizes the wired-AND property of the SDA and SCL lines to achieve these goals.
Let us look at SCL first: Assume that initially, each master generates its clock signal independently of the other masters and puts it on SCL. Due to the wired-AND property, the first master to generate a falling edge will set SCL to low. Since the masters read back the actual value of SCL, as described in Section 3.3.2, and start timing a low or high phase only after the corresponding edge has been detected on SCL, the first falling edge on SCL triggers timing of the low phase on all masters. Now one by one, the masters will finish their low phases and try to set SCL to high. However, as long as one master still remains low, the SCL line stays low due to the wired-AND property. Hence, the master with the longest low phase generates the low phase of the resulting SCL signal. When this master goes high, the SCL signal rises to high and all masters start timing their high phases. Here, the first master to finish its high phase will set SCL to low again, effectively ending the SCL high phase. Hence, the master with the shortest high phase generates the high phase of the resulting SCL signal.
Bus arbitration uses the wired-AND property of the SDA line. When the bus is idle, any master can generate the start condition and begin to transmit the slave address. Like with the SCL line, the master reads back the SDA line to check whether the bit it has written has actually made it to SDA. Again, a low level will be dominant, so a master who writes a 1 and reads back a 0 recognizes that another master is using the bus as well and stops transmitting. In the end, only one master will remain (except if two masters have sent exactly the same message, in which case backing off is not necessary).
3.3.4Extended Addresses
As we have already mentioned, the original 7-bit addressing scheme was later extended to 10-bit addresses. To allow compatibility with the original 7-bit addressing, one of the reserved 7-bit addresses (11110XX)2 was used to implement 10-bit addressing:
To write to a slave, the master sends (11110XX)2 in the address field and sets R/W to 0. The XX in the field are the two most significant bits of the 10-bit slave address. Each slave compares these two bits to the msb’s of its own address and acknowledges if there is a match. The master now sends the remaining 8 bits of the address in the next byte. Only one of the previously addressed slaves will find a match and acknowledge. After that, the master transmits data to the slave.
To read from a slave, the master first sends (11110XX)2 and sets R/W to 0. It then sends the low byte of the address and waits again for the acknowledge. After the acknowledge, the master generates a repeated start condition and again sends (11110XX)2, but this time sets R/W to 1. The slave that was addressed last will react to the match of the two msb’s and will start transmitting in the next byte.
3.4 Exercises
Exercise 3.1 Explain the differences between synchronous and asynchronous communication. Can
88 |
CHAPTER 3. COMMUNICATION INTERFACES |
you come up with a protocol that has both synchronous and asynchronous properties?
Exercise 3.2 Assume you have a UART frame format of 8E1. What percentage of the bandwidth is used for data, what is used up by the frame itself?
Exercise 3.3 Adapt equations (3.3)-(3.6) to account for e erroneous samples per bit. Remember: svn−e and svn+e now both have to be within bit k. How can you use your new formulas to account for an even s?
Exercise 3.4 You use the SPI to communicate with a peripheral device. What percentage of the bandwidth is used for data, what is used up by the communication frame itself?
Exercise 3.5 You use the IIC bus to transmit one byte of data to a slave. What percentage of the bandwidth is used for data, what is used up by the communication frame itself?
Exercise 3.6 We explained how the IIC bus synchronizes the clock signals of multiple slaves. How problematic is it that the resulting clock signal inherits the shortest high phase?
Exercise 3.7 How does the 10-bit addressing feature of the IIC bus affect 7-bit address devices?
Appendix A
Table of Acronyms
A |
|
AC |
Alternating Current (Wechselstrom) |
AD |
Analog/Digital |
ADC |
Analog/Digital Converter (Analog/Digital-Wandler) |
ALU |
Arithmetic-Logic Unit |
B |
|
BDLC |
Byte Data Link Control |
BDM |
Background Debug Mode |
BOR |
Brown-Out Reset |
bps |
bits per second |
C |
|
CAN |
Controller Area Network (Bus) |
CC |
Condition Code (Register) |
CISC |
Complex Instruction Set Computer |
CLCC |
Ceramic Leaded Chip Carrier (casing, Gehauseform)¨ |
COP |
Computer Operates Properly |
CPU |
Central Processing Unit (Zentrale Recheneinheit) |
CQFP |
Ceramic Quad Flat Pack (casing, Gehauseform)¨ |
D |
|
DA |
Digital/Analog |
DAC |
Digital/Analog Converter (Digital/Analog-Wandler) |
DC |
Direct Current (Gleichstrom) |
DDR |
Data Direction Register |
DIL |
Dual In Line (casing, Gehauseform)¨ |
DIP |
Dual-In-line Package (casing, Gehauseform,¨ same as DIL) |
DMA |
Direct Memory Access |
DNL |
Differential Non-Linearity (ADC) |
DP |
Dot Point (Dezimalpunkt) |
DRAM |
Dynamic RAM |
DSP |
Digital Signal Processor |
DUT |
Device Under Test |
89
90 |
APPENDIX A. TABLE OF ACRONYMS |
E |
|
EEPROM |
Electrically Erasable and Programmable ROM |
EMC |
Electromagnetic Compatibility (Elektromagnetische Vertraglichkeit,¨ EMV) |
EMI |
Electromagnetic Interference (Elektromagnetische Beeinflussung, EMB) |
EMR |
Electro-Mechanical Relay |
EPROM |
Erasable and Programmable ROM |
ESD |
Electrostatic Discharge (Elektrostatische Entladung) |
F |
|
FPGA |
Field Programmable Gate Array |
I |
|
I2C |
Inter-Integrated Circuit (bus) |
ICD |
In-Circuit Debugger |
ICE |
In-Circuit Emulator |
ICSP |
In-Circuit Serial Programming |
IDE |
Integrated Development Environment |
IE |
Interrupt Enable (Bit) |
IF |
Interrupt Flag (Bit) |
IIC |
see I2C |
INL |
Integral Non-Linearity (ADC) |
IR |
Infrared; Instruction Register |
IRQ |
Interrupt Request |
ISP |
In-System Serial Programming (programming interface) |
ISR |
Interrupt Service Routine |
ISS |
Instruction Set Simulator |
J |
|
JTAG |
Joint Test Action Group (debug interface) |
L |
|
LED |
Light Emitting Diode (Leuchtdiode) |
LOC |
Lines of Code |
LQFP |
Low Profile Quad Plastic Flat Back (casing, Gehauseform)¨ |
LSB |
Least Significant Bit |
M |
|
MCU |
Microcontroller Unit |
MISO |
Master In, Slave Out (part of SPI) |
MMU |
Memory Management Uni |
MOSI |
Master Out, Slave In (part of SPI) |
MSB |
Most Significant Bit |
MSCAN |
Motorola Scalable CAN |
N |
|
NMI |
Non-Maskable Interrupt |
NRZ |
Non Return to Zero (encoding) |
91
NVRAM |
Non-Volatile RAM |
O |
|
OnCE |
On-Chip Emulation (debug interface) |
OTP |
One-Time Programmable |
P |
|
PC |
Program Counter |
PCS |
Peripheral Chip Select (part of SPI) |
PCB |
Printed Circuit Board |
PDIP |
Plastic Dual-In-Line Package (casing, Gehauseform)¨ |
PIN |
Port Input Register (digital I/O) |
PLCC |
Plastic Leaded Chip Carrier (casing, Gehauseform)¨ |
PROM |
Programmable ROM |
PWM |
Pulse Width Modulation (Pulsbreitenmodulation) |
POR |
Power-On Reset |
ppm |
Parts Per Million |
pps |
Pulses Per Second |
Q |
Quad Plastic Flat Back (casing, Gehauseform)¨ |
QFP |
|
R |
|
RAM |
Random Access Memory |
RISC |
Reduced Instruction Set Computer |
ROM |
Read-Only Memory |
rpm |
Revolutions Per Minute (DC Motor, Umdrehungen pro Minute) |
RTC |
Real-Time Clock (Echtzeituhr) |
S |
|
SAR |
Successive Approximation Register |
SCI |
Serial Communications Interface |
SCL |
Serial Clock Line (part of IIC) |
SCK |
System Clock (part of SPI) |
SDA |
Serial Data Line (part of IIC) |
SDI |
Serial Debug Interface |
SO |
Small Outline (casing, Gehauseform)¨ |
SP |
Stack Pointer |
SPI |
Serial Peripheral Interface |
SS |
Slave Select (part of SPI) |
SSP |
Synchronous Serial Port |
SSR |
Solid State Relay |
SRAM |
Static RAM |
T |
|
TCK |
Test Clock (JTAG) |
TDI |
Test Data In (JTAG) |
92 |
APPENDIX A. TABLE OF ACRONYMS |
TDO |
Test Data Out (JTAG) |
TMS |
Test Mode Select (JTAG) |
TQFP |
Thin Quad Plastic Flat Back (casing, Gehauseform)¨ |
TWI |
Two-wire Serial Interface (Atmel’s name for IIC) |
U |
|
UART |
Universal Asynchronous Receiver/Transmitter |
USART |
Universal Synchronous/Asynchronous Receiver/Transmitter |
V |
Very Small Outline (casing, Gehauseform)¨ |
VSO |
|
W |
|
WCET |
Worst-Case Execution Time |