NFC ON KW

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

NFC ON KW

NFC ON KW

In the process of practical application, customers often need the combination of ble + NFC. At present, our IOT-DK006 is the only development board with NFC module. But the NFC example is not perfect. So we porting the library of NFC reader- PN7150, to support KW series microcomputer so that KW series can handle the demand of ble + NFC function.

Now I will introduce you how to port the NFC lib to KW.

1 PN7150 Introduction

PN7150 is the high-performance version of PN7120, the plug’n play NFC solution for easy integration into any OS environment, reducing Bill of Material (BOM) size and cost. PN71xx controllers are ideal for home-automation applications such as gateways and work seamlessly with NFC connected tags.

nxf56274_0-1622614472750.png

2 Tools

hardwareFRDM-KW36PN7150 , some wire

softwaremcuxpresso11.3

packageNXP-NCI MCUXpresso example Project

This package contains the nfc library and example that we need. We will refer the ‘NXPNCI-K64F_example’ firstly.

Sdk version: 2.2.8

Example: frdmkw36_rtos_examples_freertos_i2c

 3 Steps

Hardware partWe need connect the PN7150 to KW36 like the picture. Although we can connect the PN7150 to board through the ardunio connector, the pin’s voltage is not enough to drive the PN7150. So we need a wire connected to U1 to get 3.3V.  

PN7150

FRDM-KW36

VBAT/PVDD

3.3V

VANT

5V

GND

GND

IRQ

PTA16

VEN

PTC15

SCL

PTB0I2C0

SDA

PTB1I2C0

nxf56274_1-1622614472876.jpeg

Software partWe should add the nfc library and directory into our project. You can check the following picture to know what file is necessary. If you want to know how to add directory into our project, you can refer this link.

The red line shows what file we need.

nxf56274_2-1622614472948.png

Please notice that when we add file path into the mcuxpresso configuration, we also need add the path into ‘Path and Symbols’ .

nxf56274_3-1622614473031.png

 

We need add some macro into ‘Preprocessor’.

nxf56274_4-1622614473134.png

 

We copy the NXPNCI-K64F_example’s main file content into our ‘freertos_i2c.c’.

Next, we need modify the file pin_mux.c, tml.c and board.h

 

In file board.hadd the following macro. Don't forget to enable the pin clock.

/* NXPNCI NFC related declaration */

#define BOARD_NXPNCI_I2C_INSTANCE I2C0

#define BOARD_NXPNCI_I2C_BAUDRATE (100000)

#define BOARD_NXPNCI_I2C_ADDR       (0x28)

#define BOARD_NXPNCI_IRQ_PORTIRQn PORTA_IRQn

#define BOARD_NXPNCI_IRQ_GPIO     (GPIOA)

#define BOARD_NXPNCI_IRQ_PORT     (PORTA)

#define BOARD_NXPNCI_IRQ_PIN      (16U)

#define BOARD_NXPNCI_VEN_GPIO     (GPIOC)

#define BOARD_NXPNCI_VEN_PORT     (PORTC)

#define NXPNCI_VEN_PIN            (5U)

   

In file pin_mux.c, add head file ‘board.h’. Add the following code in function

’ BOARD_InitPins’. The step is to configure the VEN, IRQ and I2C0. This example contains the I2C1’s code, you can comment them.

 

  /* Initialize NXPNCI GPIO pins below */

  /* IRQ and VEN PIN_MUX Configuration */

  PORT_SetPinMux(BOARD_NXPNCI_IRQ_PORT, BOARD_NXPNCI_IRQ_PIN, kPORT_MuxAsGpio);

  PORT_SetPinMux(BOARD_NXPNCI_VEN_PORT, NXPNCI_VEN_PIN, kPORT_MuxAsGpio);

  /* IRQ interrupt Configuration */

  NVIC_SetPriority(BOARD_NXPNCI_IRQ_PORTIRQn, 6);

  EnableIRQ(BOARD_NXPNCI_IRQ_PORTIRQn);

  PORT_SetPinInterruptConfig(BOARD_NXPNCI_IRQ_PORT, BOARD_NXPNCI_IRQ_PIN, kPORT_InterruptRisingEdge);

 

Finally, in file tml.c, modify PORTC_IRQHandler as PORTA_IRQHandler

We finished all steps.

4 Results

We use ntag to test the reading and writing operation.

nxf56274_5-1622614473191.jpeg

 

When the tag is closed to the PN7150, we will get the following message.

nxf56274_6-1622614473213.png

 

The text recording is ‘VER=03’.

Next, we will modify the text recording

We need add the new macro to preprocessor.

nxf56274_7-1622614473283.png

 

We can modify the variable NDEF_MESSAGE in function task_nfc_reader to modify the text recording.

nxf56274_8-1622614473309.png

 

Then we download the program again. We will see the original text ‘VER=03’ and the text has been modified. Then we read the tag again. We will see the new text.

nxf56274_9-1622614473339.png

 

If we want to send the larger text, what should we do? We need modify the macro ‘ADD’.

When only 4 characters are sent, ‘ADD’ is 0. And every additional character is added, the ‘ADD’ will add. We modify the tag as ‘Ver=03’, and we have two more characters. So ‘ADD’ needs to be defined as 2

nxf56274_10-1622614473363.png

 

It firstly shows the text ‘Test’. Then it will show the new text ‘Ver=03’.

nxf56274_11-1622614473396.png

Other tags’ reading and writing operation can be enabled by defining some macro.

 

 

 

Labels (2)
Tags (1)
Attachments
No ratings
Version history
Last update:
‎09-22-2021 12:30 AM
Updated by: