nfc4 2.0.0.0
Main Page

NFC 4 click

‍NFC 4 Click is a compact add-on board that contains an NFC transceiver for contactless communication. This board features the ST25R3916, a multi-purpose NFC transceiver supporting passive peer-to-peer functionality and NFC card-emulation mode, as well as NFC reader operation from STMicroelectronics. It features high RF output power to directly drive an antenna etched on the PCB, alongside its tuning circuit, at high efficiency.

click Product page


Click library

  • Author : Stefan Filipovic
  • Date : Jul 2021.
  • Type : I2C/SPI type

Software Support

We provide a library for the NFC4 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 NFC4 Click driver.

Standard key functions :

  • nfc4_cfg_setup Config Object Initialization function.
    void nfc4_cfg_setup ( nfc4_cfg_t *cfg );
    void nfc4_cfg_setup(nfc4_cfg_t *cfg)
    NFC 4 configuration object setup function.
    NFC 4 Click configuration object.
    Definition nfc4.h:1157
  • nfc4_init Initialization function.
    err_t nfc4_init ( nfc4_t *ctx, nfc4_cfg_t *cfg );
    err_t nfc4_init(nfc4_t *ctx, nfc4_cfg_t *cfg)
    NFC 4 initialization function.
    NFC 4 Click context object.
    Definition nfc4.h:1130
  • nfc4_default_cfg Click Default Configuration function.
    err_t nfc4_default_cfg ( nfc4_t *ctx );
    err_t nfc4_default_cfg(nfc4_t *ctx)
    NFC 4 default configuration function.

Example key functions :

  • nfc4_get_mifare_tag_uid This function reads the UID of a mifare tag.
    err_t nfc4_get_mifare_tag_uid ( nfc4_t *ctx, uint8_t *uid, uint8_t *uid_len );
    err_t nfc4_get_mifare_tag_uid(nfc4_t *ctx, uint8_t *uid, uint8_t *uid_len)
    NFC 4 get mifare tag UID function.
  • nfc4_write_register This function writes a desired data to the selected register.
    err_t nfc4_write_register ( nfc4_t *ctx, uint8_t reg, uint8_t data_in );
    err_t nfc4_write_register(nfc4_t *ctx, uint8_t reg, uint8_t data_in)
    NFC 4 write register function.
  • nfc4_read_register This function reads a desired data from the selected register.
    err_t nfc4_read_register ( nfc4_t *ctx, uint8_t reg, uint8_t *data_out );
    err_t nfc4_read_register(nfc4_t *ctx, uint8_t reg, uint8_t *data_out)
    NFC 4 read register function.

Example Description

‍This example demonstrates the use of NFC 4 Click board by reading MIFARE ISO/IEC 14443 type A tag UID.

The demo application is composed of two sections :

Application Init

‍Initializes the driver and performs the click default configuration.

void application_init ( void )
{
log_cfg_t log_cfg;
nfc4_cfg_t nfc4_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
nfc4_cfg_setup( &nfc4_cfg );
NFC4_MAP_MIKROBUS( nfc4_cfg, MIKROBUS_1 );
err_t init_flag = nfc4_init( &nfc4, &nfc4_cfg );
if ( ( I2C_MASTER_ERROR == init_flag ) || ( SPI_MASTER_ERROR == init_flag ) )
{
log_error( &logger, " Application Init Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
if ( NFC4_ERROR == nfc4_default_cfg ( &nfc4 ) )
{
log_error( &logger, " Default Config Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}
#define NFC4_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition nfc4.h:859
#define NFC4_SET_DATA_SAMPLE_EDGE
Data sample selection.
Definition nfc4.h:840
void application_init(void)
Definition main.c:31
@ NFC4_ERROR
Definition nfc4.h:1184

Application Task

‍If there's a tag detected, it reads its UID and displays it on the USB UART every 500ms.

void application_task ( void )
{
uint8_t tag_uid[ 10 ] = { 0 };
uint8_t uid_len = 0;
if( NFC4_OK == nfc4_get_mifare_tag_uid( &nfc4, tag_uid, &uid_len ) )
{
log_printf( &logger, " Tag UID: " );
for ( uint8_t cnt = 0; cnt < uid_len; cnt++ )
{
log_printf( &logger, "%.2X", ( uint16_t ) tag_uid[ cnt ] );
}
log_printf( &logger, "\r\n" );
Delay_ms ( 500 );
}
}
void application_task(void)
Definition main.c:74
@ NFC4_OK
Definition nfc4.h:1183

Note

‍For testing purposes we used MIKROE-1475 - an RFiD tag 13.56MHz compliant with ISO14443-A standard.

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.NFC4

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.