Intermediate
30 min

Enhance your design with NFC Tag technology by using M24LR64E-R and PIC32MZ1024EFH064

Quick exchange of a digitized information

NFC Tag 5 Click with PIC32MZ clicker

Published Mar 03, 2023

Click board™

NFC Tag 5 Click

Dev Board

PIC32MZ clicker

Compiler

NECTO Studio

MCU

PIC32MZ1024EFH064

Transfer data using short-range RF communication

A

A

Hardware Overview

How does it work?

NFC Tag 5 Click is based on the M24LR64E-R, a 64-Kbit dynamic NFC/RFID tag with password protection, energy harvesting, and RF status functions from STMicroelectronics. This highly integrated Near Field Communication tag module comes with a dual-interface electrically erasable programmable memory (EEPROM), an I2C interface alongside an RF contactless interface operating at 13.56MHz, organized as 8192×8 bits in the I2C mode and 2048×32 bits in the ISO 15693 and ISO 18000-3 mode 1 RF mode. This Click board™ contains the properly tuned integrated trace antenna on the PCB to power and access the device using the ISO/IEC 15693 and ISO 18000-3 mode one protocol. Power is transferred to the M24LR64E-R by radio frequency at 13.56MHz via

coupling antennas. As mentioned, this Click board™ communicates with MCU using the standard I2C 2-Wire interface with a maximum clock frequency of 400kHz, fully adjustable through software registers. It also provides an Energy harvesting mode on the analog pin of the mikroBUS™ socket marked as VH. When the Energy harvesting mode is activated, the M24LR64E-R can output the excess energy from the RF field on the VH pin. If the RF field strength is insufficient or when the Energy harvesting mode is disabled, the VH pin goes into a high-Z state, and the Energy harvesting mode is automatically stopped. Besides, it also features a user-configurable pin marked as BSY, routed to the AN analog pin of the mikroBUS™ socket, used either to indicate that the

M24LR64E-R is executing an internal write cycle from the RF channel or that an RF command is in progress. When configured in the RF write in progress mode, the BSY pin is driven low for the entire RF internal write operation duration. When configured in the RF busy mode, this pin is driven low for the whole period of the RF command progress. This Click board™ can operate with either 3.3V or 5V logic voltage levels selected via the VCC SEL jumper. This way, both 3.3V and 5V capable MCUs can 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.

NFC Tag 5 Click top side image
NFC Tag 5 Click lateral side image
NFC Tag 5 Click bottom side image

Features overview

Development board

PIC32MZ Clicker is a compact starter development board 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 with FPU from Microchip, a USB connector, LED indicators, buttons, a mikroProg connector, and a header for interfacing with external electronics. Thanks to its compact design with clear and easy-recognizable silkscreen markings, it provides a fluid and immersive working experience, allowing access anywhere and under

any circumstances. Each part of the PIC32MZ Clicker development kit contains the components necessary for the most efficient operation of the same board. In addition to the possibility of choosing the PIC32MZ Clicker programming method, using USB HID mikroBootloader, or through an external mikroProg connector for PIC, dsPIC, or PIC32 programmer, the Clicker board also includes a clean and regulated power supply module for the development kit. The USB Micro-B connection can provide up to 500mA of current, which is more than enough to operate all onboard

and additional modules. All communication methods that mikroBUS™ itself supports are on this board, including the well-established mikroBUS™ socket, reset button, and several buttons and LED indicators. PIC32MZ Clicker is an integral part of the Mikroe ecosystem, allowing 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.

PIC32MZ clicker double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC32

MCU Memory (KB)

1024

Silicon Vendor

Microchip

Pin count

64

RAM (Bytes)

524288

Used MCU Pins

mikroBUS™ mapper

Energy Harvest
RE4
AN
NC
NC
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
RF Status
RB5
INT
NC
NC
TX
NC
NC
RX
I2C Clock
RD10
SCL
I2C Data
RD9
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Schematic

NFC Tag 5 Click Schematic schematic

Step by step

Project assembly

PIC32MZ clicker front image hardware assembly

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

PIC32MZ clicker front image hardware assembly
Thermo 26 Click front image hardware assembly
Prog-cut hardware assembly
Micro B Connector clicker - 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 via Debug Mode

1. Once the code example is loaded, pressing the "DEBUG" button initiates the build process, programs it on the created setup, and enters Debug mode.

2. After the programming is completed, a header with buttons for various actions within the IDE becomes visible. Clicking the green "PLAY" button starts reading the results achieved with the Click board™. The achieved results are displayed in the Application Output tab.

DEBUG_Application_Output

Software Support

Library Description

This library contains API for NFC Tag 5 Click driver.

Key functions:

  • nfctag5_write_ndef_uri_record This function writes specific NDEF URI record to the memory address specified with NTAG5LINK_NDEF_MESSAGE_START_ADDRESS macro.

  • nfctag5_write_message_to_memory This function writes specified number of data bytes to the user memory starting from @b block_addr.

  • nfctag5_read_message_from_memory This function reads specified number of data bytes from the user memory starting from @b block_addr.

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 NFCTag5 Click example
 *
 * # Description
 * This example demonstrates the use of NFC Tag 5 click board by programming the
 * specified NDEF URI record to the memory, and showing the memory read/write feature.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and logger and performs the click default configuration which 
 * formats its user memory. After that it programs the specified NDEF URI record to the memory.
 *
 * ## Application Task
 * Writes a desired number of data bytes to the memory and verifies that it is written 
 * correctly by reading from the same memory location and displaying the memory content 
 * on the USB UART approximately every 5 seconds.
 *
 * @note
 * Trying to write/read in RF mode (for example, processing NDEF URI record with a smartphone) 
 * while writing to memory over I2C is in progress can interrupt and block the I2C communication. 
 * 
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "nfctag5.h"

/**
 * URL to store to memory as NDEF URI record
 */
#define URI_DATA                "www.mikroe.com/nfc-tag-5-click" 

/**
 * Starting block address to where the text message will be stored
 * Must be > ( NFCTAG5_NDEF_MESSAGE_START_ADDRESS + sizeof ( URI_DATA ) / NFCTAG5_MEMORY_BLOCK_SIZE + 3 )
 * to avoid overwriting NDEF URI record.
 */
#define TEXT_MESSAGE_ADDRESS    0x0100

/**
 * Text message content that will be stored to memory
 */
#define TEXT_MESSAGE            "MikroE - NFC Tag 5 click"

static nfctag5_t nfctag5;
static log_t logger;

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    nfctag5_cfg_t nfctag5_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.
    nfctag5_cfg_setup( &nfctag5_cfg );
    NFCTAG5_MAP_MIKROBUS( nfctag5_cfg, MIKROBUS_1 );
    if ( I2C_MASTER_ERROR == nfctag5_init( &nfctag5, &nfctag5_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( NFCTAG5_ERROR == nfctag5_default_cfg ( &nfctag5 ) )
    {
        log_error( &logger, " Default configuration." );
        for ( ; ; );
    }
    
    if ( NFCTAG5_OK == nfctag5_write_ndef_uri_record ( &nfctag5, NFCTAG5_URI_PREFIX_4, 
                                                       URI_DATA, strlen ( URI_DATA ) ) )
    {
        log_printf( &logger, " NDEF URI record \"https://%s\" has been written\r\n", ( char * ) URI_DATA );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    uint8_t message_buf[ 100 ] = { 0 };
    if ( NFCTAG5_OK == nfctag5_write_message_to_memory ( &nfctag5, 
                                                         TEXT_MESSAGE_ADDRESS, 
                                                         TEXT_MESSAGE, 
                                                         strlen ( TEXT_MESSAGE ) ) )
    {
        log_printf( &logger, " \"%s\" has been written to memory address 0x%.4X \r\n", 
                    ( char * ) TEXT_MESSAGE, ( uint16_t ) TEXT_MESSAGE_ADDRESS );
    }
    if ( NFCTAG5_OK == nfctag5_read_message_from_memory ( &nfctag5,
                                                          TEXT_MESSAGE_ADDRESS, 
                                                          message_buf, 
                                                          strlen ( TEXT_MESSAGE ) ) )
    {
        log_printf( &logger, " \"%s\" has been read from memory address 0x%.4X \r\n\n", 
                    message_buf, ( uint16_t ) TEXT_MESSAGE_ADDRESS );
    }
    Delay_ms( 5000 );
}

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.