csc270—circuits & systems · 2019-04-02 · d. thiebaut, computer science, smith college...
TRANSCRIPT
![Page 1: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/1.jpg)
mith College
Computer Science
Dominique Thiébaut [email protected]
CSC270—Circuits & Systems
Week 9 — Spring 2019
![Page 2: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/2.jpg)
D. Thiebaut, Computer Science, Smith College
Continue Last Lab
(30 Minutes)
https://xkcd.com/730/
![Page 3: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/3.jpg)
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.
![Page 4: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/4.jpg)
D. Thiebaut, Computer Science, Smith College
Arduino-to-ArduinoCommunication
Arduino-to-ArduinoCommunication
![Page 5: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/5.jpg)
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
![Page 6: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/6.jpg)
D. Thiebaut, Computer Science, Smith College
Outline
• Parallel Communication
• Terminology
• Serial Communication
• Handshake
• Arduino Serial
• I2C
![Page 7: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/7.jpg)
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
![Page 8: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/8.jpg)
D. Thiebaut, Computer Science, Smith College
Protocol forParallel Exchange of Data
STB
ACK
DATA
![Page 9: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/9.jpg)
D. Thiebaut, Computer Science, Smith College
http://theconversation.com/shaking-hands-is-disgusting-heres-what-else-you-can-do-98097
![Page 10: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/10.jpg)
D. Thiebaut, Computer Science, Smith CollegeD. Thiebaut, Computer Science, Smith College
Rule #1: GroundSender and Receiver!
![Page 11: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/11.jpg)
D. Thiebaut, Computer Science, Smith College
Rule #2: Provide a Path for return current
![Page 12: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/12.jpg)
D. Thiebaut, Computer Science, Smith College
Example
• Centronics Interface (old)
![Page 13: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/13.jpg)
D. Thiebaut, Computer Science, Smith College
Features ofParallel Protocol
• When sender and receiver have different speeds?
• Wiring?
• Connectors?
![Page 14: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/14.jpg)
D. Thiebaut, Computer Science, Smith College
Arduino ParallelProtocol Algorithm
![Page 15: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/15.jpg)
D. Thiebaut, Computer Science, Smith College
![Page 16: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/16.jpg)
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)
![Page 17: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/17.jpg)
D. Thiebaut, Computer Science, Smith College
![Page 18: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/18.jpg)
D. Thiebaut, Computer Science, Smith College
Outline
• Parallel Communication
• Terminology
• Serial Communication
• Handshake
• Arduino Serial
• I2C
![Page 19: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/19.jpg)
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
![Page 20: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/20.jpg)
D. Thiebaut, Computer Science, Smith College
QuestionThe parallel protocol
we just saw is…
_________________ &
_________________
Question
![Page 21: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/21.jpg)
D. Thiebaut, Computer Science, Smith College
Serial Communication
![Page 22: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/22.jpg)
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)
![Page 23: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/23.jpg)
D. Thiebaut, Computer Science, Smith College
Bytes Can Be Sent SeriallyEasily
D Q D Q D Q 0
load/shift
![Page 24: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/24.jpg)
D. Thiebaut, Computer Science, Smith College
74LS165
![Page 25: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/25.jpg)
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
![Page 26: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/26.jpg)
D. Thiebaut, Computer Science, Smith College
Sending 1 ByteOver RS232
Voltage
time
![Page 27: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/27.jpg)
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
![Page 28: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/28.jpg)
D. Thiebaut, Computer Science, Smith College
Standard Transmission Speeds
110 300600 12002400 48009600 1440019200 2880038400 5600057600 115200
![Page 29: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/29.jpg)
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)
![Page 30: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/30.jpg)
D. Thiebaut, Computer Science, Smith College
An Example: Using Serial1
ReceiverLaptop
Sender
![Page 31: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/31.jpg)
D. Thiebaut, Computer Science, Smith College
An Example: Using Serial1
![Page 32: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/32.jpg)
D. Thiebaut, Computer Science, Smith College
https://www.youtube.com/watch?v=5y1Sp-PM0_w&feature=youtu.be
An Example: Using Serial1
![Page 33: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/33.jpg)
D. Thiebaut, Computer Science, Smith College
Another Serial Protocol:The I2C Protocol
![Page 34: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/34.jpg)
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)
![Page 35: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/35.jpg)
D. Thiebaut, Computer Science, Smith College
Video 1: I2C
https://www.youtube.com/watch?v=qeJN_80CiMU
![Page 36: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/36.jpg)
D. Thiebaut, Computer Science, Smith College
Video 2: I2C
https://www.youtube.com/watch?v=6IAkYpmA1DQ
![Page 37: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/37.jpg)
D. Thiebaut, Computer Science, Smith College
Open-DrainOpen-Collector
![Page 38: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/38.jpg)
D. Thiebaut, Computer Science, Smith College
Open-DrainOpen-Collector
![Page 39: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/39.jpg)
D. Thiebaut, Computer Science, Smith College
74LS07
![Page 40: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/40.jpg)
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
![Page 41: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/41.jpg)
D. Thiebaut, Computer Science, Smith College
I2C Examplehttps://www.arduino.cc/en/Tutorial/MasterReader
![Page 42: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/42.jpg)
D. Thiebaut, Computer Science, Smith College
Example 1https://www.arduino.cc/en/Tutorial/MasterReader
on Mega 2
560
SDA=Pin 20
SCL=Pin 21
![Page 43: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/43.jpg)
D. Thiebaut, Computer Science, Smith College
Example 1https://www.arduino.cc/en/Tutorial/MasterReader
![Page 44: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/44.jpg)
D. Thiebaut, Computer Science, Smith College
Example 1https://www.arduino.cc/en/Tutorial/MasterReader
![Page 45: CSC270—Circuits & Systems · 2019-04-02 · D. Thiebaut, Computer Science, Smith College Feedback on HW #5 • Make your program test all interesting starting states. Do NOT modify](https://reader034.vdocuments.site/reader034/viewer/2022042115/5e922f688063f37640662255/html5/thumbnails/45.jpg)
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