PN7160 NXP-NCI MCUxpresso for VS Code Example Project for MCXA156
Introduction
This document provides a guide on how to integrate the FRDM-MCXA156 as a host for the PN7160 using the examples provided in the “PN7160 NXP-NCI MCUXpresso Example Project” package. The hardware required to follow this guide is:
FRDM-MCXA156 development board as host MCU.
OM27160A1/OM27160B1 (PN7160 EVK) as the NFC controller.
MCUxpresso for VS code extension
Software setup.
PN7160 NXP-NCI MCUXpresso Example Project version: 1.2
MCXN947 SDK version: 26.06
PN7160 version: 12.50.11.
Hardware connections.
When using OM27160B1 (SPI Host Interface):
The FRDM-MCXA156 schematic document is available on this page.
In the case of SPI connections, to use PN7160 directly with the Arduino headers a rework is needed for the FRDM because SDO(MOSI) and SS (Chip select) are not connected as default (as shown in the next figure). You should move R59 and R60 from pad 2 to pad 3 to enable these connections.
Habib_MS_0-1781809327131.pngHabib_MS_0-1781809327131.png
Note: You can connect the SPI pins available in Mikro bus header with jumpers, but in this example, the signals are routed through the pins enabled by the rework configuration.
Once clarified this, these are the pins used in this example.
Name
PORT
I2C0_SDA
P0_16
I2C0_SCL
P0_17
LPSPI1_SDI
P2_16
LPSPI1_SDO
P2_13
LPSPI1_SCK
P2_12
LPSPI1_SS
P2_6
IRQ
P1_15
VEN
P1_14
REQ
P3_16
Software Changes
This section describes the software changes required to run an “NXP-NCI2.0” example with the MCXA156, which consists in a detection loop that displays in a terminal information (like UID, SAK, and Product Type for MIFARE product-based cards) about any tag detected by the PN7160.
To begin the integration, we first need to import a hello_world project from the FRDM-MCXA156 SDK (v26.06.00) into MCUXpresso IDE for VS Code. For this purpose, download and install the FRDM-MCXA156 repository (version 26.06) using the extension available in the Quickstart panel by selecting Import Repository. For more information about this process, you can consult the corresponding guide.
Importing NCI2.0 examples
Download the “PN7160 NXP-NCI MCUXpresso Example Project” zip from the product page and extract in a known folder. This will be useful for later use.
Importing base project
1. In the Quick Start panel click on “Import Example from Repository” in VS code.
Habib_MS_1-1781809359168.pngHabib_MS_1-1781809359168.png
2. Select “FRDM-MCXA156” in board setting.
Habib_MS_1-1785802139304.pngHabib_MS_1-1785802139304.png
3. In the template will search for the “hello_world” example, select Freestanding Applications, chose the location and click on “import”.
Habib_MS_0-1785802110562.pngHabib_MS_0-1785802110562.png
Importing SDK drivers
Once the project is added to the workspace we will need to add the required drivers, which are the SPI driver in case the OM27160B1HN is being used, or the I2C driver if the OM27160A1HN is being used. For this we need to add the following code in the prj.cfg file.
Habib_MS_0-1781809845396.pngHabib_MS_0-1781809845396.png
Spoiler (Highlight to read) CONFIG_MCUX_COMPONENT_driver.lpi2c=y
CONFIG_MCUX_COMPONENT_driver.lpspi=y CONFIG_MCUX_COMPONENT_driver.lpi2c=y
CONFIG_MCUX_COMPONENT_driver.lpspi=y
Add the example source code to the newly created MCXA156 project
Delete the hello_world.c of the project files folder of the MCXA156 project. From the “NXP-NCI2.0_iMXRT1170_examples” extracted just drag and drop in the project files folder the following files and folders.
Habib_MS_0-1781809900813.pngHabib_MS_0-1781809900813.png
Habib_MS_1-1781809927413.pngHabib_MS_1-1781809927413.png
When you drag and drop a file into VS code a window will appear asking whether you want to link the file or copy it. Please select “Copy files.”
Habib_MS_2-1781809983781.pngHabib_MS_2-1781809983781.png
The project folder should look like this:
Habib_MS_3-1781810001861.pngHabib_MS_3-1781810001861.png
After dragging and dropping all the files, the CMakeLists.txt file is automatically updated to include all the copied .c files. An example of this is shown below:
Habib_MS_4-1781810063910.pngHabib_MS_4-1781810063910.png
However, .h files are not automatically linked, so they must be added manually. Please copy and paste the following includes into the CMakeLists.txt file:
Habib_MS_5-1781810096008.pngHabib_MS_5-1781810096008.png
Spoiler (Highlight to read) mcux_add_include(
BASE_PATH ${CMAKE_CURRENT_LIST_DIR}
INCLUDES tool
TML
NfcLibrary/inc
NfcLibrary/NdefLibrary/inc
INCLUDES NfcLibrary/NxpNci20/inc
.
)
mcux_add_include(
BASE_PATH ${CMAKE_CURRENT_LIST_DIR}
INCLUDES tool
TML
NfcLibrary/inc
NfcLibrary/NdefLibrary/inc
INCLUDES NfcLibrary/NxpNci20/inc
.
)
Preprocessor Interface macro
Depending on the interface to be used to communicate with the PN7160, a preprocessor macro must be defined in the CMakelist.txt
BOARD_NXPNCI_INTERFACE_SPI (For using SPI with OM27160B1)
BOARD_NXPNCI_INTERFACE_I2C (For using I2C with OM27160A1)
Additionally, it is necessary to add the macro called REMOVE_P2P_SUPPORT. Please make sure that this Macro is included.
Spoiler (Highlight to read) mcux_add_macro(
CC "BOARD_NXPNCI_INTERFACE_I2C=1\
REMOVE_P2P_SUPPORT=1") mcux_add_macro(
CC "BOARD_NXPNCI_INTERFACE_I2C=1\
REMOVE_P2P_SUPPORT=1")
Note: The following sections are exemplified using the SPI interface (BOARD_NXPNCI_INTERFACE_SPI macro).
After making the modifications described below, the interface used by the example can be changed simply by setting the macro to BOARD_NXPNCI_INTERFACE_I2C.
Board definitions
In the board.h file we will add the following definitions in order to refer to the different peripherals and clocks to be used, you can find this file in the following path:
{PrjRootDirPath}\ frdmmcxa156\frdmmcxa156\board.h
Habib_MS_1-1781810404448.pngHabib_MS_1-1781810404448.png
Spoiler (Highlight to read) #ifdef BOARD_NXPNCI_INTERFACE_I2C
#define BOARD_NXPNCI_I2C_CLOCK (CLOCK_GetLpi2cClkFreq(0U))
#define BOARD_NXPNCI_I2C_INSTANCE (LPI2C0)
#define BOARD_NXPNCI_I2C_BAUDRATE (100000)
#define BOARD_NXPNCI_I2C_ADDR (0x28)
#endif
#ifdef BOARD_NXPNCI_INTERFACE_SPI
#define BOARD_NXPNCI_SPI_CLOCK (CLOCK_GetLpspiClkFreq(1U))
#define BOARD_NXPNCI_SPI_INSTANCE (LPSPI1)
#define BOARD_NXPNCI_SPI_BAUDRATE (400000)
#endif
#define BOARD_NXPNCI_IRQ_PORT (GPIO1)
#define BOARD_NXPNCI_VEN_PORT (GPIO1)
#define BOARD_NXPNCI_DWL_PORT (GPIO3)
#define BOARD_NXPNCI_IRQ_PIN (15U)
#define BOARD_NXPNCI_VEN_PIN (14U)
#define BOARD_NXPNCI_DWL_PIN (16U)
#ifdef BOARD_NXPNCI_INTERFACE_I2C
#define BOARD_NXPNCI_I2C_CLOCK (CLOCK_GetLpi2cClkFreq(0U))
#define BOARD_NXPNCI_I2C_INSTANCE (LPI2C0)
#define BOARD_NXPNCI_I2C_BAUDRATE (100000)
#define BOARD_NXPNCI_I2C_ADDR (0x28)
#endif
#ifdef BOARD_NXPNCI_INTERFACE_SPI
#define BOARD_NXPNCI_SPI_CLOCK (CLOCK_GetLpspiClkFreq(1U))
#define BOARD_NXPNCI_SPI_INSTANCE (LPSPI1)
#define BOARD_NXPNCI_SPI_BAUDRATE (400000)
#endif
#define BOARD_NXPNCI_IRQ_PORT (GPIO1)
#define BOARD_NXPNCI_VEN_PORT (GPIO1)
#define BOARD_NXPNCI_DWL_PORT (GPIO3)
#define BOARD_NXPNCI_IRQ_PIN (15U)
#define BOARD_NXPNCI_VEN_PIN (14U)
#define BOARD_NXPNCI_DWL_PIN (16U)
Code modifications to the TML component
In the source tml.c source file the following modifications are made, you can find this file in the following path:
{{PrjRootDirPath }>frdmmcxa156_hello_world\TML
Habib_MS_2-1781810455046.pngHabib_MS_2-1781810455046.png
Spoiler (Highlight to read) static Status tml_Reset(void) {
/* Set DWL_REQ low for NCI protocol */
GPIO_PortClear(BOARD_NXPNCI_DWL_PORT, 1U << BOARD_NXPNCI_DWL_PIN);
GPIO_PortClear(BOARD_NXPNCI_VEN_PORT, 1U << BOARD_NXPNCI_VEN_PIN);
Sleep(10);
GPIO_PortSet(BOARD_NXPNCI_VEN_PORT, 1U << BOARD_NXPNCI_VEN_PIN);
Sleep(10);
return SUCCESS;
}
static Status tml_Reset(void) {
/* Set DWL_REQ low for NCI protocol */
GPIO_PortClear(BOARD_NXPNCI_DWL_PORT, 1U << BOARD_NXPNCI_DWL_PIN);
GPIO_PortClear(BOARD_NXPNCI_VEN_PORT, 1U << BOARD_NXPNCI_VEN_PIN);
Sleep(10);
GPIO_PortSet(BOARD_NXPNCI_VEN_PORT, 1U << BOARD_NXPNCI_VEN_PIN);
Sleep(10);
return SUCCESS;
}
Habib_MS_3-1781810501153.pngHabib_MS_3-1781810501153.png
Spoiler (Highlight to read) static void INTF_INIT(void)
{
lpspi_master_config_t masterConfig;
LPSPI_MasterGetDefaultConfig(&masterConfig);
masterConfig.baudRate = BOARD_NXPNCI_SPI_BAUDRATE;
masterConfig.whichPcs = (lpspi_which_pcs_t) kLPSPI_Pcs1;
masterXfer.configFlags = kLPSPI_MasterPcs1 | kLPSPI_MasterPcsContinuous | kLPSPI_MasterByteSwap;
LPSPI_MasterInit(BOARD_NXPNCI_SPI_INSTANCE, &masterConfig, BOARD_NXPNCI_SPI_CLOCK);
}
static void INTF_INIT(void)
{
lpspi_master_config_t masterConfig;
LPSPI_MasterGetDefaultConfig(&masterConfig);
masterConfig.baudRate = BOARD_NXPNCI_SPI_BAUDRATE;
masterConfig.whichPcs = (lpspi_which_pcs_t) kLPSPI_Pcs1;
masterXfer.configFlags = kLPSPI_MasterPcs1 | kLPSPI_MasterPcsContinuous | kLPSPI_MasterByteSwap;
LPSPI_MasterInit(BOARD_NXPNCI_SPI_INSTANCE, &masterConfig, BOARD_NXPNCI_SPI_CLOCK);
}
Habib_MS_4-1781810544149.pngHabib_MS_4-1781810544149.png
Spoiler (Highlight to read) static Status tml_Init(void) {
gpio_pin_config_t in_config = {kGPIO_DigitalInput, 0};
gpio_pin_config_t out_config = {kGPIO_DigitalOutput, 0};
GPIO_PinInit(BOARD_NXPNCI_IRQ_PORT, BOARD_NXPNCI_IRQ_PIN, &in_config);
GPIO_PinInit(BOARD_NXPNCI_VEN_PORT, BOARD_NXPNCI_VEN_PIN, &out_config);
GPIO_PinInit(BOARD_NXPNCI_DWL_PORT, BOARD_NXPNCI_DWL_PIN, &out_config);
INTF_INIT();
return SUCCESS;
}
static Status tml_DeInit(void) {
GPIO_PortClear(BOARD_NXPNCI_VEN_PORT, 1U << BOARD_NXPNCI_VEN_PIN);
return SUCCESS;
}
static Status tml_Init(void) {
gpio_pin_config_t in_config = {kGPIO_DigitalInput, 0};
gpio_pin_config_t out_config = {kGPIO_DigitalOutput, 0};
GPIO_PinInit(BOARD_NXPNCI_IRQ_PORT, BOARD_NXPNCI_IRQ_PIN, &in_config);
GPIO_PinInit(BOARD_NXPNCI_VEN_PORT, BOARD_NXPNCI_VEN_PIN, &out_config);
GPIO_PinInit(BOARD_NXPNCI_DWL_PORT, BOARD_NXPNCI_DWL_PIN, &out_config);
INTF_INIT();
return SUCCESS;
}
static Status tml_DeInit(void) {
GPIO_PortClear(BOARD_NXPNCI_VEN_PORT, 1U << BOARD_NXPNCI_VEN_PIN);
return SUCCESS;
}
Code modifications for ports, pins and clocks initialization
In the file “hardware_init.c” in the board folder of the project, write the following function as shown, in order to add port and clock peripheral initializations.
Habib_MS_5-1781810589344.pngHabib_MS_5-1781810589344.png
Spoiler (Highlight to read) /*
* Copyright 2024 NXP
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*${header:start}*/
#include "pin_mux.h"
#include "fsl_clock.h"
#include "fsl_reset.h"
#include "board.h"
#include
/*${header:end}*/
/*${function:start}*/
void BOARD_InitHardware(void)
{
CLOCK_SetClockDiv(kCLOCK_DivLPI2C0, 1u);
CLOCK_AttachClk(kFRO12M_to_LPI2C0);
CLOCK_SetClockDiv(kCLOCK_DivLPSPI1, 1u);
CLOCK_AttachClk(kFRO12M_to_LPSPI1);
BOARD_InitPins();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();
}
/*${function:end}*/
/*
* Copyright 2024 NXP
*
* SPDX-License-Identifier: BSD-3-Clause
*/
/*${header:start}*/
#include "pin_mux.h"
#include "fsl_clock.h"
#include "fsl_reset.h"
#include "board.h"
#include
/*${header:end}*/
/*${function:start}*/
void BOARD_InitHardware(void)
{
CLOCK_SetClockDiv(kCLOCK_DivLPI2C0, 1u);
CLOCK_AttachClk(kFRO12M_to_LPI2C0);
CLOCK_SetClockDiv(kCLOCK_DivLPSPI1, 1u);
CLOCK_AttachClk(kFRO12M_to_LPSPI1);
BOARD_InitPins();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();
}
/*${function:end}*/
In the pin_mux.c file modifies the function called BOARD_InitPins(); accordingly, this file can be seen in the following path:
{PrjRootDirPath}\ frdmmcxa156\hello_world \pin_mux.c
Spoiler (Highlight to read) void BOARD_InitPins(void)
{
CLOCK_EnableClock(kCLOCK_GateGPIO1);
/* GPIO3: Peripheral clock is enabled */
CLOCK_EnableClock(kCLOCK_GateGPIO3);
/* PORT0: Peripheral clock is enabled */
CLOCK_EnableClock(kCLOCK_GatePORT0);
CLOCK_EnableClock(kCLOCK_GatePORT1);
CLOCK_EnableClock(kCLOCK_GatePORT2);
CLOCK_EnableClock(kCLOCK_GatePORT3);
/* GPIO1 peripheral is released from reset */
RESET_ReleasePeripheralReset(kGPIO1_RST_SHIFT_RSTn);
/* GPIO3 peripheral is released from reset */
RESET_ReleasePeripheralReset(kGPIO3_RST_SHIFT_RSTn);
RESET_ReleasePeripheralReset(kLPUART0_RST_SHIFT_RSTn);
RESET_ReleasePeripheralReset(kPORT0_RST_SHIFT_RSTn);
RESET_ReleasePeripheralReset(kLPSPI0_RST_SHIFT_RSTn);
RESET_ReleasePeripheralReset(kPORT1_RST_SHIFT_RSTn);
RESET_ReleasePeripheralReset(kLPSPI1_RST_SHIFT_RSTn);
RESET_ReleasePeripheralReset(kPORT3_RST_SHIFT_RSTn);
RESET_ReleasePeripheralReset(kPORT2_RST_SHIFT_RSTn);
const port_pin_config_t port0_2_pin78_config = {/* Internal pull-up resistor is enabled */
kPORT_PullUp,
/* Low internal pull resistor value is selected. */
kPORT_LowPullResistor,
/* Fast slew rate is configured */
kPORT_FastSlewRate,
/* Passive input filter is disabled */
kPORT_PassiveFilterDisable,
/* Open drain output is disabled */
kPORT_OpenDrainDisable,
/* Low drive strength is configured */
kPORT_LowDriveStrength,
/* Normal drive strength is configured */
kPORT_NormalDriveStrength,
/* Pin is configured as LPUART0_RXD */
kPORT_MuxAlt2,
/* Digital input enabled */
kPORT_InputBufferEnable,
/* Digital input is not inverted */
kPORT_InputNormal,
/* Pin Control Register fields [15:0] are not locked */
kPORT_UnlockRegister};
/* PORT0_2 (pin 78) is configured as LPUART0_RXD */
PORT_SetPinConfig(PORT0, 2U, &port0_2_pin78_config);
const port_pin_config_t port0_3_pin79_config = {/* Internal pull-up resistor is enabled */
kPORT_PullUp,
/* Low internal pull resistor value is selected. */
kPORT_LowPullResistor,
/* Fast slew rate is configured */
kPORT_FastSlewRate,
/* Passive input filter is disabled */
kPORT_PassiveFilterDisable,
/* Open drain output is disabled */
kPORT_OpenDrainDisable,
/* Low drive strength is configured */
kPORT_LowDriveStrength,
/* Normal drive strength is configured */
kPORT_NormalDriveStrength,
/* Pin is configured as LPUART0_TXD */
kPORT_MuxAlt2,
/* Digital input enabled */
kPORT_InputBufferEnable,
/* Digital input is not inverted */
kPORT_InputNormal,
/* Pin Control Register fields [15:0] are not locked */
kPORT_UnlockRegister};
/* PORT0_3 (pin 79) is configured as LPUART0_TXD */
PORT_SetPinConfig(PORT0, 3U, &port0_3_pin79_config);
const port_pin_config_t port2_13_pin35_config = {
kPORT_PullDisable,
kPORT_LowPullResistor,
kPORT_FastSlewRate,
kPORT_PassiveFilterDisable,
kPORT_OpenDrainDisable,
kPORT_LowDriveStrength,
kPORT_NormalDriveStrength,
/* Pin is configured as LPSPI1_SDO */
kPORT_MuxAlt2,
kPORT_InputBufferEnable,
kPORT_InputNormal,
kPORT_UnlockRegister};
PORT_SetPinConfig(PORT2, 13U, &port2_13_pin35_config);
const port_pin_config_t port2_12_pin34_config = {
kPORT_PullDisable,
kPORT_LowPullResistor,
kPORT_FastSlewRate,
kPORT_PassiveFilterDisable,
kPORT_OpenDrainDisable,
kPORT_LowDriveStrength,
kPORT_NormalDriveStrength,
/* Pin is configured as LPSPI1_SCK */
kPORT_MuxAlt2,
kPORT_InputBufferEnable,
kPORT_InputNormal,
kPORT_UnlockRegister};
PORT_SetPinConfig(PORT2, 12U, &port2_12_pin34_config);
const port_pin_config_t port2_16_pin37_config = {
kPORT_PullDisable,
kPORT_LowPullResistor,
kPORT_FastSlewRate,
kPORT_PassiveFilterDisable,
kPORT_OpenDrainDisable,
kPORT_LowDriveStrength,
kPORT_NormalDriveStrength,
/* Pin is configured as LPSPI1_SDI */
kPORT_MuxAlt2,
kPORT_InputBufferEnable,
kPORT_InputNormal,
kPORT_UnlockRegister};
PORT_SetPinConfig(PORT2, 16U, &port2_16_pin37_config);
const port_pin_config_t port2_6_pin28_config = {
kPORT_PullDisable,
kPORT_LowPullResistor,
kPORT_FastSlewRate,
kPORT_PassiveFilterDisable,
kPORT_OpenDrainDisable,
kPORT_LowDriveStrength,
kPORT_NormalDriveStrength,
/* Pin is configured as LPSPI1_PCS0 */
kPORT_MuxAlt2,
kPORT_InputBufferEnable,
kPORT_InputNormal,
kPORT_UnlockRegister};
PORT_SetPinConfig(PORT2, 6U, &port2_6_pin28_config);
const port_pin_config_t port1_15_pin8_config = {
kPORT_PullDisable,
kPORT_LowPullResistor,
kPORT_FastSlewRate,
kPORT_PassiveFilterDisable,
kPORT_OpenDrainDisable,
kPORT_LowDriveStrength,
kPORT_NormalDriveStrength,
/* Pin is configured as GPIO1 15 */
kPORT_MuxAlt0,
kPORT_InputBufferEnable,
kPORT_InputNormal,
kPORT_UnlockRegister};
PORT_SetPinConfig(PORT1, 15U, &port1_15_pin8_config);
const port_pin_config_t port1_14_pin7_config = {
kPORT_PullUp,
kPORT_LowPullResistor,
kPORT_FastSlewRate,
kPORT_PassiveFilterDisable,
kPORT_OpenDrainDisable,
kPORT_LowDriveStrength,
kPORT_NormalDriveStrength,
/* Pin is configured as GPIO1 14 */
kPORT_MuxAlt0,
kPORT_InputBufferEnable,
kPORT_InputNormal,
kPORT_UnlockRegister};
PORT_SetPinConfig(PORT1, 14U, &port1_14_pin7_config);
const port_pin_config_t port3_16_pin59_config = {
kPORT_PullUp,
kPORT_LowPullResistor,
kPORT_FastSlewRate,
kPORT_PassiveFilterDisable,
kPORT_OpenDrainDisable,
kPORT_LowDriveStrength,
kPORT_NormalDriveStrength,
/* Pin is configured as GPIO3 16 */
kPORT_MuxAlt0,
kPORT_InputBufferEnable,
kPORT_InputNormal,
kPORT_UnlockRegister};
PORT_SetPinConfig(PORT3, 16U, &port3_16_pin59_config);
const port_pin_config_t port0_16_pin83_config = {
kPORT_PullDisable,
kPORT_LowPullResistor,
kPORT_FastSlewRate,
kPORT_PassiveFilterDisable,
kPORT_OpenDrainDisable,
kPORT_LowDriveStrength,
kPORT_NormalDriveStrength,
/* Pin is configured as LPI2C0 SDA */
kPORT_MuxAlt2,
kPORT_InputBufferEnable,
kPORT_InputNormal,
kPORT_UnlockRegister};
PORT_SetPinConfig(PORT0, 16U, &port0_16_pin83_config);
const port_pin_config_t port0_17_pin84_config = {
kPORT_PullDisable,
kPORT_LowPullResistor,
kPORT_FastSlewRate,
kPORT_PassiveFilterDisable,
kPORT_OpenDrainDisable,
kPORT_LowDriveStrength,
kPORT_NormalDriveStrength,
/* Pin is configured as LPI2C0 SCL */
kPORT_MuxAlt2,
kPORT_InputBufferEnable,
kPORT_InputNormal,
kPORT_UnlockRegister};
PORT_SetPinConfig(PORT0, 17U, &port0_17_pin84_config);
}
void BOARD_InitPins(void)
{
CLOCK_EnableClock(kCLOCK_GateGPIO1);
/* GPIO3: Peripheral clock is enabled */
CLOCK_EnableClock(kCLOCK_GateGPIO3);
/* PORT0: Peripheral clock is enabled */
CLOCK_EnableClock(kCLOCK_GatePORT0);
CLOCK_EnableClock(kCLOCK_GatePORT1);
CLOCK_EnableClock(kCLOCK_GatePORT2);
CLOCK_EnableClock(kCLOCK_GatePORT3);
/* GPIO1 peripheral is released from reset */
RESET_ReleasePeripheralReset(kGPIO1_RST_SHIFT_RSTn);
/* GPIO3 peripheral is released from reset */
RESET_ReleasePeripheralReset(kGPIO3_RST_SHIFT_RSTn);
RESET_ReleasePeripheralReset(kLPUART0_RST_SHIFT_RSTn);
RESET_ReleasePeripheralReset(kPORT0_RST_SHIFT_RSTn);
RESET_ReleasePeripheralReset(kLPSPI0_RST_SHIFT_RSTn);
RESET_ReleasePeripheralReset(kPORT1_RST_SHIFT_RSTn);
RESET_ReleasePeripheralReset(kLPSPI1_RST_SHIFT_RSTn);
RESET_ReleasePeripheralReset(kPORT3_RST_SHIFT_RSTn);
RESET_ReleasePeripheralReset(kPORT2_RST_SHIFT_RSTn);
const port_pin_config_t port0_2_pin78_config = {/* Internal pull-up resistor is enabled */
kPORT_PullUp,
/* Low internal pull resistor value is selected. */
kPORT_LowPullResistor,
/* Fast slew rate is configured */
kPORT_FastSlewRate,
/* Passive input filter is disabled */
kPORT_PassiveFilterDisable,
/* Open drain output is disabled */
kPORT_OpenDrainDisable,
/* Low drive strength is configured */
kPORT_LowDriveStrength,
/* Normal drive strength is configured */
kPORT_NormalDriveStrength,
/* Pin is configured as LPUART0_RXD */
kPORT_MuxAlt2,
/* Digital input enabled */
kPORT_InputBufferEnable,
/* Digital input is not inverted */
kPORT_InputNormal,
/* Pin Control Register fields [15:0] are not locked */
kPORT_UnlockRegister};
/* PORT0_2 (pin 78) is configured as LPUART0_RXD */
PORT_SetPinConfig(PORT0, 2U, &port0_2_pin78_config);
const port_pin_config_t port0_3_pin79_config = {/* Internal pull-up resistor is enabled */
kPORT_PullUp,
/* Low internal pull resistor value is selected. */
kPORT_LowPullResistor,
/* Fast slew rate is configured */
kPORT_FastSlewRate,
/* Passive input filter is disabled */
kPORT_PassiveFilterDisable,
/* Open drain output is disabled */
kPORT_OpenDrainDisable,
/* Low drive strength is configured */
kPORT_LowDriveStrength,
/* Normal drive strength is configured */
kPORT_NormalDriveStrength,
/* Pin is configured as LPUART0_TXD */
kPORT_MuxAlt2,
/* Digital input enabled */
kPORT_InputBufferEnable,
/* Digital input is not inverted */
kPORT_InputNormal,
/* Pin Control Register fields [15:0] are not locked */
kPORT_UnlockRegister};
/* PORT0_3 (pin 79) is configured as LPUART0_TXD */
PORT_SetPinConfig(PORT0, 3U, &port0_3_pin79_config);
const port_pin_config_t port2_13_pin35_config = {
kPORT_PullDisable,
kPORT_LowPullResistor,
kPORT_FastSlewRate,
kPORT_PassiveFilterDisable,
kPORT_OpenDrainDisable,
kPORT_LowDriveStrength,
kPORT_NormalDriveStrength,
/* Pin is configured as LPSPI1_SDO */
kPORT_MuxAlt2,
kPORT_InputBufferEnable,
kPORT_InputNormal,
kPORT_UnlockRegister};
PORT_SetPinConfig(PORT2, 13U, &port2_13_pin35_config);
const port_pin_config_t port2_12_pin34_config = {
kPORT_PullDisable,
kPORT_LowPullResistor,
kPORT_FastSlewRate,
kPORT_PassiveFilterDisable,
kPORT_OpenDrainDisable,
kPORT_LowDriveStrength,
kPORT_NormalDriveStrength,
/* Pin is configured as LPSPI1_SCK */
kPORT_MuxAlt2,
kPORT_InputBufferEnable,
kPORT_InputNormal,
kPORT_UnlockRegister};
PORT_SetPinConfig(PORT2, 12U, &port2_12_pin34_config);
const port_pin_config_t port2_16_pin37_config = {
kPORT_PullDisable,
kPORT_LowPullResistor,
kPORT_FastSlewRate,
kPORT_PassiveFilterDisable,
kPORT_OpenDrainDisable,
kPORT_LowDriveStrength,
kPORT_NormalDriveStrength,
/* Pin is configured as LPSPI1_SDI */
kPORT_MuxAlt2,
kPORT_InputBufferEnable,
kPORT_InputNormal,
kPORT_UnlockRegister};
PORT_SetPinConfig(PORT2, 16U, &port2_16_pin37_config);
const port_pin_config_t port2_6_pin28_config = {
kPORT_PullDisable,
kPORT_LowPullResistor,
kPORT_FastSlewRate,
kPORT_PassiveFilterDisable,
kPORT_OpenDrainDisable,
kPORT_LowDriveStrength,
kPORT_NormalDriveStrength,
/* Pin is configured as LPSPI1_PCS0 */
kPORT_MuxAlt2,
kPORT_InputBufferEnable,
kPORT_InputNormal,
kPORT_UnlockRegister};
PORT_SetPinConfig(PORT2, 6U, &port2_6_pin28_config);
const port_pin_config_t port1_15_pin8_config = {
kPORT_PullDisable,
kPORT_LowPullResistor,
kPORT_FastSlewRate,
kPORT_PassiveFilterDisable,
kPORT_OpenDrainDisable,
kPORT_LowDriveStrength,
kPORT_NormalDriveStrength,
/* Pin is configured as GPIO1 15 */
kPORT_MuxAlt0,
kPORT_InputBufferEnable,
kPORT_InputNormal,
kPORT_UnlockRegister};
PORT_SetPinConfig(PORT1, 15U, &port1_15_pin8_config);
const port_pin_config_t port1_14_pin7_config = {
kPORT_PullUp,
kPORT_LowPullResistor,
kPORT_FastSlewRate,
kPORT_PassiveFilterDisable,
kPORT_OpenDrainDisable,
kPORT_LowDriveStrength,
kPORT_NormalDriveStrength,
/* Pin is configured as GPIO1 14 */
kPORT_MuxAlt0,
kPORT_InputBufferEnable,
kPORT_InputNormal,
kPORT_UnlockRegister};
PORT_SetPinConfig(PORT1, 14U, &port1_14_pin7_config);
const port_pin_config_t port3_16_pin59_config = {
kPORT_PullUp,
kPORT_LowPullResistor,
kPORT_FastSlewRate,
kPORT_PassiveFilterDisable,
kPORT_OpenDrainDisable,
kPORT_LowDriveStrength,
kPORT_NormalDriveStrength,
/* Pin is configured as GPIO3 16 */
kPORT_MuxAlt0,
kPORT_InputBufferEnable,
kPORT_InputNormal,
kPORT_UnlockRegister};
PORT_SetPinConfig(PORT3, 16U, &port3_16_pin59_config);
const port_pin_config_t port0_16_pin83_config = {
kPORT_PullDisable,
kPORT_LowPullResistor,
kPORT_FastSlewRate,
kPORT_PassiveFilterDisable,
kPORT_OpenDrainDisable,
kPORT_LowDriveStrength,
kPORT_NormalDriveStrength,
/* Pin is configured as LPI2C0 SDA */
kPORT_MuxAlt2,
kPORT_InputBufferEnable,
kPORT_InputNormal,
kPORT_UnlockRegister};
PORT_SetPinConfig(PORT0, 16U, &port0_16_pin83_config);
const port_pin_config_t port0_17_pin84_config = {
kPORT_PullDisable,
kPORT_LowPullResistor,
kPORT_FastSlewRate,
kPORT_PassiveFilterDisable,
kPORT_OpenDrainDisable,
kPORT_LowDriveStrength,
kPORT_NormalDriveStrength,
/* Pin is configured as LPI2C0 SCL */
kPORT_MuxAlt2,
kPORT_InputBufferEnable,
kPORT_InputNormal,
kPORT_UnlockRegister};
PORT_SetPinConfig(PORT0, 17U, &port0_17_pin84_config);
}
Configure the main.c as follows:
Habib_MS_0-1781813861103.pngHabib_MS_0-1781813861103.png
Spoiler (Highlight to read) #include
#include
#include "board.h"
#include "app.h"
#include "pin_mux.h"
#include "fsl_debug_console.h"
extern void nfc_example (void);
int main(void)
{
BOARD_InitHardware();
#ifdef BOARD_NXPNCI_INTERFACE_I2C
PRINTF("\nRunning the NXP-NCI2.0 example (I2C interface)\n");
#else
PRINTF("\nRunning the NXP-NCI2.0 example (SPI interface)\n");
#endif
nfc_example();
}
#include
#include
#include "board.h"
#include "app.h"
#include "pin_mux.h"
#include "fsl_debug_console.h"
extern void nfc_example (void);
int main(void)
{
BOARD_InitHardware();
#ifdef BOARD_NXPNCI_INTERFACE_I2C
PRINTF("\nRunning the NXP-NCI2.0 example (I2C interface)\n");
#else
PRINTF("\nRunning the NXP-NCI2.0 example (SPI interface)\n");
#endif
nfc_example();
}
Building and Debugging the example
For building the example, please click on this button and if you followed this guide accordingly the project should compile without errors:
Habib_MS_1-1781813991676.pngHabib_MS_1-1781813991676.png
Habib_MS_2-1781813999778.pngHabib_MS_2-1781813999778.png
Open a serial terminal such as Teraterm with the following settings:
Habib_MS_3-1781814017721.pngHabib_MS_3-1781814017721.png
Start a debug session by clicking this button:
Habib_MS_4-1781814064724.pngHabib_MS_4-1781814064724.png
Once running, the example should look as follows:
Habib_MS_5-1781814084057.pngHabib_MS_5-1781814084057.png
When tapping a card on the antenna, the card information will be shown:
Habib_MS_6-1781814110924.pngHabib_MS_6-1781814110924.png
NFC Controller Solutions
View full article