Microchip | The Embedded Control Solutions Company Register Login
Browse All
Microchip Technology
 369 Code Snippets

MikroElekronika Multimeter Click using the SPI module on the PIC18LF45K42

Microchip Technology

Check out this project's MPLAB Xpress Webpage to view the complete code example along with a detailed step by step write-up and description, or visit the PIC18LF45K42 Device Product Page for more information.

About this Code Example


This example demonstrates how to use MPLAB Xpress IDE to interface the MikroElektronika Multimeter click board using the Serial Peripheral Interface (SPI) module on the PIC18FxxK42 family. The objective is to create a PIC powered Curiosity HPC “multimeter” that can measure resistance, current, voltage, and capacitance. The raw data is transferred over the SPI bus and then will be arithmetically processed for each mode and then transmitted through the UART module to a serial terminal display.


In this project, we will be using the Curiosity HPC Development Board, MikroElektronika Multimeter click board, and MikroElektronika USB UART click board. The microcontroller used in this example is PIC18LF45K42 and MikroElektronika USB UART click board is used for the USB to UART serial communication.

The Multimeter Click is equipped with an MCP3204. This is a four channel 12-bit Analog-to-Digital Converter (ADC).

The purpose of this example is to capture the raw measurement values from the inputs of the click board and transfer them to the microcontroller using the SPI interface. Once the microcontroller has received the raw measurements, the arithmetic calculations related to each measurement type is performed. The final data of the measurement is then sent to a serial terminal on the computer using the UART module. The EEPROM is used to store the calibration data for the resistance measurement mode.

Resistance measurement

A voltage divider circuit is used with different division ratios for different ranges to measure the resistance.

Current measurement

A small resistor (0.1 ohms) is connected in series to the circuit that contains the unknown current being measured. The voltage drop across the small resistor is measured using a differential amplifier. The current is then calculated in software from the raw analog value using the other principals of Ohm’s Law.

Voltage measurement

A differential amplifier is used to measure both positive and negative voltages up to around 17 volts DC.

Capacitance measurement

An NE555 precision timer is used to generate impulses with the frequency of 585Hz. The unknown capacitor connected to the terminals changes the frequency of the astable multivibrator. A frequency to voltage converter circuit is used to convert this signal to voltage.

MPLAB Code Configurator (MCC) Setup

As mentioned earlier, we use the PIC18LF45K42 for this example. This device family is supported in MPLAB Code Configurator (MCC). MCC is a graphical tool that can be used to quickly setup peripherals on a device and generate basic driver code. In this project we will setup the SPI module to communicate with the MCP3204 ADC chip, UART module to communicate with the MCP2200 and the EEPROM module to store the calibration data. There is pin configuration that is also associated with these modules that is shown below.

System Module Settings

Interrupt Module Settings

SPI Settings

UART Settings

EEPROM Settings

Pin Module Settings

Pin Manager Settings


Calibration routine

Switch 2 (S2) of the Curiosity HPC is used to initiate the calibration routine during startup. In the calibration routine, the short circuit values in the resistance measurement mode are read and stored in the EEPROM of the microcontroller. Then, in the resistance calculation routine, the calibration values are implemented for better accuracy.

Calibration routine can be initiated by the following steps:

  1. Connect a zero-ohm resistor to the Resistor Measurement Terminal of the Multimeter Click
  2. Reset the device using the Reset Switch of the Curiosity HPC while holding down the Switch S2
  3. If the calibration routine is successful, LED D2 will blink till S2 is released
  4. Then the application goes to the resistance measurement routine

Note: If the calibration routine is not performed, the application goes to resistance measurement routine by default

Measurement routine

Switch 1 (S1) of the Curiosity HPC is used to switch between different measurement modes. There are four LEDs on the Curiosity HPC that are used to show which mode is currently working. D2, D3, D4, and D5 represent Resistance, Current, Voltage, and Capacitance measurement respectively.

The terminal application used for this example is Tera Term, although any terminal application should work. The figure below illustrates the UART/Serial Port Setup in Tera Term.

The figures below show what the serial output from the PIC18LF45K42 should look like in the different measurement modes. The application returns Resistance (Ohm), Current (A), Voltage (V), and Capacitance (F).






Release History

  • Dec 4, 2018

    Version: 1.0.0

    Initial Release

Download Contact the Developer

*Required Fields

  • Current Version:1.0.0
  • Created:Dec 4, 2018
  • Updated:Dec 4, 2018
  • Downloads:427
  • C Compiler:XC8 (v2.00)
  • Development Tools:Curiosity High Pin Count (HPC) Development Board
  • Supported Devices:PIC18LF45K42

Corporate News


Stay Connected

Stay up to date with the latest news from Microchip Technology.