# Networking and Communications  Based on [Erwin's](https://fabacademy.org/2021/labs/waag/students/kooi-erwin/teaching/slides/) slides --- ## Connecting stuff - Getting data from here to there and back again - From many sensors to microcontrollers to displays - In FabAcademy networking often 1 main microcontroller and multiple secondaries (sensors, LEDs, displays) --- ## Topology : Star - Main has 1:1 connection to all secondaries  - UART, SPI --- ## Topology : Ring - Addressing depends on position in the ring - Output of one secondary is connected to the input of the next secondary  - Neopixels, SPI --- ## Topology : Bus  - I2C, WiFi --- ## Protocols – UART - Asynchronous - No clock - Rx / Tx with fixed speed - Synchronization rules - 9600,8,n,1 - 9600 baud (bit/s) - 8 data bits - no parity bit - 1 stop bit  --- ## Protocols – UART - Parity for 1‑bit error detection (no correction) - P = d0 ⊕ d1 ⊕ d2 ⊕ d3 ⊕ d4 ⊕ d5 ⊕ d6 ⊕ d7  0 for even | 1 for odd --- ## Protocols – UART **RS232** - UART with ±15 V levels **RS485** - UART with differential signals - Full duplex (4 wires) / Half duplex (2 wires) --- ## Protocols – UART - Differential signals + twisted wires for lower EMC  --- ## Protocols – UART (AVR MPCM) - Lame claim to fame: AVR’s MPCM - Multi Processor Communication Mode - 8-bit address with this-is-an-address bit - Upon receiving an address, each µC checks the address - Only the addressed µC switches to regular receive - All others remain in MPCM and wait till the next address - All implemented in hardware - limited interruption on running code - limited impact on memory and program size --- ## Protocols – SPI - Serial Peripheral Interface - Invented by Motorola - Main ↔ secondary connections (MISO/MOSI) - (Main Input Secondary Output) - High data-rate - Clock for data synchronization - Uses CS (chip select) to specify which receiver to talk to  --- ## Protocols – SPI Or use daisy-chaining to send all data in one stream to all receivers (same principle as NeoPixels)  --- ## Protocols – SPI Mode 0: - CPOL = 0 - MOSI rising edge - MISO falling edge  [More Info](https://www.analog.com/en/analog-dialogue/articles/introduction-to-spi-interface.html ) --- ## Protocols – SPI Used often for: - Flash memory - SD cards - Displays - Accelerometer --- ## Protocols – I2C - Inter‑IC Communication (Invented by Philips) - Mostly fixed 7‑bit addresses Example PCA9555: - 0100\
\
\
R/W - Range 0100000x–0100111x - 10‑bit addresses also possible  --- ## Protocols – I2C - Instead of just sending bits (like UART or SPI), addressing and an operation is required - Receivers acknowledge successful reception - Sender in control of the bus  --- ## Protocols – I2C  [More Info](https://learn.adafruit.com/working-with-i2c-devices) [More Info 2](https://www.analog.com/en/analog-dialogue/articles/i2c-communication-protocol-understanding-i2c-primer-pmbus-and-smbus.html) --- ## Bus pull-up / pull-down  - Good practice to fix bus levels to ensure a valid signals - Value depends on speed - Rules of thumb: - SPI: 10 kΩ pull‑down (mode 0) - I2C: 4.7 kΩ pull‑up --- ## Bus termination - Long communication wires (many meters) or wires carrying high frequency (many kHz) signals must be terminated to prevent reflections and provide a good impedance - Wires behave like capacitor + resistor (low‑pass filter) --- ## OSI layers 1. Physical 2. Datalink 3. Network 4. Transport 5. Session 6. Presentation 7. Application --- ## TCP/IP - Transmission Control Protocol / Internet Protocol - Invented by DARPA for highly resilient communication - Defined in IETF RFCs  --- ## TCP/ - IP address (routable) - Subnet - Default gateway - Underlying MAC addresses (non‑routable) --- ## TCP/IP – Addresses - IPv4 example: **95.216.151.48** - IPv6: **2a10:3780:2:52:185:93:175:46** --- ## TCP/IP – Subnet and beyond - Subnet defines local network scope - Common mask: **255.255.255.0** or /24 - Calculate if destination IP is local or not - Example: - My IP: 192.168.1.1/24 - Destination: 95.216.151.48 --- ## TCP/IP – Subnet and beyond Calculate if destination is local or not 11000000.10101000.00000001.00000001 my IP 11111111.11111111.11111111.00000000 subnet → 11000000.10101000.00000001.00000000 network addr 01011111.11011000.10010111.01100000 dest IP 11111111.11111111.11111111.00000000 subnet → 01011111.11011000.10010111.00000000 network addr --- ## TCP/IP – Subnet and beyond Calculate if destination is local or not 11000000.10101000.00000001.00000000 01011111.11011000.10010111.00000000 XOR 10011111.01110000.10010110.00000000 - If not zero, then not local - Send packet to default gateway --- ## TCP/IP – Subnet and beyond Default gateway - Knows where to ask for non-local IP addresses - An IP address on the local network  --- ## TCP/IP over Ethernet  --- ## TCP/IP over Ethernet - MAC address: unique interface identifier - Physical (RJ45), WiFi, or virtual - ARP (Address Resolution Protocol) for finding link between IP address and MAC address - Example: - "Who has 10.1.3.254? Tell c4:03:a8:86:a1:14" - Response: "10.1.3.254 is at 14:fe:b5:db:e6:ab" --- ## TCP/IP – Services - ARP – Address Resolution Protocol - BGP – Border Gateway Protocol - DNS – Domain Name System - DHCP – Dynamic Host Configuration Protocol (beware 169.254.0.0/16) - NTP – Network Time Protocol --- ## Assignment Check FabAc Schedule and weekly page