题目说是操作,其实主要是移植。该芯片支持iic与spi两种操作方式,对于现在我使用的NFC06A1扩展板来说,默认即为spi模式,本文将记录下移植时需要注意的点.) {( S5 a- L g
1.原理图$ X. ]! c" @% O8 H
7 s$ E# b+ f5 V$ Y. @" s4 z扩展板引脚标注与实际板卡的引脚是不同的,这里需要根据实际修改一下。, k. W; n: S4 U# f9 G9 V9 s2 w
5 z6 I3 d7 q1 j3 I! q3 m7 {2.spi配置% t" z+ o. o. N. z' g
4 I0 ]/ a U: I& e上图是本次移植中,笔者使用的配置,亲测可行3 ~) W, Z9 H; f) v2 ^- |; f
0 U6 d; G; m4 A3 b7 D2 @1 H
3.外部中断配置6 `$ @2 ~6 c& u" F
- /**
% U8 U+ r' L& N- |' @ - * @brief This function handles EXTI line3 interrupt.
5 \. O2 U) B5 A' y3 p - */
7 [6 F- E. [. a% q6 n - void EXTI3_IRQHandler(void)8 I* Y. P9 c/ I6 X
- {
( I$ N$ r! N/ Q! h* ^9 h4 F( X6 } - /* USER CODE BEGIN EXTI3_IRQn 0 */
2 f+ Z6 C: a% u
# T! F, N& n, J: p& M- /* USER CODE END EXTI3_IRQn 0 */
I! v" f. `) i) [1 \. y6 ^ - HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_3);
W3 B7 k; ~& t - /* USER CODE BEGIN EXTI3_IRQn 1 */
9 w6 y! l" U8 r. @ - st25r3916Isr();1 o! t. Z: B- R! t2 k
- /* USER CODE END EXTI3_IRQn 1 */
, {3 H+ i$ ?" T9 A5 T - }
复制代码 需要在外部中断中加入st25r3916Isr();处理。注意:该函数操作了接口的读写,如果使用spi中断或者iic中断接受需要注意。建议使用操作系统的时候使用通知进行操作。( n' p4 ^. ]- l/ _
5 Y# c1 m& U3 v
4 k8 v! N3 t2 A6 d; q9 D& ^% C4.代码配置
/ u2 {) B- u3 g基本所有的配置都集中在platform.h文件里面。下面代码是关于NFC支持相关功能的开关。
6 }! W/ V8 N' h: _) g# ~# Q- #define RFAL_FEATURE_LISTEN_MODE true /*!< Enable/Disable RFAL support for Listen Mode */
& @' K$ d0 E# a* c - #define RFAL_FEATURE_WAKEUP_MODE true /*!< Enable/Disable RFAL support for the Wake-Up mode */( [8 Q4 s: n/ k; J' o" V o
- #define RFAL_FEATURE_NFCA true /*!< Enable/Disable RFAL support for NFC-A (ISO14443A) */% J0 A. ], A& ~9 p6 d" F+ @/ q
- #define RFAL_FEATURE_NFCB true /*!< Enable/Disable RFAL support for NFC-B (ISO14443B) */( \/ X% {0 B1 | p; }" C
- #define RFAL_FEATURE_NFCF true /*!< Enable/Disable RFAL support for NFC-F (FeliCa) */
1 E. Q9 z4 h% B& E - #define RFAL_FEATURE_NFCV true /*!< Enable/Disable RFAL support for NFC-V (ISO15693) */2 A' `. s) Y# i6 G- T
- #define RFAL_FEATURE_T1T true /*!< Enable/Disable RFAL support for T1T (Topaz) */
5 S8 v1 L' {; ? - #define RFAL_FEATURE_T2T true /*!< Enable/Disable RFAL support for T2T (Mifare) */* l8 X' u1 s+ W2 [& I( x
- #define RFAL_FEATURE_T4T true /*!< Enable/Disable RFAL support for T4T */
9 u- h& s4 o0 g* [ - #define RFAL_FEATURE_ST25TB true /*!< Enable/Disable RFAL support for ST25TB */: T& R+ J4 e# X1 H3 j3 g
- #define RFAL_FEATURE_ST25xV true /*!< Enable/Disable RFAL support for ST25TV/ST25DV */ |/ |' v$ V5 G* Y9 k0 X8 ^
- #define RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG false /*!< Enable/Disable Analog Configs to be dynamically updated (RAM) */
7 ~: U& w [% w0 v0 Z C, l - #define RFAL_FEATURE_DPO false /*!< Enable/Disable RFAL dynamic power support */; f# q4 D; ?9 J
- #define RFAL_FEATURE_ISO_DEP true /*!< Enable/Disable RFAL support for ISO-DEP (ISO14443-4) */
& \. y1 v& P2 A2 |( P; e - #define RFAL_FEATURE_ISO_DEP_POLL true /*!< Enable/Disable RFAL support for Poller mode (PCD) ISO-DEP (ISO14443-4) */
+ G3 X- s! D! R t( \% W - #define RFAL_FEATURE_ISO_DEP_LISTEN true /*!< Enable/Disable RFAL support for Listen mode (PICC) ISO-DEP (ISO14443-4) */
" l3 b" u6 g" q8 i7 k - #define RFAL_FEATURE_NFC_DEP true /*!< Enable/Disable RFAL support for NFC-DEP (NFCIP1/P2P) */
( H: x7 T) C2 _6 u; r
1 ]) w# F6 P2 d* n1 P7 G* b- #define RFAL_FEATURE_ISO_DEP_IBLOCK_MAX_LEN 256U /*!< ISO-DEP I-Block max length. Please use values as defined by rfalIsoDepFSx */
( t# L$ ]! c) L& z+ B3 l* C5 F- n - #define RFAL_FEATURE_NFC_DEP_BLOCK_MAX_LEN 254U /*!< NFC-DEP Block/Payload length. Allowed values: 64, 128, 192, 254 */* T" X+ ~# x: q
- #define RFAL_FEATURE_NFC_RF_BUF_LEN 258U /*!< RF buffer length used by RFAL NFC layer */( R! `4 i6 a5 f+ J) ]& y
6 t, h/ Z- H2 a4 @ I2 X8 u6 ^- #define RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN 512U /*!< ISO-DEP APDU max length. Please use multiples of I-Block max length */3 k. J3 u" d# h- R" k
- #define RFAL_FEATURE_NFC_DEP_PDU_MAX_LEN 512U /*!< NFC-DEP PDU max length. */
复制代码 * B5 G( p/ A+ Z% [( O) C
! ]7 d& c4 b# l效果演示:
+ L: g% d2 O6 Z$ K' ?
; c, `7 d8 ~6 ~) m
读取M1卡卡号,不支持M1协议,但是支持NRFA。
9 s5 f# w9 k. D1 W" C. c2 F' g/ @5 |
" g+ f+ H+ c. K+ y# l" j% C: {' g6 L
# B7 m9 p7 s( Z, H- C
手机读取板子,识别为NFCF协议了,其实是因为手机啥都支持,读到的就看板子处在那种模式。
, k; d" r3 ?/ H) P' P' R" i$ I9 ^9 d, N
+ N$ L. S g5 \) Y n
相关打印
! ?8 d( l9 e! Q$ s. w5 @/ |+ q
% F$ }* l, S2 x7 o+ H* W) R最后附上程序,注:为了减小代码体积,删除了CMSIS的DSP相关文件
+ X9 l! |% B1 z
nfc.zip
(6.59 MB, 下载次数: 0)
|