Communications How to get something to almost talk to something else Raffi Krikorian

advertisement
Communications
How to get something to
almost talk to something else
Raffi Krikorian
MAS.863
1 December 2003
Getting stuff from A to B
• Over wires
– Traces on a PCB, wire from peripheral to
computer…
• Over the air
– Optical pules, radio waves…
• Inter-media
– Putting it all together
Over wires
Wiring two PICs together
(v1.0)
• Parallel connection
• As many wires as
“simultaneous” bits
• To transmit a 0xF,
bring the lower four
wires high, & the
rest low
Wiring two PICs together
(v2.0)
• Serial connection
• Using minimal
number of wires to
transmit “in time”
• To transmit 0xF (low
bit first), send high
for 4 time units, then
4 low
Parallel vs. Serial
• Really fast
• Usage of large numbers
of pins
– Requires bigger ICs
• Large number of
wires/traces
– Space requirements on
board (imagine modella)
– Large bundle of wires if
off board
• Minimum number of
pins (1 to 3) and wires
• Requires inter-device
agreements and
synchronization
– Speed (baud rate)
– Bit framing
• Requires extra software
or hardware (USART)
Synchronous Serial
• Clock on one wire, and synchronized data on other
• Usually used to connect microcontrollers/processors
to peripherals
• SPI (Serial Peripheral Interface) -- 1 wire for each dir
+ 1 clock wire
• I2C (Inter IC) -- 1 wire for bidirectional data (direction
is handled by protocol) + 1 clock wire
Asynchronous Serial
• Remove the clock wire
• Need way to synchronize clocks due to
clock drift
– Agree on a speed
– Use start bit to start running clocks
– Transmit/Receive data
– Stop clocks
Asynchronous Serial Framing
• Agree on how the bytes/bits are to be sent
• 8N1 : 8 data bits, no parity bit, 1 stop bit
– Parity bits are the check against error
– Stop bit indicate how long the line has to be quiet between
bytes
• Transmit least significant bit (LSB) first
– Above transmitting b’11010110’
Serial standards and ICs
• RS-232
–
–
–
–
MAX202 (pref. 203)
12V levels
15m max cable length
P2P between devices
• RS-485
–
–
–
–
LTC1481
5V differential signals
Kms max cable length
Can be used as multidrop between devices
Serial from the IC
• Hardware USART good
– PIC16F876 has it built in
• Can use external peripheral
– and use some other wired communication
from microcontroller/processor to
peripheral)
• “Bit bang” the serial line
– Rely on a compiler to do this work
USB
•
•
•
•
Universal Serial Bus
12 Mbit/sec
5m cable length
Use http://www.dlpdesign.com/usb/
– Have USB ICs
– Premade boards that have a parallel (DLPUSB245M) and serial (DLP-USB232M)
interface that convert to USB
Over the air
Radio
• Modulate a carrier frequency with data
– AM modulation takes a carrier frequency
and plays with its amplitude
– FM plays with the instantaneous frequency
of the carrier
• AM is relatively simple
– but most “natural noise” is AM
Don’t build a radio!
• Get a chip and just send serial data
• Nordic VLSI nRF401
– Single chip 433MHz
– 200 kbps @ 100 meters
• Texas Instruments TRF6900
– Mostly single chip 900MHz
– 38.4 kbps @ 100 meters
• rfPIC Microcontrollers
– PIC with built in FM transmitters
Infra-red
• Use IR transmitter (diode) and IR
receiver (photoresistor)
• Hook it up like a LED and just turn it on
and off
• Problems with surrounding noise and
base illumination levels
Don’t rebuild IrDA!
• Unless you are doing something really
simple
– Hook IR transceiver to a USART
• MAX3120
– Single chip IRDA modulator : hook one end
to USART other end to IR transceiver
– 115 kbps @ 1 m
802.11b
• Wireless LAN
– 2.4 GHz
– Internet Protocol based radio
– 11 Mbit/sec @ 30 m
• Spoof a PCMCIA bus and just wire yourself
into a Orinoco Gold card
– Saves you from having to get the analogs right
• IOSoft 802.11b development kit for the PIC
– http://www.iosoft.co.uk/wlan2.php
Inter-media
Internet Protocol
• Unreliable packet based protocol
• IPv4 = RFC791
• Addressing
– IPv4 addresses are 4 bytes wide
– Obtain address either statically or via DHCP
– Not necessarily globally unique due to NAT
(waiting for IPv6)
• Routing
IPv4 packet
• The beginning of every IP packet starts with
20 bytes of this header (the options and the
padding are optional)
• “Data” immediately precedes this header
User Datagram Protocol
(RFC768)
• Unreliable packet layer on top of IP
• UDP allows for fast access to send packets
– Packets are small
– Packets are “one-offs”, you send the bytes and are
done
• No flow control, no congestion control, no
guarantees
• Trivial as an implementation
Transmission Control Protocol
(RFC793)
• Creates a virtual “stream” on top of the
Internet
– Reliable, in-order packets
– Uses bandwidth responsibly
• Non-trivial for implementation
• Still areas of research to make it efficient,
determine whether it is a “stable” system
Using IP
• Using IP protocols
• Serial line (over RS-232 or RS-485) or simple
radio
– Probably the best and easiest bet
– SLIP (RFC1055) as packet framing or,
– PPP (RFC 1661) as a control protocol
• Ethernet (CS8900) and 802.11
– Need to implement ARP (RFC826)
Download