Networking and CommunicationsFor this assignment I had two options in mind: serial communication or I²C. With serial communication you have no master/slave relationship but you can only connect two boards quite easy.You need four wires between them ( Miso, Mosi, SCK, CS(1,2,)).
I²C (Inter-Integrated Circuit) is a multi-master and multi-slave serial communication bus invented by Philips Semiconductor in the 1990s with only two bus lines (SDA-Data Line and SCL-Serial Clock Line) instead of four. In difference to UART 'Universal Asynchronous serial Receiver and Transmitter' which needs in its bidirectional form TXD, RXD and GND as data lines, the I²C bus drivers are 'open drain'. It means that the connection lines have to be pulled down for signal, from 1 to 0. The lines are powered by 5V and waiting for transmitting. One bit is send when the the closed line opens, and the lines are pulled down to zero. Through clock regulation the slaves can hold the zero position for a while to extend the communication. I²C is available since 2006 without licence fees for a lot of applications.
handbook of I²C from NXP Semiconductors former Pilips Semiconductors. I also used some explanations in the internet as follows: I²C-bus.org or I²C Protokoll this pdf you can download is written in German for schools.
Basic FunctionBelow you can see, how the boards are wired and that they need a pull-up resistor to Vcc to keep the lines high.
Some central commands:
Wiring up an I²C busFirst I wanted to set up one master and one slave board and make a first trial with Arduino program.
I changed the design of my fabkitaleks board a bit and inserted Atmega328p instead of Atmega328 to make it easier for programming with Arduino.
You can download board and schematic files here:
Then I looked up for Arduino Pin settings to get I²C wired.
I opend both arduino sketches, master and slave. Below you can see the main structure of master sketch and slave sketch. With this sketch a LED is blinking for two seconds.
I've programmed master and slave as seen below, with my programmer.
The LED is blinking: two seconds on and half a second off.
Downlod 'Master' and 'Slave' Arduino sketches: Master, Slave. In the Master sketch I included one more slave optionally. You can choose to extend your Slave program to two or to delete the second one within your Master sketch.