“Now let’s discuss some of the reasons why you might want to use a peripheral connected to the MCU via a serial interface and the types of functions available. Data converters provide prime examples of the types of peripherals you might use. One reason you might consider using an external converter is that you might need more precision than the converter integrated on the MCU of your choice can provide.
While engineers often think of microcontrollers (MCUs) in terms of integrating the peripherals required for the application at hand, in many cases, functionality needs to be added outside the MCU. For example, you may need to place sensors or actuators physically close to external devices, away from the MCU. Alternatively, you may find that a low-end MCU combined with some peripherals provides a combination of cost and system footprint for a given application. Regardless, the number of MCU peripherals based on interfaces such as ICs and SPI (Serial Peripheral Interface) is increasing. This article will examine some typical peripherals and how to use them with popular MCUs.
MCUs widely support I²C and SPI. In some cases, you will have to choose one or the other because the MCU uses the same on-chip resources to support IC or SPI. Also, you will need some software to handle the serial bus protocol, but almost every MCU vendor has software support out of the box.
The IC has the advantage of using fewer signal lines and fewer MCU pins. Most implementations have a bidirectional data line and a clock line that support half-duplex communication. Typically, the MCU acts as a master that can connect to multiple slaves, although some implementations do support the flexibility of having multiple masters on the bus. The master uses the address bits to locate a specific slave at the start of a transfer, eliminating the need for a dedicated slave select signal.
An SPI bus usually requires at least three to four wires. SPI uses a separate date line for full-duplex communication. Additionally, it uses dedicated slave select signal lines, so if your system has many SPI peripherals, you can easily drain the I/O ports on the MCU using them as select signals.
SPI usually has higher performance based on higher data transfer speed and full duplex communication. You will find that the SPI clock frequency is in the range of 20 to 40 MHz. Most I²C implementations are in the 10 to 100-kbit/s range, although some implementations use MCUs that run faster.
Motivation and Characteristics
Now let’s discuss some of the reasons why you might want to use a peripheral connected to the MCU via a serial interface and the types of functions available. Data converters provide prime examples of the types of peripherals you might use. One reason you might consider using an external converter is that you might need more precision than the converter integrated on the MCU of your choice can provide.
Consider some of Linear Technology’s converters. The company offers I?CA/D converters, I?CD/A converters, SPI A/D converters and SPI D/A converters. Furthermore, all of these have higher accuracy than the converters integrated on typical MCUs. For example, consider the relatively new Renesas RL78 MCU family, the company’s offering in 16-bit MCUs. Most family members available to date offer 8-bit A/D converters, while some offer 10-bit converters. In contrast, discrete Linear Technology A/D converters have an accuracy range of 8 to 24 bits, and D/A converters have an accuracy range of 8 to 18 bits. Even in 8-bit or 16-bit systems, you can easily have a single sensor that requires higher accuracy.
Consider a specific product example – the LTC245116-bit A/D converter. An I?C-based device is shown in Figure 1. The converter relies on a delta-sigma modulator as the converter core and can perform 30 or 60 conversions per second. The 16-bit converter provides 4 significant bits of full-scale error and sets up multiplexing within one sample conversion time. In addition, the device is very small, measuring 2 x 3 mm, in an 8-pin SOT-23 package.
Figure 1: Linear Technology’s 8-pin LTC2451 A/D converter provides 16-bit precision and connects to the MCU via an I²C serial interconnect.
Small system footprint
External peripherals can also provide a way to achieve a system footprint. This may seem counterintuitive since we usually think of integrating peripherals as the path to miniaturization. But, moving on to data converters, let’s discuss an example of an MCU paired with Microchip’s A/D converter.
Microchip offers a long list of I? CA/D converters as well as D/A converters and SPI-based versions of both. As a specific example, the MCP3021 10-bit A/D converter is based on I²C and uses a successive approximation conversion topology. Housed in a SOT-23 package, this tiny device has only five pins, but it offers more precision than many low-end MCU converters.
You can also choose from 6-pin and 8-pin 8-bit MCUs from Microchip and other suppliers. For example, the Microchip PIC10 MCU family includes many MCUs in the 6-pin SOT-23 package. The combination of a tiny MCU and an equally tiny data converter may be smaller and less expensive than an MCU that integrates a converter that matches your application’s requirements.
What other types of peripherals can you add to an MCU-based design through the serial interface? The list is long. A simple example is an I/O port expander. Many low-end MCUs are pin-constrained. Also, even if you have an MCU with a lot of I/O, you may find that you need to physically place some I/O pins away from the MCU—for example, near sensors.
NXP Semiconductors offers the PCA9502 I/O port expander that works with SPI or I²C masters. The IC provides 8 I/O lines. In addition, it is very compact, measuring 4.1 x 4.1 mm in a SOT616 package. NXP also offers SC16IS740/50/60 UARTs that allow you to add a 5-Mbit/s serial interface to your design. SC16IS750 and SC16IS760 variants also include an 8-bit I/O expander.
Nonetheless, more useful peripherals may be those with application-specific capabilities. For example, Microchip offers a wide range of I²C digital potentiometers. You can use this product with thermistors in temperature sensing applications. Figure 2 depicts an example where a Microchip MPC4018 potentiometer is used to calibrate the thermistor and account for the non-linear operation of the thermistor.
Figure 2: Microchip’s series digital potentiometers can be used in a variety of applications, such as calibrating nonlinear thermistors in the circuit shown.
For more robust temperature-centric applications, Microchip also offers I²C-based temperature sensor ICs. For example, the MCP9808 digital temperature sensor provides ±0.5°C accuracy over a range of C20°C to 100°C. Additionally, the IC is available in a variety of 2 x 3-mm packages.
The range of serial peripherals extends all the way to user interface or human machine interface (HMI) applications. For example, Microchip offers the AR1000 touchscreen controller (Figure 3) that is SPI and I²C compatible. The serial interface links the MCU to the controller. The AR1000 can interface with four-, five-, and eight-wire touchscreen sensors from multiple vendors (Figure 3). The IC provides digital coordinates directly to the MCU through the serial interface.
Figure 3: Microchip AR1000 IC linked to a touch screen sensor for HMI applications.
As you can see, serial interconnects offer considerable flexibility in MCU-based designs. In some cases, SPI and I²C can be purely a useful way to implement functionality that you cannot integrate on an MCU. But don’t limit your consideration of serial buses to such instances. Consider how external peripherals may affect the system footprint, power consumption, and cost. Also, making sure you don’t sacrifice fidelity with long signal runs between on-chip peripherals and the actual interface, local peripherals can add value in terms of fidelity. You may find distributed peripherals have advantages such as a smaller footprint and more accurate system specifications.