The Basics of Inputs and Outputs, Part 2: Understanding Protocols

Updated on 04-Nov-2016

The Arduino 101*/Genuino 101* board is the first development board to be powered by Intel® Curie™technology. It counts with the same peripheral list and controllers as the Arduino* UNO board. Sharing the same physical shape and pin layout as the UNO board, the Arduino 101 board accepts many of the shields that fit in its predecessor; you can also interchange cases and mounts between the two boards.

The Arduino board has a dual-core x86 32-bit Intel® Quark™ processor, which allows for multithreaded applications and enables the use of powerful peripherals that the UNO board did not support. The board’s operating voltage is 3.3 V input/output (I/O), with 5 V tolerance, meaning that you can also connect 5 V components. It has 20 general-purpose I/O (GPIO) pins: 14 digital I/O pins and 6 pins for analog-to-digital conversion (ADC). It is equipped with four pulse width modulation (PWM) pins and three channel logic converters connected to the GPIO pins. The Arduino 101 board has an in-circuit serial programming header with serial peripheral interface (SPI) signals that you can use to access microcontrollers and I2C dedicated pins. With a built-in six-axis accelerometer, gyroscope, and Bluetooth* low energy (Bluetooth* LE), you can easily create Internet of Things (IoT) apps that allow you to use your smartphone to control your board (Figure 1).

Figure 1. Arduino 101* board with Intel® Curie™ technology

ADC and PWM

So, what does all this mean? To understand ADC and PWM, you first need to take a closer look at analog and digital signals. For components to communicate, they must send signals—think of them as messages—that reflect a change of state in a given time. In electronics, the quantity being measured is voltage. How the change takes place is what differentiates these two types of signals. You can represent signals (change in voltage over time) in graphs: Analog signals are shown as smooth, continuous waves given that the transition in voltage is gentle, while digital signals are represented in square waves where there is an “on” (5 V) or “off” (0 V) state only (Figure 2).

Figure 2. Digital (squared) and analog (smooth) signals

Most communication between integrated circuits is digital, and ADC allows microcontrollers to read signals from analog devices. Conversely, digital-to-analog conversion allows the microcontroller to generate an analog signal and communicate with the analog interface. PWM comes into play when you want to control the time variable in a digital signal, allowing for a longer on or off state. The amount of time the signal is on (5 V) is known as duty cycle.

Figure 3 provides a graph representation of various duty cycles. You can alter the time unit to have the on state for a longer or shorter period. The bigger the duty cycle percentage, the longer the LED will be lit and so reducing the time the LED is off (0 V). PWM can be demonstrated using an LED; a common example is the fade effect, where by switching the on and off state very fast, you can mimic analog behavior.

Remember that in analog waves, the transition between on and off is smoother; therefore, to the observer, the LED will seem to fade. In a digital setup, the change is more abrupt, and you will only see the LED rapidly switching between on and off. PWM allows the LED to trick your eye by making it seem as if it’s fading even when using digital signals. On an RGB LED (composed of one red, one green, and one blue LED), each color can be represented at a different percentage, which affects the light’s overall color. If you have green and blue at a 50 percent duty cycle (equal quantities) while red is at 0 percent, the light generated will be teal.

Figure 3. LEDs whose pulse width modulation is set at 50 percent, 25 percent, and 100 percent duty cycles, respectively

Serial Communication: Interintegrated Circuit, SPI, and Universal Asynchronous Receiver/Transmitter

The Arduino 101 board uses serial communication between its microcontrollers and peripherals. In serial systems, you can send only 1 bit at a time, while in parallel communications, you send multiple bits. You can think of serial as a single-lane road and parallel as a multilane highway. SPI and interintegrated circuit (I2C) are serial buses that communicate through digital signals. Think of a bus as a road for data transpiration: Its purpose is to allow communication between multiple master–slave chips, where one device acts as the controller (master) while others are being controlled (slaves; see Figure 4). The board uses I2C for communication with slower, on-board peripherals that it accesses occasionally. It only requires 2 wires to have up to 127 devices, where each receives a unique identifier that the master uses to recognize its slaves. I2C can read and write data from and to many sensors. Synchronous systems require a clock to ensure that the data is written and read at the correct tempo. The master defines which device is performing which action (read/write). The serial clock (SCL) wire provides the clock signal that the master generates, which synchronizes the data transfer between the devices on the I2C bus. The serial data (SDA) is the second wire, and it carries the data flowing through the bus. Because of its simplicity and being a low-bandwidth protocol, it’s a great option for infrequently accessed devices, but it’s slower than SPI.

Figure 4. Interintegrated circuit master–slave bus with serial data and serial clock lines.

SPI allows one master and one or multiple slaves using four signal types. Think of them as four channels (lines) of communications between the masters and slaves:

  • Master-out-slave-in (MOSI). Carries data from master to slave (data line)
  • Master-in-slave-out (MISO). Carries data from the slave to the master (data line)
  • Serial-clock (SCLK). Clock signal that synchronizes the system
  • Slave-select line (SS_). Used to select and enable the slave on the bus; notifies the slave that it should wake up and send or receive data

You can set up SPI in two ways. If all slaves share the same slave-select line, SPI requires a minimum of four wires (MOSI, MISO, SCLK, SS_). Another option is to give each slave have its own SS_ line to connect to the master; here, you need an additional wire per slave. Figure 5 summarizes these two setups.

Figure 5. A serial peripheral interface with one shared slave-select line (SS_) versus each slave with its own SS_ line

When contrasting I2C and SPI, you should also understand the concept of full duplex and half-duplex. Full-duplex communication is where two parties (slave and master in this context) can send data at the same time. In half-duplex communication, one party has to wait until the other is done sending data. Taking a closer look, given that SPI is full duplex, it has an additional data wire compared to half-duplex I2C, where there is only one data line and it can’t send and receive data at the same time (Figure 6).

Figure 6. Serial peripheral interface versus interintegrated circuit communication

In asynchronous systems, there is no clock to dictate when the information is sent. Instead, the sender and receiver must agree on a speed (bit rate) at which the information will be communicated. If the sender is delivering at a faster rate, the receiver won’t be able to understand the data being sent because it will be processing it at a lower tempo. Therefore, it’s essential that you establish a bit rate to effectively use asynchronous communication. The Universal Asynchronous Receiver/Transmitter (UART) is an asynchronous unit now commonly included in microcontrollers, and it acts as an intermediary between parallel and serial interfaces. It’s intended to have two connected devices, where the transmitter’s output, labeled Tx, is connected through a unidirectional data line to the receiver (Rx input; Figure 7). In this fashion, one UART takes bytes of data (1 byte = 8 bits) and transmits each individual bit through the Tx line to the receiving UART (Rx line). On the receiver end, the UART reassembles the bits, generating the byte that was originally sent.

Figure 7. Universal Asynchronous Receiver/Transmitter send and receive bus

Summary

The Arduino 101 board is equipped with a broad array of pins, chips, and other devices that communicate by using synchronous and asynchronous methods. Complex, time-sensitive solutions have been designed to ensure that data is sent, received, and processed correctly. This article explored how PWM, ADC, I2C, SPI, and UART work together to enable communication between microcontrollers and peripherals, helping your IoT projects come to life.

For more such intel IoT resources and tools from Intel, please visit the Intel® Developer Zone

Source:https://software.intel.com/en-us/articles/the-basics-of-inputs-and-outputs-part-2-understanding-protocols

Connect On :