7493 views|7 replies

110

Posts

1

Resources
The OP
 

【BearPi-HM Nano】NFC test [Copy link]

This post was last edited by sumoon_yao on 2021-6-28 17:34

According to official information, the main chip Hi3861 of the Bear Pi has two IIC communication interfaces, one of which is led out in E53 mode, and the other is used by the NFC chip. See the following schematic diagram:

This time, let’s test the NFC function of Bear Pie.

B5 in the example is a demonstration of the NFC function. Enter the B5_basic_i2c_nfc directory and open the main program i2c_example.c :

static void I2CTask(void)

{

uint8_t ret;

GpioInit();

//GPIO_0 is multiplexed as I2C1_SDA

IoSetFunc(WIFI_IOT_IO_NAME_GPIO_0, WIFI_IOT_IO_FUNC_GPIO_0_I2C1_SDA);

//GPIO_1 is multiplexed as I2C1_SCL

IoSetFunc(WIFI_IOT_IO_NAME_GPIO_1, WIFI_IOT_IO_FUNC_GPIO_1_I2C1_SCL);

//baudrate: 400kbps

I2cInit(WIFI_IOT_I2C_IDX_1, 400000);

I2cSetBaudrate(WIFI_IOT_I2C_IDX_1, 400000);

printf("I2C Test Start\n");

ret = storeText(NDEFFirstPos, (uint8_t *)TEXT);

if (ret != 1)

{

printf("NFC Write Data Falied :%d ", ret);

}

ret = storeUrihttp(NDEFLastPos, (uint8_t *)WEB);

if (ret != 1)

{

printf("NFC Write Data Falied :%d ", ret);

}

while (1)

{

printf("========================================\r\n");

printf("************I2C_NFC_example************\r\n");

printf("========================================\r\n");

printf("Please use the mobile phone with NFC function close to the development board!\r\n");

usleep(1000000);

}

}

The program looks relatively simple. It sets the two pins and baud rate of the IIC bus , and then writes two sets of data to the NFC storage area, one set is plain text information and the other is URI data. Finally, the program enters a loop, waiting for a mobile phone with NFC function to read the two sets of information.

Modify the build.gn file in the sample directory as follows:

#"B1_basic_led_blink:led_example",

# "B2_basic_button:button_example",

#"B3_basic_pwm_led:pwm_example",

#"B4_basic_adc:adc_example",

"B5_basic_i2c_nfc:i2c_example",

#"B6_basic_uart:uart_example",

That is, comment out B2 and remove the comment of B5.

The compilation and burning process is the same as the previous one.

Open the serial terminal, and the program running results are shown as follows:

Waiting for the NFC-enabled phone to read NFC data

There are two NFC tools installed in the mobile phone, one is NFC Tap from ST, and the other is NFC Taginfo from NXP. Use these two apps to read them respectively.

Let's first look at the reading of NFC Tap. NFC Tap has two reading modes: Read Tag and Read NDEF.

Let’s look at the Read Tag method first:

When the phone is close to the NFC TAG area of the board, the NFC indicator light is on, but the phone does not read any information.

Then use the Read NDEF method to read. When the phone is close to the NFC TAG area of the board, a successful reading prompt sound is immediately heard, and the read content is displayed on the phone screen:

From the above picture, we can see that the NFC reading app has successfully read the two sets of data written by the main program of the board.

Let’s look at the NXP Taginfo reading status. Click the “Sacn & Show” button and bring the phone close to the NFC TAG area of the board. Soon the screen will show that the data has been read :

Click the "NTAG I2C Plus" button and the screen displays the detailed information of the NFC Tag:

How to write data to the Bear Pi via NFC? After learning that the new version of the Bear Pi has an example of reading NFC data, you can make some changes to the existing NFC routines to achieve it.

First modify the main program i2c_example.c:

Add the following function to the NT3H.c file in the nfc directory:

Add a line to the header file NT3H.h in the nfc directory:

The program running results after compilation and burning are as follows:

While waiting for the external NFC card reader to read, the board itself is also looping to read the initially written data. At this time, if an external NFC Writer writes data to the board, the purpose of transmitting data to the board via NFC is achieved.

Open the NFC Writer on your phone and test writing text data first:

Press the WRITE button and bring the phone close to the NFC area of the board. After a click, the writing is successful and the test serial terminal displays:

Because of the output display problem, I can't see the data read by the board. I use NFC Tap APP to read it again. The result is as follows:

This indicates that the data has been successfully written into the NFC data storage area of the board.

Then use NFC Write to write URL data:

Similarly, the writing is successful after a beep, and the test serial terminal displays:

Use NFC Tap APP to read again, the result is as follows:

At this point, the NFC two-way communication test is complete. Of course, some specific technical details of NFC will be studied later.

This post is from ARM Technology

Latest reply

【BearPi-HM Nano】NFC test   Details Published on 2021-6-25 11:44

赞赏

1

查看全部赞赏

 

5221

Posts

239

Resources
2
 

See the touch

This post is from ARM Technology
Add and join groups EEWorld service account EEWorld subscription account Automotive development circle
 
 
 

1942

Posts

2

Resources
3
 

Not bad, the effect is really good!

This post is from ARM Technology
 
 
 

7462

Posts

2

Resources
4
 

Thanks for sharing, looking forward to the follow-up!

This post is from ARM Technology
 
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 

14

Posts

0

Resources
5
 

Looks good, wait for a follow-up!

This post is from ARM Technology
 
 
 

53

Posts

0

Resources
6
 

Awesome

This post is from ARM Technology
 
 
 

5

Posts

0

Resources
7
 

【BearPi-HM Nano】NFC test

This post is from ARM Technology
 
 
 

110

Posts

1

Resources
8
 
This post was last edited by sumoon_yao on 2021-6-28 17:36

Reverse operation update completed.

This post is from ARM Technology
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews

Room 1530, Zhongguancun MOOC Times Building, Block B, 18 Zhongguancun Street, Haidian District, Beijing 100190, China Tel:(010)82350740 Postcode:100190

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list