Introduction to Communications
Arduinos have several digital pins, which you can attach to many devices. Devices can have more efficient communication with the use of one of several communications protocols and mechanisms. We will look at the UART, I2C, and the SPI Communications.
Most of the long header pins are general purpose input-output pins, providing a good way communicating wtih buttons or LEDs to read the status of a button or potentiometer. What if you need to communicate with a graphics screen or LED, or a 3 axis accelerometer or gyroscope, or even a GPS module? Simple GPIO pins are not sufficient, they are not very efficient. To make it easy to connect such devices to the arduino, we need communications protocols, and the arduino comes with built-in communications protocols, and this is what this article is about.
Looking at the header, there's something more about header functionality other than power and GPIO pins. There are some pins with special markings, like there are SCL, SDA, and pins numbers 0 and 1 are marked as both Rx and Tx. We don't really have any other clues on the other side, other than the functionality of the analog pins as analog pins. We learn that the AT Mega provides UART TTL serial ports, which is attached to specific digital ports 0 and 1, with a TX (transmit) and RX (receive) data, allowing the patterns to happen at the same time. What I'm looking for through this lecture is communications. It's a full duplex type of protocol. These 2 pins are connected or tied together with the serial port that is managed by the At Mega microcontroller port. It is connected to the serial port. When a computer is connected through USB, RX and TX allow the USB port to communicate with the AT Mega on Arduino. However, these 2 pins are available for other devices to use, such as GPS modules. They can communicate with the Arduino Uno via these serial interfaces. Other Arduinos have multiple UART interfaces, such as the Mega 2560. Because it is sometimes necessary to have multiple serial devices communicating, we can implement the same functionality with digital pin pairs and using the software to simulate hardware, which can give us access to more interfaces. Another use is to connect multiple Arduinos together and have them communicate through serial interface.
The AT Mega 328 also supports I2C and SPI communications. I2C or Inter-Integrated Circuit, has been developed by NXP Semiconductors, and is a fast serial interface that allows devices to be connected in a chain fashion, which mean it operates on a bus. In computing, a "bus" is a communications system used to transfer data between multiple components of a computer. The Arduino acts as a master, and the rest of the devices act as slaves, and you can have many, many slaves. This is what I2C or TWI looks like in practice. The implementation of software is fairly simple in high level, since things come up with a special library that makes use of the I2C very simply. There are many devices in the Arduino world that implement I2C and make communications easy in the Arduino world. There is an SCL and SDA line. SCL stands for clock. Like everything else in a computer system, everything depends on a clock. Every time that the clock ticks, the clock is a silver device which is the crystal that is ticking, every second, and every time a clock ticks, a new bit sent over the blue line, because the blue line represents data. Every time a clock ticks, a new bit is sent through the blue line. Every one of the devices needs to have a unique address for a master to send the data to that address. We simply number devices, device number 1, number 2, number 3, etc., and these are unique addresses for each slave. One last thing I want to mention is, how come it is also named TWI? Phillips or NXP semiconductors owns this trademark and I2C is a trademark name that belongs to the particular company. TWI, which is Two Wire Interface, since quantities have 2 wires. A last bit of interesting information is that there are clearly marked pins in the Arduino Uno, but the SDA line is also on pin A4 and SCL line is implemented on pin A5.
The SPI is the Serial Peripheral Interface bus, which can have very fast serial full-duplex communication with external data. Full-duplex communication allows for two devices to communicate so that information flows in both directions at the same tie. The connection between the Arduino and external device happens by connecting 4 wires in a device. Let's have 2 lines representing direction, then a clock line and a slave select. SS is the slave select, SCK is the clock, and the 2 green lines are MOSI and MISO, which basically convey data. MOSI is master output slave input and MISO is Master Input slave output. Let's say we have an SD card reader storing data readings. What you do in this case is that you can share data lines, as well as a clock line, and then need to use another digital pin on the Arduino, and implement a different select line. Thus, the Arduino will be able to talk to one device at a time, so we use slave select to turn on or off one of the SPI slaves. This way, we disable all the devices with the exception of the screen we want to send data to. Just like with I2C, there is an SPI library that ships with Arduino IDE and make communication very very easy, so we don't really need to get to the details of communication, but taken care of the very easy-to-use SPI library.


Comments
Post a Comment