nfc 2.1.0.0
Main Page

NFC click

‍NFC click is a mikroBUS™ add-on board with a versatile near field communications controller from NXP — the PN7120 IC. NFC devices are used in contactless payment systems, electronic ticketing, smartcards, but also in retail and advertising — inexpensive NFC tags can be embedded into packaging labels, flyers or posters.

click Product page


Click library

  • Author : Stefan Ilic
  • Date : Mar 2023.
  • Type : I2C type

Software Support

We provide a library for the NFC Click as well as a demo application (example), developed using MikroElektronika compilers. The demo can run on all the main MikroElektronika development boards.

Package can be downloaded/installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Library Description

‍This library contains API for NFC Click driver.

Standard key functions :

  • nfc_cfg_setup Config Object Initialization function.
    void nfc_cfg_setup ( nfc_cfg_t *cfg );
    void nfc_cfg_setup(nfc_cfg_t *cfg)
    NFC configuration object setup function.
    NFC Click configuration object.
    Definition nfc.h:292
  • nfc_init Initialization function.
    err_t nfc_init ( nfc_t *ctx, nfc_cfg_t *cfg );
    err_t nfc_init(nfc_t *ctx, nfc_cfg_t *cfg)
    NFC initialization function.
    NFC Click context object.
    Definition nfc.h:272
  • nfc_default_cfg Click Default Configuration function.
    void nfc_default_cfg ( nfc_t *ctx );
    void nfc_default_cfg(nfc_t *ctx, control_packet_t *ctrl_pck)
    NFC default configuration function.

Example key functions :

Example Description

‍This is an example which demonstrates the usage of NFC Click board.

The demo application is composed of two sections :

Application Init

‍Initializes driver and logger, then performs hardware reset, puts the device in operating mode by disabling standby mode, performs test procedure, and configures the device to start discovery.

void application_init ( void )
{
log_cfg_t log_cfg;
nfc_cfg_t nfc_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
nfc_cfg_setup( &nfc_cfg );
NFC_MAP_MIKROBUS( nfc_cfg, MIKROBUS_1 );
err_t init_flag = nfc_init( &nfc, &nfc_cfg );
if ( I2C_MASTER_ERROR == init_flag )
{
log_error( &logger, " Application Init Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
log_printf( &logger, " HW Reset \r\n" );
nfc_hw_reset( &nfc );
Delay_ms ( 100 );
log_printf( &logger, "-----------------------\r\n" );
log_printf( &logger, " Reset and Init. Core \r\n" );
Delay_ms ( 100 );
Delay_ms ( 100 );
Delay_ms ( 100 );
Delay_ms ( 100 );
while ( nfc_check_irq( &nfc ) == NFC_IRQ_STATE_HIGH );
log_printf( &logger, "-----------------------\r\n" );
log_printf( &logger, " Disabling Standby Mode \r\n" );
Delay_ms ( 100 );
Delay_ms ( 100 );
log_printf( &logger, "-----------------------\r\n" );
log_printf( &logger, "Starting Test Procedure\r\n" );
Delay_ms ( 100 );
Delay_ms ( 100 );
nfc_hw_reset( &nfc );
Delay_ms ( 100 );
log_printf( &logger, "-----------------------\r\n" );
log_printf( &logger, " NFC Config. \r\n" );
log_printf( &logger, "-----------------------\r\n" );
log_printf( &logger, " Discovery Start \r\n" );
Delay_ms ( 100 );
Delay_ms ( 100 );
log_printf( &logger, "-----------------------\r\n" );
log_printf( &logger, "-------- START --------\r\n" );
log_printf( &logger, "-----------------------\r\n" );
Delay_ms ( 500 );
log_info( &logger, " Application Task " );
}
#define NFC_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition nfc.h:258
#define NFC_IRQ_STATE_HIGH
Definition nfc.h:202
void nfc_read_ctrl_packet_data(nfc_t *ctx, control_packet_t *ctrl_pck)
Read control packet data function.
void nfc_cmd_core_reset(nfc_t *ctx)
Core reset command function.
void nfc_cmd_start_discovery(nfc_t *ctx)
Start discovery command function.
void nfc_cmd_core_init(nfc_t *ctx)
Core init command function.
uint8_t nfc_check_irq(nfc_t *ctx)
Check IRQ ststus function.
void nfc_cmd_test_procedure(nfc_t *ctx)
NFC test procedure command function.
void application_init(void)
Definition main.c:69
void display_packet(control_packet_t *ctrl_pck)
NFC display packet function.
Definition main.c:194
control_packet_t ctrl_pck_data
Definition main.c:37
void nfc_test_antenna(nfc_t *ctx, control_packet_t *ctrl_pck)
NFC test antena function.
Definition main.c:276

Application Task

‍NFC Click board can be used for detection of RFiD tag and displays it's value via USART terminal. All data logs write on USB uart changes for every 1 sec.

void application_task ( void )
{
while ( nfc_check_irq( &nfc ) == NFC_IRQ_STATE_HIGH )
{
}
while ( nfc_check_irq( &nfc ) == NFC_IRQ_STATE_LOW );
log_printf( &logger, "-----------------------\r\n" );
Delay_ms ( 1000 );
}
#define NFC_IRQ_STATE_LOW
NFC IRQ state.
Definition nfc.h:201
void application_task(void)
Definition main.c:164
void nfc_read_nfc_data(nfc_t *ctx, control_packet_t *ctrl_pck)
NFC read nfc data function.
Definition main.c:241

The full application code, and ready to use projects can be installed directly from NECTO Studio Package Manager(recommended way), downloaded from our LibStock™ or found on Mikroe github account.

Other Mikroe Libraries used in the example:

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.NFC

Additional notes and informations

Depending on the development board you are using, you may need USB UART click, USB UART 2 Click or RS232 Click to connect to your PC, for development systems with no UART to USB interface available on the board. UART terminal is available in all MikroElektronika compilers.