Microcontroller Interfacing
Microcontroller Interfacing
Microcontroller Interfacing
16301 Blue Ridge Road, Missouri City, Texas 77489 USA Telephone: 1-713-283-9970 Fax: 1-281-416-2806 E-mail: [email protected] Web: www.bipom.com
Overview
Micro-controllers are useful to the extent that they communicate with other devices, such as sensors, motors, switches, keypads, displays, memory and even other micro-controllers. Many interface methods have been developed over the years to solve the complex problem of balancing circuit design criteria such as features, cost, size, weight, power consumption, reliability, availability, manufacturability. Many microcontroller designs typically mix multiple interfacing methods. In a very simplistic form, a micro-controller system can be viewed as a system that reads from (monitors) inputs, performs processing and writes to ( controls ) outputs.
Input Devices Microcontroller Output Devices
Microcontroller Interfaces
Digital
Analog
On/Off
Parallel
Serial
Voltage
Current
Page 2
Digital Inputs/Outputs
On/OFF control and monitoring. Advantages Simplest interface Lowest-cost to implement (built into the microcontroller) High speed Low programming overhead Disadvantages Only on/off control/monitoring Short distance, few feet maximum. Single device control/monitoring
Columns
Columns
P2.5
1
P2.4 P2.3 P2.2 P2.1 P2.0
2 5 8 0
3 6 9 #
A B C D
4 7 *
Rows
Page 3
LED's
P0.3 P0.2 P0.1 P0.0
7407
P1.4
Page 4
Analog Inputs/Outputs
Voltage-based control and monitoring. Disadvantages Advantages Simple interface Low cost for low-resolutions High speed Low programming overhead High cost for higher resolutions Not all microcontrollers have analog inputs/outputs built-in Complicates the circuit design when external ADC or DAC are needed. Short distance, few feet maximum.
Analog Interface
Vcc
Amplifier Potentiometer
Vcc
Strain-gage
4-20mA Output
Page 5
Parallel Bus
Consists of multiple digital inputs/outputs. Most common types: 4-bit 8-bit ( e.g. Centronics ) 16-bit ( e.g. ISA ) 32-bit ( e.g. PCI ) Disadvantages Large number of microcontroller pins that needed for implementing the parallel bus
Advantages High speed High throughput: Several bits are transmitted on one clock transition Low cost
D7 D6 D5 D4 D3 D2 D1 D0 E R/W RS
Hello World
P0.7 P0.6 P0.5 P0.4 P0.3 P0.2 P0.1 P0.0 P2.2 P2.1 P2.0
D7 D6 D5 D4 D3 D2 D1 D0 E R/W RS
Hello World
Page 6
2.2K
2.2K
A0 A1 A2
Lithium Battery
Page 7
Data Validity
Data can change while the clock is low. Data should remain stable while the clock is going high.
Acknowledge (ACK)
Page 8
P0, P1, P2 indicate the page number ( 2Kbit pages ). A0, A1, A2 indicate the device number on the bus.
Reading a byte from a serial EEPROM (24C04 ) on the I2C bus ( starting from the current address )
Example:
Page 9
MMC Interface
P3.5 P3.7 CS DIN DOUT P3.3 P3.4 CLK
Page 10
1-wire
Originated by Dallas Semiconductor ( now part of MAXIM ) to address a variety of peripherals, sensors, and memory chips from a single wire interface ( DATA and Ground ). One signal wire carries both operating power and signal. Usually the network is built using a wire pair where one wire carries the signal and power and the other wire is ground. The system is sensitive to the right timing to operate well. Advantages Multiple slave devices can be accessed with only 2 wires Low-cost Implemented in hardware or software Ease to implement, many examples Relatively long distance. Theoretically 300 meters but this is limited in practice due to noise and cable capacitance
Disadvantages Slow speed 1-wire slave devices typically has to come from one source: Dallas Semiconductor
For more information on the 1-wire bus, please refer to BiPOM Application Note: Temperature Measurements with 1-Wire Bus Sensors http://www.bipom.com/applications/ds18xx_app.pdf
Page 11
RS232
Asynchronous communications Advantages Popular interface with many examples Many compatible legacy devices Relatively long distance, 50 feet maximum for low baud rates although longer distances work in practice, with low baud rates and error correction Immune to noise due to +/-5 Volts or higher voltage levels for logic 0 and 1 Implemented in hardware or software Ease to implement, many examples Disadvantages More suitable for system to system communications, not so much for chip to chip or chip to sensor Low speed for long distance, 115200 baud can be achieved with small microcontrollers using short distances Requires transceiver chips which add to system cost ( TTL/CMOS level RS232 can be used without transceiver chips ). Single master/single slave
Page 12
RS485 Asynchronous communications Advantages Popular interface with many examples Very long distance, thousands of feet Immune to noise due to differential voltage Implemented in hardware or software Ease to implement, many examples Widely used in industrial automation Higher speeds beyond 115200 baud Disadvantages More suitable for system to system communications, not so much for chip to chip or chip to sensor Requires transceiver chips and twisted pair cable with terminating resistors which add to system cost.
RS485 Network Topology: Any station can communicate with any other station, but not at the same time.
Correct termination resistor that matches the characteristic impedance of the cable is very important in RS485. Otherwise, reflected waves will result in distortions of the original waveform to the point where data errors occur.
Page 13
Ethernet
Advantages Very high speed ( 10Mbit to 100Mbit/s ) Very long distance, hundreds of feet can be achieved, more with hubs and switches Immune to noise Widely used in industrial automation due to noise immunity Disadvantages Cost More suitable for system to system communications, not so much for chip to chip/sensor Requires Ethernet chipset, transformer, jack and special cabling that add to system cost. Complicated to implement High code footprint
Page 14
Appendix A: Comparison of Serial Digital Data Networks ( from MAXIM website: www.maxim-ic.com )
1-Wire Network Concept Number of Signal Lines Optional signals Network Size single master, multiple slaves 1 (IO) N/A Up to 300 m (with suitable master circuit) open drain, resistive or active master pull-up From 2.8 to 6.0 V, device specific I C* multiple masters, multiple slaves 2, (SCL, SDA) N/A Limited by max. 400pF bus capacitance requirement
2
SMBUS
SPI
MicroWire/PLUS single master, multiple slaves 4, (CS\, DI, DO, SK) N/A
M-Bus (EN1434)
CAN (ISO11898)
LIN Bus single master, multiple slaves 1 (LIN) N/A Up to 40m, max. 10nF total load open drain, resistive master pull-up 8 to 18V VDD-related level: <20%, >80% of VDD (driver spec.)<40%, >60% of VDD (receiver spec.) LS bit first, halfduplex
multiple masters, single master, multiple slaves multiple slaves 2, (SMBCLK, SMBDAT) SMBSUS#, SMBALERT# Limited by max. 400pF bus capacitance requirement 4, (CS\, SI, SO, SCK) N/A
single master, multiple multiple masters, slaves multiple slaves 2 (lines can be swapped) N/A Max. 350m per segment of max. 250 slaves; max. 180nF M to S: voltage drive S to M: current load ~40V Master to slave: 24V, 36V nominalSlave to master: <1.5mA, >11mA LS bit first, halfduplex, acknowledge response 8 bits (primary address), 64 bits (secondary address) 2 (CAN_H, CAN_L, terminated) 2nd GND, Power, Shield 40m @1M bps1000m @ 50k bps (example) Differential open drain/source or open coll./emitter VDD-VD (diode drop); ~4.5V max. Differential: <50mV (recessive), >1.5V (dominant); driver specification MS bit first, half-duplex
open drain, resistive open drain, Push-pull with or active master resistive or active tristate pull-up master pull-up From 1.8 to 5.5V, device specific Fixed level: >1.5V, >3.0 V VDD-related level: <30%, >70% of VDD MS bit first plus Acknowledge bit, half-duplex 7 bits, (10 bits defined but not implemented) N/A; slave addresses hardcoded in firmware Standard: ~0 to 100k bps; Fast: ~0 to 400k bps; HighSpeed: ~0 to 3.4M bps 2.7V to 5.5V From 1.8V to 5.5V, device specific VDD-related level: <20% (30%), >70% of VDD (inconsistent)
Push-pull with tristate From 1.8V to 5.5V, device specific Fixed level: <0.8V, >2.0V; VDD-related level: <20% (30%), >70% (80%) of VDD (inconsistent) MS bit first, full-duplex
Logic Thresholds
<0.8V, >2.1V
Transmission
MS bit first plus MS bit first, fullAcknowledge bit, duplex half-duplex 7 bits, (10 bits defined but not implemented) ARP, Address Resolution Protocol (Rev. 2.0 only) N/A
Address Format
56 bits
N/A
Message identifier 11 Message identifier 8 bits (standard format), bits, including 2 parity 29 bits (extended bits format) N/A; message-based protocol, not address based N/A; message-based protocol, not address based
Network Inventory
Automatic, supports dynamic topology change Standard: ~0 to 16.3k bps Overdrive: ~0 to 142k bps) Standard: ~ 5.4ms Overdrive: ~0.6ms (at maximum speed) 8-bit and 16-bit CRC Yes, through nonmatching CRC Parasitic (typical), VDD (exception)
N/A; slave select N/A; slave select (CS\) (CS\) hard-coded hard-coded in firmware in firmware
Automatic
~0 to 1M bps
Access Time
Standard: ~95sFast: ~95s @ 100k ~23s(at maximum bps speed) N/A Yes (multi-master operation only) VDD only PEC Packet Error Code (Rev.1.1, 2.0) Yes (Rev. 2.0 only) VDD only
N/A
N/A
Primary address, 2400 bps: 13.75ms (short frame), 27.5ms (long frame) Even parity, check sum, frames Yes ("medium" and "strong" collisions) Parasitic and/or local supply
At 1M bps 19s At 20k bps 1.7ms (standard) or 39s from start of frame to (extended) from start 1st data bit of frame to 1st data bit 15-bit CRC, frames, frame acknowledge Yes: CSMA/CD VDD only, local or remote source Check sum, frames Yes, through check sum Parasitic only