Intermediate
30 min

Enhance access control and security measures with PN5180A0HN and ATmega32

Your world, just a touch away: Embrace the NFC experience

NFC 3 Click with EasyAVR v7

Published Nov 01, 2023

Click board™

NFC 3 Click

Dev Board

EasyAVR v7

Compiler

NECTO Studio

MCU

ATmega32

Step into a future where NFC simplifies and enhances your daily life, offering the convenience of secure payments and instant data sharing

A

A

Hardware Overview

How does it work?

NFC 3 Click is based on the PN5180A0HN, a high-performance multiprotocol full NFC frontend from NXP Semiconductors, for contactless communication at 13.56MHz. The PN5180A0HN implements the RF and all the low-level functionality, like an antenna driving and receiver circuitry, to realize an NFC Forum-compliant reader. It utilizes an outstanding modulation and demodulation concept for different contactless communication methods and protocols. The PN5180A0HN is fully compliant with many Reader/Writer standards like ISO 14443A/B up to 848 kBit/s, JIS X 6319-4 comparable with FeliCa scheme, ISO 15693, ISO 18092, and more. Alongside support for reading all NFC tag types (type 1, 2, 3, 4A, and 4B) and high RF output power, this Click board™ is ideally suited for industrial and consumer NFC applications like industrial, eGov readers, payment terminals, and more. This Click board™ connects to a host MCU with an SPI

interface for configuration, NFC data exchange, and high-level NFC protocol implementation. It supports the most common SPI Mode 0 and operates with data rates up to 7 Mbit/s. The PN5180A0HN has two types of integrated memories: RAM and EEPROM. Internal registers of the PN5180A0HN store configuration data, while the RF configuration for dedicated RF protocols is defined by EEPROM data, copied by a command issued from the host MCU. This allows users to achieve maximum RF performance from a given antenna design. In addition to the SPI interface signals, this board uses several other signals from the mikroBUS™ socket. The reset pin routed on the RST pin of the mikroBUS™ socket provides the general reset ability, while the IRQ pin of the mikroBUS™ socket represents an interrupt request to inform the host controller of various events. The PN5180A0HN also has the possibility of updating the implemented firmware. In Secure

Firmware update mode, the PN5180A0HN requires dedicated physical handling of the SPI interface lines and the BSY line of the mikroBUS™ socket. The BSY signal is used to indicate that the PN5180A0HN is not able to send or receive data over the SPI interface. The secure firmware download mode is entered by setting the AUX pin to a high logic state during the Start-Up sequence of the device. The AUX pin is allowed for any other functionality after Start-Up (as test signals provided by test points on the board); the level of this pin has no impact on the download functionality after Start-Up during standard NFC operation. 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.

NFC 3 Click top side image
NFC 3 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)

32

Silicon Vendor

Microchip

Pin count

40

RAM (Bytes)

2048

Used MCU Pins

mikroBUS™ mapper

FW Download Request
PA7
AN
Reset / ID SEL
PA6
RST
SPI Select / ID COMM
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
BUSY Indicator
PD4
PWM
Interrupt
PD2
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
NC
NC
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

NFC 3 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

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 NFC 3 Click driver.

Key functions:

  • nfc3_read_card_uid - NFC 3 read card UID function.

  • nfc3_read_firmware_version - NFC 3 reading firmware version function.

  • nfc3_read_eeprom_version - NFC 3 reading EEPROM version function.

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 main.c
 * @brief NFC3 Click example
 *
 * # Description
 * This example demonstrates the use of NFC 3 Click board 
 * by reading MIFARE ISO/IEC 14443 type A tag UID.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes driver and logger, then enables the click board and reads 
 * the device product, firmware and eeprom versions.
 *
 * ## Application Task
 * If there's a tag detected, it reads its UID and displays it on USB UART.
 *
 * @note
 * Only tags with 4-byte or 7-byte UIDs are compatible with this example.
 * We recommend MIKROE-1475 - an RFiD tag 13.56MHz compliant with ISO14443-A standard.
 * 
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "nfc3.h"

static nfc3_t nfc3;
static log_t logger;
static uint16_t info;

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    nfc3_cfg_t nfc3_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.

    nfc3_cfg_setup( &nfc3_cfg );
    NFC3_MAP_MIKROBUS( nfc3_cfg, MIKROBUS_1 );
    err_t init_flag = nfc3_init( &nfc3, &nfc3_cfg );
    if ( init_flag == SPI_MASTER_ERROR ) 
    {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );
        for ( ; ; );
    }

    nfc3_reset ( &nfc3 );
    Delay_ms( 100 );
    
    log_printf( &logger, "------------------------\r\n" );
    nfc3_read_product_version ( &nfc3, &info );
    log_printf( &logger, "Product version: 0x%.4X\r\n", info );
    nfc3_read_firmware_version ( &nfc3, &info );
    log_printf( &logger, "Firmware version: 0x%.4X\r\n", info );
    nfc3_read_eeprom_version ( &nfc3, &info );
    log_printf( &logger, "EEPROM version: 0x%.4X\r\n", info );
    log_printf( &logger, "------------------------\r\n" );
    log_info( &logger, " Application Task " );
    log_printf( &logger, "------------------------\r\n" );
    Delay_ms( 1000 );
}

void application_task ( void ) 
{
    uint8_t uid[ 7 ];
    uint8_t uid_len;
    uid_len = nfc3_read_card_uid( &nfc3, uid );
    if ( uid_len > 0 )
    {
        log_printf( &logger, "Tag UID: " );
        for ( uint8_t cnt = 0; cnt < uid_len; cnt++ )
        {
            log_printf( &logger, "0x%.2X ", ( uint16_t ) uid[ cnt ] );
        }
        log_printf( &logger, "\r\n------------------------\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.