mith College
Computer Science
Dominique Thiébaut [email protected]
CSC270—Circuits & Systems
Week 9 — Spring 2019
D. Thiebaut, Computer Science, Smith College
Continue Last Lab
(30 Minutes)
https://xkcd.com/730/
D. Thiebaut, Computer Science, Smith College
Feedback on HW #5
• Make your program test all interesting starting states. Do NOT modify and restart by hand. While this is fine for a handful of cases, it is better to let the program do all the work, not the programmer!
• The second part asked to change the design. Once the change is made, verify that it will work as you expect using the Python simulator.
D. Thiebaut, Computer Science, Smith College
Arduino-to-ArduinoCommunication
Arduino-to-ArduinoCommunication
D. Thiebaut, Computer Science, Smith College
Sources forMaterial Covered
• Chapter 7 of Programming in C for the Arduino by Julien Bayle (https://doc.lagout.org/programmation/C/
C%20Programming%20for%20Arduino%20%5BBayle%202013-05-17%5D.pdf)
• Serial Communication: https://www.arduino.cc/en/Tutorial/MultiSerialMega
• I2C: wire library: https://www.arduino.cc/en/reference/wire
D. Thiebaut, Computer Science, Smith College
Outline
• Parallel Communication
• Terminology
• Serial Communication
• Handshake
• Arduino Serial
• I2C
D. Thiebaut, Computer Science, Smith College
Parallel CommunicationSender
STB ACK
D0 D1 D2 D3 D4 D5 D6 D7
GND
Receiver
STB ACK D0 D1 D2 D3 D4 D5 D6 D7
GND
D. Thiebaut, Computer Science, Smith College
Protocol forParallel Exchange of Data
STB
ACK
DATA
D. Thiebaut, Computer Science, Smith College
http://theconversation.com/shaking-hands-is-disgusting-heres-what-else-you-can-do-98097
D. Thiebaut, Computer Science, Smith CollegeD. Thiebaut, Computer Science, Smith College
Rule #1: GroundSender and Receiver!
D. Thiebaut, Computer Science, Smith College
Rule #2: Provide a Path for return current
D. Thiebaut, Computer Science, Smith College
Example
• Centronics Interface (old)
D. Thiebaut, Computer Science, Smith College
Features ofParallel Protocol
• When sender and receiver have different speeds?
• Wiring?
• Connectors?
D. Thiebaut, Computer Science, Smith College
Arduino ParallelProtocol Algorithm
D. Thiebaut, Computer Science, Smith College
D. Thiebaut, Computer Science, Smith College
QuestionHow fast could twoArduinos transfer a byte
from one to the other,using this parallel
protocol?
P.S. You know enough to answer in bytes/second (approximately)
D. Thiebaut, Computer Science, Smith College
D. Thiebaut, Computer Science, Smith College
Outline
• Parallel Communication
• Terminology
• Serial Communication
• Handshake
• Arduino Serial
• I2C
D. Thiebaut, Computer Science, Smith College
Terminology• Synchronous vs asynchronous communication
• Synchronous: a clock signal is sent along with the data for the receiver to recognize each data word
• Asynchronous: no clock signal is sent.
• Simplex, half-duplex, and full-duplex
• Simplex: unidirectional only
• half-duplex: bidirectional, but only one dir at a time
• full-duplex: bidirectional, both directions at the same time
D. Thiebaut, Computer Science, Smith College
QuestionThe parallel protocol
we just saw is…
_________________ &
_________________
Question
D. Thiebaut, Computer Science, Smith College
Serial Communication
D. Thiebaut, Computer Science, Smith College
Many Protocols
• RS232 (old, but defines serial comm)
• USART: Universal Synchronous/Asynchronous Receiver/Transmitter (https://www.arduino.cc/en/Tutorial/MultiSerialMega)
• I2C (https://www.arduino.cc/en/Tutorial/MasterWriter)
• SPI (https://www.arduino.cc/en/Reference/SPI)
• USB (https://en.wikipedia.org/wiki/USB)
D. Thiebaut, Computer Science, Smith College
Bytes Can Be Sent SeriallyEasily
D Q D Q D Q 0
load/shift
D. Thiebaut, Computer Science, Smith College
74LS165
D. Thiebaut, Computer Science, Smith College
RS-232• See Serial Port on Wikipedia (https://
en.wikipedia.org/wiki/Serial_port)
• Old. Created in 1960
• Can be implemented with 3 wires (although the standard called for a 25- or 9-pin connector)
TxD
RxD
GND
TxD
RxD
GND
D. Thiebaut, Computer Science, Smith College
Sending 1 ByteOver RS232
Voltage
time
D. Thiebaut, Computer Science, Smith College
8-N-1: Most Common
• 8 = number of data bits
• N = No Parity
• 1 = 1 Stop bit
• Typical use: 9600/8N1
D. Thiebaut, Computer Science, Smith College
Standard Transmission Speeds
110 300600 12002400 48009600 1440019200 2880038400 5600057600 115200
D. Thiebaut, Computer Science, Smith College
Arduino-to-ArduinoCommunication Using USARTs
• Serial 0: 0(RX), 1(TX) USB to laptop
• Serial 1: 19(RX), 18(TX)
• Serial 2: 16(RX), 17(TX)
• Serial 3: 15(RX), 14(TX)
D. Thiebaut, Computer Science, Smith College
An Example: Using Serial1
ReceiverLaptop
Sender
D. Thiebaut, Computer Science, Smith College
An Example: Using Serial1
D. Thiebaut, Computer Science, Smith College
https://www.youtube.com/watch?v=5y1Sp-PM0_w&feature=youtu.be
An Example: Using Serial1
D. Thiebaut, Computer Science, Smith College
Another Serial Protocol:The I2C Protocol
D. Thiebaut, Computer Science, Smith College
Features• Serial communication over a bus
• 100KHz standard (100,000 bits/sec). 400KHz, 1MHz, 3.4MHz also possible, but will depend on processor speed.
• 3 wires: clock, data, ground
• 1 controller/many peripherals
• Up to 127 peripherals
• One to one communication ("Master/Slave")
• Automatic error detection (ensure correct byte exchange)
D. Thiebaut, Computer Science, Smith College
Video 1: I2C
https://www.youtube.com/watch?v=qeJN_80CiMU
D. Thiebaut, Computer Science, Smith College
Video 2: I2C
https://www.youtube.com/watch?v=6IAkYpmA1DQ
D. Thiebaut, Computer Science, Smith College
Open-DrainOpen-Collector
D. Thiebaut, Computer Science, Smith College
Open-DrainOpen-Collector
D. Thiebaut, Computer Science, Smith College
74LS07
D. Thiebaut, Computer Science, Smith College
Recap for I2C Communication
1. Get address of device to communicate with on I2C Bus
2. Get addresses of registers in device that contains the bytes (read or write)
3. Write sketch (Use the "Wire" library on Arduino, #include <Wire.h>)
4. In loop() function:
1. Initiate communication. Specify address of device to talk with
2. Write or read to/from device
3. Close communication
D. Thiebaut, Computer Science, Smith College
I2C Examplehttps://www.arduino.cc/en/Tutorial/MasterReader
D. Thiebaut, Computer Science, Smith College
Example 1https://www.arduino.cc/en/Tutorial/MasterReader
on Mega 2
560
SDA=Pin 20
SCL=Pin 21
D. Thiebaut, Computer Science, Smith College
Example 1https://www.arduino.cc/en/Tutorial/MasterReader
D. Thiebaut, Computer Science, Smith College
Example 1https://www.arduino.cc/en/Tutorial/MasterReader
D. Thiebaut, Computer Science, Smith College
Modern SerialInterface: USB
• Started 1996 (USB 1.0)
• For data and power (5V)
• High Speed (1.5Mbits/s —> 40GBits/s)
• Several Layers of Software
• Exchanges data in packets
• Uses some form of Acknowledge