题目说是操作,其实主要是移植。该芯片支持iic与spi两种操作方式,对于现在我使用的NFC06A1扩展板来说,默认即为spi模式,本文将记录下移植时需要注意的点.4 c0 S" a) l; `0 ~3 c; e) i
1.原理图
" D7 E# b" p- G2 J9 U
4 V: e' b9 w& ] r9 [5 P" t扩展板引脚标注与实际板卡的引脚是不同的,这里需要根据实际修改一下。
9 H" l0 F2 ~- @5 f# _" b, u
0 n: c. z! D1 @2.spi配置
; }* w6 n- X* K4 t
) `# P8 F! P6 }/ k+ O8 T6 c
上图是本次移植中,笔者使用的配置,亲测可行
4 [4 s. M1 V0 ~% @2 |" T: n/ |, a4 p5 Y2 B/ n/ v, t
3.外部中断配置
8 ]3 l% h, G. {/ c9 `7 N& a" B- /**5 e( @( i t! v0 f& i0 ?' ?8 z
- * @brief This function handles EXTI line3 interrupt.) C; y3 Y4 a: y
- */' n5 c% L$ ?# ~9 q1 J
- void EXTI3_IRQHandler(void)
" Q; \; t7 z5 ?7 t - {
; x2 T; P( D( \, E$ w - /* USER CODE BEGIN EXTI3_IRQn 0 */
8 ]6 r; @$ f9 Q' G. n - 6 A: L. p; q: [3 O7 b
- /* USER CODE END EXTI3_IRQn 0 */9 `. o. j8 I4 Y. b6 e/ [! X+ ]6 |
- HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_3);
5 n. u' Y& G$ E, i! z# x' V1 O1 J - /* USER CODE BEGIN EXTI3_IRQn 1 */+ v5 b* y7 U3 y/ {, `" R$ c
- st25r3916Isr();1 s4 Z! u4 q6 [4 v4 f' i
- /* USER CODE END EXTI3_IRQn 1 */ o3 I4 U& T; o& Z/ {6 I+ q
- }
复制代码 需要在外部中断中加入st25r3916Isr();处理。注意:该函数操作了接口的读写,如果使用spi中断或者iic中断接受需要注意。建议使用操作系统的时候使用通知进行操作。' a( f, G" x$ V( W( {
- ?6 L% F+ D- M, t; h% D
8 s4 U9 B3 ]- x. U2 h8 d/ o# {* _
4.代码配置4 h- [9 G" G! y
基本所有的配置都集中在platform.h文件里面。下面代码是关于NFC支持相关功能的开关。, L: l$ O# b1 m3 y" p
- #define RFAL_FEATURE_LISTEN_MODE true /*!< Enable/Disable RFAL support for Listen Mode */
+ p3 j" f* d1 S- | - #define RFAL_FEATURE_WAKEUP_MODE true /*!< Enable/Disable RFAL support for the Wake-Up mode */
. W1 w9 F, z) ^: r6 z - #define RFAL_FEATURE_NFCA true /*!< Enable/Disable RFAL support for NFC-A (ISO14443A) */
# Y! u7 D0 {7 c2 x5 t6 E N - #define RFAL_FEATURE_NFCB true /*!< Enable/Disable RFAL support for NFC-B (ISO14443B) */; }" g2 G; Q7 e7 v
- #define RFAL_FEATURE_NFCF true /*!< Enable/Disable RFAL support for NFC-F (FeliCa) */
" f4 a, |, o2 c! k! ?2 G4 f6 E9 h* t - #define RFAL_FEATURE_NFCV true /*!< Enable/Disable RFAL support for NFC-V (ISO15693) */
" w; A3 s' W* r2 H; L1 I - #define RFAL_FEATURE_T1T true /*!< Enable/Disable RFAL support for T1T (Topaz) */
0 X P: Q2 t6 `" f2 e" E - #define RFAL_FEATURE_T2T true /*!< Enable/Disable RFAL support for T2T (Mifare) */* `3 I1 c" l# A6 a8 j. _
- #define RFAL_FEATURE_T4T true /*!< Enable/Disable RFAL support for T4T */4 P, R( `2 c' h$ X
- #define RFAL_FEATURE_ST25TB true /*!< Enable/Disable RFAL support for ST25TB */
& j. o# U. h' Z6 I" @0 G - #define RFAL_FEATURE_ST25xV true /*!< Enable/Disable RFAL support for ST25TV/ST25DV */# ?( P5 n% {+ d$ H
- #define RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG false /*!< Enable/Disable Analog Configs to be dynamically updated (RAM) */
5 ]) L5 ^ h- f- ^, U) ~9 l - #define RFAL_FEATURE_DPO false /*!< Enable/Disable RFAL dynamic power support */
* ~: q. {- Q6 @ [0 p - #define RFAL_FEATURE_ISO_DEP true /*!< Enable/Disable RFAL support for ISO-DEP (ISO14443-4) */
" n1 k- C q& `& P' x - #define RFAL_FEATURE_ISO_DEP_POLL true /*!< Enable/Disable RFAL support for Poller mode (PCD) ISO-DEP (ISO14443-4) */. ]- b. }& X, C! p
- #define RFAL_FEATURE_ISO_DEP_LISTEN true /*!< Enable/Disable RFAL support for Listen mode (PICC) ISO-DEP (ISO14443-4) */7 s" n/ u1 ]+ ~3 n
- #define RFAL_FEATURE_NFC_DEP true /*!< Enable/Disable RFAL support for NFC-DEP (NFCIP1/P2P) */
) c- O8 v1 z- B% R6 Y, \
' r$ k+ q" u$ c# N" K- #define RFAL_FEATURE_ISO_DEP_IBLOCK_MAX_LEN 256U /*!< ISO-DEP I-Block max length. Please use values as defined by rfalIsoDepFSx */
, S4 z; C) x6 c" [0 I - #define RFAL_FEATURE_NFC_DEP_BLOCK_MAX_LEN 254U /*!< NFC-DEP Block/Payload length. Allowed values: 64, 128, 192, 254 */
' h" u3 b% V4 W$ c% M6 C - #define RFAL_FEATURE_NFC_RF_BUF_LEN 258U /*!< RF buffer length used by RFAL NFC layer */; w* t! W7 C7 |6 g% T4 @
- 7 H3 E) Q! A* W8 `
- #define RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN 512U /*!< ISO-DEP APDU max length. Please use multiples of I-Block max length */$ ], f( P r; ^, t8 d
- #define RFAL_FEATURE_NFC_DEP_PDU_MAX_LEN 512U /*!< NFC-DEP PDU max length. */
复制代码 2 D4 { A9 x& a
9 T% [5 I+ Q0 R0 ^- v5 b1 T
效果演示:7 Q8 d! E+ ^* ?, Z
4 Z4 w) G! c( I/ e; t读取M1卡卡号,不支持M1协议,但是支持NRFA。
8 m% |! f: {& s5 C v3 w, ?. }4 P* [- l# \ \5 o3 i
7 S! ?9 ]9 G( W# ? a( U2 R
手机读取板子,识别为NFCF协议了,其实是因为手机啥都支持,读到的就看板子处在那种模式。9 D" C* F7 J4 Z3 C9 E1 l+ q7 R
9 b F) E" C- Y4 v% m2 F
# m; h. E0 V/ C2 M相关打印
2 C0 s& B/ V" l$ b. f8 a# Q. x4 A8 S _9 G* v' A
最后附上程序,注:为了减小代码体积,删除了CMSIS的DSP相关文件
6 A4 l" f8 A3 m* S3 _
nfc.zip
(6.59 MB, 下载次数: 0)
|