Intermediate
30 min

Measure magnetic flux density in 3-axis with TMAG5170 and ATmega1284P

Stronger with each step

3D Hall 10 Click with EasyAVR v7

Published Nov 01, 2023

Click board™

3D Hall 10 Click

Dev Board

EasyAVR v7

Compiler

NECTO Studio

MCU

ATmega1284P

Detect the strength of a magnetic field in all three dimensions

A

A

Hardware Overview

How does it work?

3D Hall 10 Click is based on the TMAG5170, a 3D linear Hall-effect sensor used to detect the strength of a magnetic field in all three dimensions (X, Y, and Z axes) in a range from ±25mT to ±100mT from Texas Instruments. The high level of integration offers flexibility and accuracy in various industrial and personal electronics applications such as position sensing systems. A precision signal chain and an integrated 12-bit ADC enable high accuracy and low drift magnetic field measurements while supporting a sampling of up to 20ksps. An integrated angle calculation engine (CORDIC) uses two user-selected magnetic axes and provides complete 360°

angular position information for both on- and off-axis angle measurement topologies. The device also features magnetic gain and offset correction to mitigate the impact of system mechanical error sources. 3D Hall 10 Click communicates with MCU through a register-selectable standard SPI interface that enables high clock speed up to 10MHz for any combination of magnetic axes and temperature measurements. The SPI communication features a user-enabled cyclic redundancy check to enhance the data integrity. A dedicated alert pin marked as ALR and routed on the INT pin of the mikroBUS™ socket can act as a system interrupt during low power

Wake-up and Sleep mode and be used by an MCU to trigger a new sensor conversion. Besides, the TMAG5170 offers multiple diagnostics features to detect and report system and device-level failures. This Click board™ can operate with both 3.3V and 5V logic voltage levels selected via the VCC SEL jumper. This way, it is allowed for both 3.3V and 5V capable MCUs to use the communication lines properly. However, the Click board™ comes equipped with a library containing easy-to-use functions and an example code that can be used, as a reference, for further development.

3D Hall 10 Click top side image
3D Hall 10 Click lateral side image
3D Hall 10 Click bottom side image

Features overview

Development board

EasyAVR v7 is the seventh generation of AVR development boards specially designed for the needs of rapid development of embedded applications. It supports a wide range of 16-bit AVR microcontrollers from Microchip and has a broad set of unique functions, such as a powerful onboard mikroProg programmer and In-Circuit debugger over USB. The development board is well organized and designed so that the end-user has all the necessary elements in one place, such as switches, buttons, indicators, connectors, and others. With four different connectors for each port, EasyAVR v7 allows you to connect accessory boards, sensors, and custom electronics more

efficiently than ever. Each part of the EasyAVR v7 development board contains the components necessary for the most efficient operation of the same board. An integrated mikroProg, a fast USB 2.0 programmer with mikroICD hardware In-Circuit Debugger, offers many valuable programming/debugging options and seamless integration with the Mikroe software environment. Besides it also includes a clean and regulated power supply block for the development board. It can use a wide range of external power sources, including an external 12V power supply, 7-12V AC or 9-15V DC via DC connector/screw terminals, and a power source via the USB Type-B (USB-B)

connector. Communication options such as USB-UART and RS-232 are also included, alongside the well-established mikroBUS™ standard, three display options (7-segment, graphical, and character-based LCD), and several different DIP sockets which cover a wide range of 16-bit AVR MCUs. EasyAVR v7 is an integral part of the Mikroe ecosystem for rapid development. Natively supported by Mikroe software tools, it covers many aspects of prototyping and development thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

EasyAVR v7 horizontal image

Microcontroller Overview

MCU Card / MCU

default

Architecture

AVR

MCU Memory (KB)

128

Silicon Vendor

Microchip

Pin count

40

RAM (Bytes)

16384

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
NC
NC
RST
SPI Chip Select
PA5
CS
SPI Clock
PB7
SCK
SPI Data OUT
PB6
MISO
SPI Data IN
PB5
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Alert
PD2
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Schematic

3D Hall 10 Click Schematic schematic

Step by step

Project assembly

EasyAVR v7 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the EasyAVR v7 as your development board.

EasyAVR v7 front image hardware assembly
Buck 22 Click front image hardware assembly
MCU DIP 40 hardware assembly
EasyAVR v7 MB 1 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
NECTO Compiler Selection Step Image hardware assembly
NECTO Output Selection Step Image hardware assembly
Necto image step 6 hardware assembly
Necto DIP image step 7 hardware assembly
EasyPIC PRO v7a Display Selection Necto Step hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto PreFlash Image hardware assembly

Track your results in real time

Application Output

After pressing the "FLASH" button on the left-side panel, it is necessary to open the UART terminal to display the achieved results. By clicking on the Tools icon in the right-hand panel, multiple different functions are displayed, among which is the UART Terminal. Click on the offered "UART Terminal" icon.

UART Application Output Step 1

Once the UART terminal is opened, the window takes on a new form. At the top of the tab are two buttons, one for adjusting the parameters of the UART terminal and the other for connecting the UART terminal. The tab's lower part is reserved for displaying the achieved results. Before connecting, the terminal has a Disconnected status, indicating that the terminal is not yet active. Before connecting, it is necessary to check the set parameters of the UART terminal. Click on the "OPTIONS" button.

UART Application Output Step 2

In the newly opened UART Terminal Options field, we check if the terminal settings are correct, such as the set port and the Baud rate of UART communication. If the data is not displayed properly, it is possible that the Baud rate value is not set correctly and needs to be adjusted to 115200. If all the parameters are set correctly, click on "CONFIGURE".

UART Application Output Step 3

The next step is to click on the "CONNECT" button, after which the terminal status changes from Disconnected to Connected in green, and the data is displayed in the Received data field.

UART Application Output Step 4

Software Support

Library Description

This library contains API for 3D Hall 10 Click driver.

Key functions:

  • c3dhall10_get_alert_pin This function returns the alert (ALR) pin logic state. The alert pin is configured as a conversion complete interrupt by default.

  • c3dhall10_read_data This function reads new data which consists of X, Y, and Z axis values in mT, and temperature in Celsius. It also reads the angle in Degrees between X and Y by default, and magnitude data as well.

  • c3dhall10_write_frame This function writes a desired data to the selected register by using SPI serial interface.

Open Source

Code example

This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.

/*!
 * @file main.c
 * @brief 3DHall10 Click example
 *
 * # Description
 * This example demonstrates the use of 3D Hall 10 click board by reading the magnetic
 * flux density from 3 axes, and the angle and magnitude between X and Y axes  
 * as well as the sensor internal temperature.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the click default configuration.
 *
 * ## Application Task
 * Waits for the conversion complete interrupt and then reads the new data from the sensor 
 * approximately every 100ms and displays the measurement values on the USB UART.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "c3dhall10.h"

static c3dhall10_t c3dhall10;
static log_t logger;

void application_init ( void )
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    c3dhall10_cfg_t c3dhall10_cfg;  /**< Click config object. */

    /** 
     * 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.
    c3dhall10_cfg_setup( &c3dhall10_cfg );
    C3DHALL10_MAP_MIKROBUS( c3dhall10_cfg, MIKROBUS_1 );
    if ( SPI_MASTER_ERROR == c3dhall10_init( &c3dhall10, &c3dhall10_cfg ) )
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( C3DHALL10_ERROR == c3dhall10_default_cfg ( &c3dhall10 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void )
{
    while ( c3dhall10_get_alert_pin ( &c3dhall10 ) );
    
    c3dhall10_data_t sensor_data;
    if ( C3DHALL10_OK == c3dhall10_read_data ( &c3dhall10, &sensor_data ) )
    {
        log_printf( &logger, " X-axis: %.1f mT\r\n", sensor_data.x_axis );
        log_printf( &logger, " Y-axis: %.1f mT\r\n", sensor_data.y_axis );
        log_printf( &logger, " Z-axis: %.1f mT\r\n", sensor_data.z_axis );
        log_printf( &logger, " Angle: %.1f Degrees\r\n", sensor_data.angle );
        log_printf( &logger, " Magnitude: %u\r\n", sensor_data.magnitude );
        log_printf( &logger, " Temperature: %.2f Celsius\r\n\n", sensor_data.temperature );
    }
}

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.