Building Blocks of the 4-20 mA Industrial Ecosystem: SPI to Current Loop

This DigiKey workbench demo is a bridge between microcontrollers and industrial automation. It demonstrates an SPI-controlled 4-20 mA current loop using a Microchip PIC microcontroller and a Texas Instruments XTR116. This is a reference design teardown of the MIKROE 4-20 mA Click board. The analysis shows why the parts were chosen, allowing you to evaluate technology and then incorporate select portions of the circuitry directly onto your next PCB. Figure 1 presents the workbench demo including power supply, a process meter, a PIC Curiosity development platform, and a collection of 4-20 mA Click boards.

Key Takeaways

  • A microcontroller can drive an industrial 4-20 mA loop by sending SPI data through an isolated signal chain: MCU → digital isolator → DAC → XTR116 transmitter → loop output.

  • The MIKROE 4-20 mA Click board is best understood as a compact reference design, not just a plug-in module. It demonstrates isolation, digital-to-analog conversion, loop-current modulation, surge protection, and polarity protection.

  • Bench testing with a Fluke 789 showed loop-current stability within approximately ±0.02 mA while also making small temperature-driven drift visible.


This article is part of the DigiKey Field Guide for Industrial Automation

Location: Understand It → Industrializing Microcontroller-Based Designs
Difficulty: :gear: Engineer — difficulty levels explained
Author: Aaron Dahlen | MSEE | Senior Applications Engineer, DigiKey
Last update: 28 May 2026


Figure 1: A process meter is used to verify the performance of the microcontroller-based 4-20 mA current loop.

Prerequisite Reading

This is a continuation of the analog 4-20 mA transmitter article which provides a detailed workbench-centric description of the XTR116. That article addressed several important aspects of the XTR116 that will not be addressed here.

  • Lack of galvanic isolation between the current loop output and the sensor / signal processing side. This is not a deficit of the XTR116 as most products in this class are designed to electrically float the sensor-side circuitry. Actually, this is a benefit as it allows us to explore the Analog Devices ADuM1411 quad-channel digital isolator.

  • The XTR116 consolidates circuitry. In addition to the 4-20 mA loop processing, it also contains a precision voltage reference and a 5 VDC regulator. Both are used in the MIKROE Click board. These voltages are essential for the 12-bit DAC and the output side of the quad isolator.

  • Like most products, the XTR116 requires an external pass transistor. This is necessary as the current loop operates like a linear amplifier dissipating a considerable amount of power. It could dissipate over 0.8 W in a worst case situation of 20 mA while being driven by an objectionably high 40 VDC power supply. In the article I proposed that the BD139 or even a TIP41 is a reasonable solution.

  • The 4-20 mA output requires surge protection in the form of a capacitor and TVS.

Workbench Setup

Figure 1 shows the simple setup consisting of:

  • Microchip Curiosity MIKRO board
  • PIC16F13145 microcontroller
  • B&K Precision DC power supply
  • Fluke 789 Process meter

The PIC was programmed to increment the loop current by 0.1 mA every 5 seconds.

Workbench Results

The measured current remained within ± 0.02 mA. However, this setup is precise enough to see the impact of temperature changes on the XTR116. Placing a finger on the XTR116 was enough to cause a small shift in the 0.001 mA range. It was exciting to see that an increase in temperature drove the measured system to near zero error as measured by the Fluke process meter. For a more drastic change, freeze spray can be used or a few drops of liquid air from an inverted spray can.

Tech Tip: We can take pleasure in obtaining a near zero error. However, this is not particularly important in an industrial environment where the temperature can swing from Arctic cold to steam-pipe hot. As a designer, we either live with the temperature coefficient of the XTR116’s voltage reference or add a higher performance model.

Signal Path of the MIKROE Click Board

The MIKROE board has the following signal flow. Be sure to reference the official schematic.

  • Analog Devices ADuM1411: Quad-channel digital isolator provides galvanic isolation between the microcontroller and the industrial current loop. Three of the isolators are used for the SPI signal including CS_NOT, SCK, and MOSI.

  • Microchip MCP4921: The 12-bit DAC converts the SPI to a physical voltage where full scale is 4.096 VDC as determined by the voltage reference of the XTR116.

  • Texas Instruments XTR116: This is the 4-20 mA current-loop transmitter. It is a linear device that accepts a voltage and modulates the loop current. Note that we said “modulates” not “provides,” as the transmitter does not provide loop current as explained in the prerequisite article.

  • Loop interface and protection circuitry including the pass transistor, suppression capacitor, TVS, and a full bridge rectifier.

Isolating the SPI Signals

The Analog Devices ADuM1411 is a four-channel digital isolator based on air core transformer technology. It provides kV level isolation while allowing Mbps signaling. In Figure 2 we see the three units passing data left to right and one right to left. This is a good solution for the SPI signals. We have three signals (CS_NOT, SCK, and MOSI) flowing from the microcontroller to the device. And a single MISO signal flowing from device to uC. Note that the MISO connection is not used in this application. In the Click board schematic, we see that Vi_D is tied to ground.

Optical coupling is often used to isolate the sensitive logic from the harsh industrial environment. Yet, here we are presented with a unique technology. To understand why let us turn to the Analog Devices datasheet where we find this justification give in terms or high speed data transfer. lowered parts count, and lower power consumption.

Note that the ADuM1411 requires two galvanically isolated sources of power. On the microcontroller side, we see VDD1 and GND1. On the industrial loop side, we see VDD2 and GND2.

  • Power for the microcontroller domain side is provided directly by the microcontroller’s power supply.

  • In this application power for the current loop domain is provided by the 5 VDC output of the XTR116. The DAC is also fed by this power supply.

For clarity, we say that the DAC and XTR116 float relative to the microcontroller with isolation provided by the ADuM1411. These domains must never be electrically bridged, or the isolation is broken, thereby exposing the sensitive microcontroller to the harsh industrial environment.

Figure 2: Block diagram of the Analog Devices ADuM1411 with transformer coupling between sections.

DAC Precision Using the 4.096 VDC Reference

The Microchip MCP4921 is workhorse single-channel 12-bit DAC. It features a SPI input and an analog output that swings between 0 VDC and the reference voltage applied to pin 6.

In the prerequisite article, we stated that the XTR116 transmitter provides circuit integration eliminating many required components. This includes both a 5 VDC regulator and a precision 4.096 VDC voltage reference. The utility of this integration is perfectly demonstrated by the connection to the MCP4921 DAC as it utilizes both of the XTR116’s outputs.

Note that the 4.096 VDC is a natural fit for the 12-bit DAC. The Power-of-Two friendly voltage reference equates to a nominal 1 mV per count. This translates into clean integer numbers in the microcontroller such as 800 for a current output of 4 mA from the XTR116.

Demonstration Code

The helper functions for the Microchip MCP4921 DAC are included in Listing 1. This is straightforward Microchip PIC code that refuses to use floats. Instead, the representation of loop current is stored in the ‘current_tenths_mA’ variable. Instead of float values such as ‘12.0’, we see the integer ‘120’. An oscilloscope screen capture of the SPI signals is included as Figure 3. This related article shows how to interface the Digilent Analog Discovery with the Click boards.

void MCP4921_Write(uint16_t dac_value)
{
    uint8_t SPIBufferData[MCP4921_SPI_BUFFER_SIZE];
    uint16_t command;

    dac_value &= 0x0FFF;          // Keep only 12 bits
    command = 0x3000 | dac_value; // 1x gain, active output

    SPIBufferData[0] = (uint8_t)(command >> 8);
    SPIBufferData[1] = (uint8_t)(command & 0xFF);

    CS_NOT_SetLow();     
    SPI1_BufferExchange(SPIBufferData, MCP4921_SPI_BUFFER_SIZE); 
    CS_NOT_SetHigh(); 
}



void C420MAT_SetCurrentTenths_mA(uint16_t current_tenths_mA)
{
    uint16_t dac_value;

    /* 4.0 mA  -> current_tenths_mA = 40  -> DAC = 800
     * 20.0 mA -> current_tenths_mA = 200 -> DAC = 4000
     */
    dac_value = 20 * current_tenths_mA;

    if (dac_value >= 800 && dac_value <= 4095)  // FIXME: Add error handling code as opposed to silently holding the last known value. 
    {
        MCP4921_Write(dac_value);
    }
}

Listing 1: Functions used to communicate with the Microchip MCP4921.

Figure 3: Oscilloscope screen capture of the SPI signal.

Next Steps

Industrial control systems provide a natural laboratory from which to explore hardened microcontroller-based designs. There are two avenues for study including the circuit function and the isolation methods used to protect the sensitive microcontroller. In this article we see the elegant optimization of the XTR116 as well as the isolation provided by the ADuM1411.

As a starting point, consider other compact reference designs. As an example, consider the MAX14912EVKIT#. It may look like a simple octal relay driver but it has unexpected active clamp circuitry that will ignite your latent semiconductor theory knowledge.

:books: Continue Exploring Industrial Control Systems

If this discussion was helpful, you may also want to explore:

:world_map: DigiKey Navigation

:japanese_symbol_for_beginner: Related Foundational Articles

About This Author

Aaron Dahlen, LCDR USCG (Ret.), is a Senior Applications Engineer at DigiKey in Thief River Falls. His background in electronics and industrial automation was shaped by a 27-year military career as both technician and engineer, followed by over a decade of teaching.

Dahlen holds an MSEE from Minnesota State University, Mankato. He has taught in an ABET-accredited electrical engineering program, served as coordinator of an electronic engineering technology program, and instructed military technicians in component-level repair.

Today, he has returned to his home in northern Minnesota, completing a decades-long journey that began with a search for capacitors. Read his story here.