Intermediate
30 min

Capture magnetic field data in 3D with ease using IIS2MDCTR and PIC32MZ2048EFH100

Navigating the magnetic world in 3D

3D HALL 5 click with Flip&Click PIC32MZ

Published Sep 15, 2023

Click board™

3D HALL 5 click

Dev. board

Flip&Click PIC32MZ

Compiler

NECTO Studio

MCU

PIC32MZ2048EFH100

Uncover the versatility of our solution, which allows you to master magnetic fields in three dimensions, enhancing the performance and accuracy of your devices and applications

A

A

Hardware Overview

How does it work?

3D HALL 5 Click is based on the IIS2MDCTR, a low power 3D magnetic sensor, from STMicroelectronics. This sensor relies on a Hall effect to accurately sense magnetic field changes on three perpendicular axes. The internal magnetic field sensing elements are multiplexed and connected to a 16bit low noise Analog to Digital Converter (ADC), which sequentially samples each sensor, providing 16-bit spatial data over the digital interface. An additional thermal sensor is also available, and it is used for thermal compensation. The magnetic sensor has a very low pin count. Therefore, SPI and I2C lines are multiplexed on the same pins. In addition, the SPI data in (SDI) and SPI data out (SDO) share the same pin. In order to allow functionality for both SPI read and SPI write functions, 3D HALL 5 click incorporates another IC: the 74HC4053, a triple 2-channel multiplexer/demultiplexer IC from NXP is used in conjunction with the RST pin of the mikroBUS™, labeled as CSS. This allows to demultiplex the SDI/SDO pin of the IIS2MDCTR and route the two resulting pins to appropriate pins of the mikroBUS™ (SDI and SDO).
The rest of the communication interface selection procedure relies on switching the appropriate SMD jumpers, grouped under the I2C/SPI label. Note that all of the I2C/SPI group jumpers need to be switched at the same side: all three should either be soldered as I2C or SPI. If one of them shows in the opposite position from the rest, the communication with the IC might not be possible. The power consumption is a big concern as of

lately, with the introduction of the IoT. The ability to work in a low power mode is a must for every device which is to be used for any type of IoT networking. The IIS2MDCTR magnetic sensor features two operational modes, with the addition of a low-pass filter (LPF). The power consumption is in a close relationship with the data output refresh rate (ODR). When operated in Low Power mode, and with the LPF and the offset cancelation turned OFF, the power consumption of the sensor alone drops down to 25 μA. Turning on the LPF and the offset cancelation will double the power consumption for the same ODR frequency to 50 μA, which is still in a domain of micropower consumption. However, filtering and offset cancelation options offer less noise and more accurate readings for both high-resolution and low-resolution modes. The IIS2MDCTR magnetic sensor also features a powerful programmable interrupt engine, which allows many event sources to be signaled via the interrupt pin (INT/DRDY), which is routed from the sensor to the mikroBUS™ INT pin. A very useful function of the interrupt engine is the signaling of the data ready event. That way, the host MCU does not have to poll the sensor for the data acquisition. The sensor can simply trigger an interrupt when the data is ready for reading. The interrupt engine allows some other customizations of the interrupt signal, such as the polarity, pulse/latch mode, and so on. The sensor provides raw data output, based on a strength of the magnetic field. The measurement is affected by many factors: slight manufacturing

differences between ICs affect the readings, even the slight differences between Hall plates within the same IC might affect the accuracy, although the IC contains highly matched sensing elements. Also, the altitude might affect the readings, as well as temperature changes. Therefore, the sensor IC is equipped with the thermal sensor, used to measure the influence of the ambient temperature. Unlike errors which occur due to the influence of other parameters, the influence of the temperature is not linear, so a proper firmware development approach by using LUT tables is highly advisable. The power mode, output data rate, interrupt thresholds for each axis, and other working parameters, including the availability of the I2C interface, are contained within the configuration registers of the IIS2MDCTR magnetic sensor. The sensor is highly configurable, with many configuration options. The IIS2MDCTR datasheet contains an in-depth explanation of all the registers and their functionality. However, 3D Hall 5 software library contains simplified functions that allow straight-forward readings to be performed, reducing the steps needed for a proper initialization and configuration of the device. This Click board™ can be operated only with a 3.3V logic voltage level. The board must perform appropriate logic voltage level conversion before using MCUs with different logic levels. Also, it comes equipped with a library containing functions and an example code that can be used as a reference for further development.

3D HALL 5 Click top side image
3D HALL 5 Click bottom side image

Features overview

Development board

Flip&Click PIC32MZ is a compact development board designed as a complete solution that brings the flexibility of add-on Click boards™ to your favorite microcontroller, making it a perfect starter kit for implementing your ideas. It comes with an onboard 32-bit PIC32MZ microcontroller, the PIC32MZ2048EFH100 from Microchip, four mikroBUS™ sockets for Click board™ connectivity, two USB connectors, LED indicators, buttons, debugger/programmer connectors, and two headers compatible with Arduino-UNO pinout. Thanks to innovative manufacturing technology,

it allows you to build gadgets with unique functionalities and features quickly. Each part of the Flip&Click PIC32MZ development kit contains the components necessary for the most efficient operation of the same board. In addition, there is the possibility of choosing the Flip&Click PIC32MZ programming method, using the chipKIT bootloader (Arduino-style development environment) or our USB HID bootloader using mikroC, mikroBasic, and mikroPascal for PIC32. This kit includes a clean and regulated power supply block through the USB Type-C (USB-C) connector. All communication

methods that mikroBUS™ itself supports are on this board, including the well-established mikroBUS™ socket, user-configurable buttons, and LED indicators. Flip&Click PIC32MZ development kit allows you to create a new application in minutes. Natively supported by Mikroe software tools, it covers many aspects of prototyping thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

Flip&Click PIC32MZ double image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC32

MCU Memory (KB)

2048

Silicon Vendor

Microchip

Pin count

100

RAM (Bytes)

524288

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
SDI/SDO Selection
RE2
RST
SPI Chip Select
RA0
CS
SPI Clock
RG6
SCK
SPI Data OUT
RC4
MISO
SPI Data IN
RB5
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt
RD9
INT
NC
NC
TX
NC
NC
RX
I2C Clock
RA2
SCL
I2C Data
RA3
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

3D HALL 5 click Schematic schematic

Step by step

Project assembly

Flip&Click PIC32MZ front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Flip&Click PIC32MZ as your development board.

Flip&Click PIC32MZ front image hardware assembly
GNSS2 Click front image hardware assembly
Prog-cut hardware assembly
Flip&Click PIC32MZ MB1 Access - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Flip&Click PIC32MZ MCU step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

Track your results in real time

Application Output

1. Application Output - In Debug mode, the 'Application Output' window enables real-time data monitoring, offering direct insight into execution results. Ensure proper data display by configuring the environment correctly using the provided tutorial.

2. UART Terminal - Use the UART Terminal to monitor data transmission via a USB to UART converter, allowing direct communication between the Click board™ and your development system. Configure the baud rate and other serial settings according to your project's requirements to ensure proper functionality. For step-by-step setup instructions, refer to the provided tutorial.

3. Plot Output - The Plot feature offers a powerful way to visualize real-time sensor data, enabling trend analysis, debugging, and comparison of multiple data points. To set it up correctly, follow the provided tutorial, which includes a step-by-step example of using the Plot feature to display Click board™ readings. To use the Plot feature in your code, use the function: plot(*insert_graph_name*, variable_name);. This is a general format, and it is up to the user to replace 'insert_graph_name' with the actual graph name and 'variable_name' with the parameter to be displayed.

Software Support

Library Description

This library contains API for 3D HALL 5 Click driver.

Key functions:

  • c3dhall5_get_axis_data - Axis data

  • c3dhall5_set_offset - Set offest

  • c3dhall5_get_interrupt_state - Interrupt state

Open Source

Code example

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.

/*!
 * \file
 * \brief 3dHall5 Click example
 *
 * # Description
 * The Demo application displays and reads 3 magnetic axes.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Configuring clicks and log objects.
 * Reads device ID for check communication.
 *
 * ## Application Task
 * Reads the magnetics X / Y / Z axis data every 1 seconds.
 *
 * *note:*
 * Default communication that is set is I2C communication.
 * If you want to use SPI, you have to set up the cfg structure.
 *
 * \author Katarina PerendicS
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "c3dhall5.h"

// ------------------------------------------------------------------ VARIABLES

static c3dhall5_t c3dhall5;
static log_t logger;

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;
    c3dhall5_cfg_t cfg;
    uint8_t device_id;

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, "---- Application Init ----" );

    //  Click initialization.

    c3dhall5_cfg_setup( &cfg );
    C3DHALL5_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    c3dhall5_init( &c3dhall5, &cfg );

    c3dhall5_default_cfg ( &c3dhall5 );

    device_id = c3dhall5_get_device_id ( &c3dhall5 );
    log_info( &logger, "** Device ID: 0x%x", device_id );
}

void application_task ( void )
{
    int16_t axis_x;
    int16_t axis_y;
    int16_t axis_z;

    //  Task implementation.

    axis_x = c3dhall5_get_axis_data( &c3dhall5, C3DHALL5_AXIS_X );
    axis_y = c3dhall5_get_axis_data( &c3dhall5, C3DHALL5_AXIS_Y );
    axis_z = c3dhall5_get_axis_data( &c3dhall5, C3DHALL5_AXIS_Z );

    log_printf( &logger, "----- AXIS -----\r\n" );
    log_printf( &logger, "** X: %d \r\n", axis_x );
    log_printf( &logger, "** Y: %d \r\n", axis_y );
    log_printf( &logger, "** Z: %d \r\n", axis_z );
    log_printf( &logger, "----------------\r\n" );

    Delay_ms( 1000 );
}

void main ( void )
{
    application_init( );

    for ( ; ; )
    {
        application_task( );
    }
}


// ------------------------------------------------------------------------ END

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.