《转》PN532读写操作(串口)

本文详细解析了PN532模块用于读写Mifare 1 Card S50/S70卡片的数据帧结构。从帧头、开始码、数据长度、校验位等方面介绍了帧的基本构成,并解释了LCS和DCS校验位的计算方法。

这几天玩玩pn532读写Mifare1 Card,s50,s70,在网上看了一些文章,照着做了,尝试了很久才成功最坑的莫过于校验位,还有认证过程。

1.先了解帧(frame)的结构:

可能好多人对英文望而却步,在下不才,解释下

1.PREAMBLE1 byte4,

这个就是所谓的帧头,也称为前导码,一般是00
2.START CODE2 bytes (0x00 and 0xFF),

开始码 2个字节,分别是 00和FF 
3.LEN1 byte indicating the number of bytes in the data field
(TFI and PD0 to PDn),

这个是数据长度,一个TFI和n个PD
3.LCS1 Packet Length Checksum LCS byte that satisfies the relation:
Lower byte of [LEN + LCS] = 0x00,

这个是LEN的补码,也就是(LEN取反+1)
4.TFI1 byte frame identifier, the value of this byte depends
on the way of the message
- D4h in case of a frame from the host controller to the PN532,
- D5h in case of a frame from the PN532 to the host controller.

表示数据流向 D4 表示 数据发向PN532

        D5 表示 PN532数据发出
5.DATALEN-1 bytes of Packet Data Information
The first byte PD0 is the Command Code,

搞了半天,这才是我们想要发的数据,DATA的第一个字节PD0为控制字符,其余为普通数据。该包长度为 LEN-1
6.DCS1 Data Checksum DCS byte that satisfies the relation:
Lower byte of [TFI + PD0 + PD1 + … + PDn + DCS] = 0x00,

DCS 其实最坑了,根本不知道怎么算出来的。其实就是把这些十六进制数加起来,后两位取补码即可。即(TFI + PD0 + PD1 + … + PDn)累加和,取后两位的补码。
 POSTAMBLE1 byte2.

帧尾 一般为 00
The amount of data that can be exchanged using this frame structure is limited to 255
bytes (including TFI).

最后一句话了,,这种的数据结构只能有255 个data (包括TFI),还有几种种结构,这里先不说了。

其他参考:

NFC模块PN532使用:NFC模块PN532使用 | MakerInChina

NFC模块PN532使用 | MakerInChina

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值