题目说是操作,其实主要是移植。该芯片支持iic与spi两种操作方式,对于现在我使用的NFC06A1扩展板来说,默认即为spi模式,本文将记录下移植时需要注意的点.& J4 F/ ~4 k; U! d8 m7 E2 X
1.原理图
2 T9 }0 Y9 p5 i: o# H8 p, j* O/ }
Z& H4 F) A. E
扩展板引脚标注与实际板卡的引脚是不同的,这里需要根据实际修改一下。
1 y- f% c2 D$ T7 [
1 t* u+ G. h- X I5 l2.spi配置
% c+ ~8 \7 |: {& d4 T' l8 z
# |0 K- P% z$ Q* x
上图是本次移植中,笔者使用的配置,亲测可行2 D- [# E# X# x1 C A+ Q. i
5 I1 r7 v4 D+ O3 M" z! {+ a* l
3.外部中断配置
0 p/ y4 R9 y, x8 x; T6 j4 b# { P- /**
, B2 ?1 S+ q3 Q) V% U - * @brief This function handles EXTI line3 interrupt.
M6 X: A. Z+ j/ d2 h m% R$ r - */7 h3 }( D5 C/ l# |) K! N n
- void EXTI3_IRQHandler(void)3 ?/ ^! R/ G; ]+ z
- {
1 g- k& q9 m3 `! H8 w; J5 F4 M - /* USER CODE BEGIN EXTI3_IRQn 0 */
* I% L- e* L# j2 _ - % {" M3 u: x! w* f% ^% s& K
- /* USER CODE END EXTI3_IRQn 0 */
; M$ j2 a% z) S) v4 [ - HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_3);& m# R: [7 _7 Z/ `
- /* USER CODE BEGIN EXTI3_IRQn 1 */
) @9 F. _. m2 R3 |2 R - st25r3916Isr();
5 W0 ?3 C8 \* e - /* USER CODE END EXTI3_IRQn 1 */5 E T: ]3 g# f s
- }
复制代码 需要在外部中断中加入st25r3916Isr();处理。注意:该函数操作了接口的读写,如果使用spi中断或者iic中断接受需要注意。建议使用操作系统的时候使用通知进行操作。
( ~' D9 M6 y2 \! `. b0 \! [: Y/ U3 n# ~( s# O' ^, ?& p; I
3 `: ~! M- u9 V# Q+ U4.代码配置
_5 X7 r( S7 L9 u8 t9 n基本所有的配置都集中在platform.h文件里面。下面代码是关于NFC支持相关功能的开关。
$ \( R6 O1 \, p0 {! W* o5 j- #define RFAL_FEATURE_LISTEN_MODE true /*!< Enable/Disable RFAL support for Listen Mode */
/ N7 I5 A6 E1 A0 ~' w3 f - #define RFAL_FEATURE_WAKEUP_MODE true /*!< Enable/Disable RFAL support for the Wake-Up mode */
" \( T9 r) t$ n( o6 G6 l - #define RFAL_FEATURE_NFCA true /*!< Enable/Disable RFAL support for NFC-A (ISO14443A) */
$ [- O6 o; |0 l j4 ^1 \: s. w* [ - #define RFAL_FEATURE_NFCB true /*!< Enable/Disable RFAL support for NFC-B (ISO14443B) *// N; R+ n& {3 l
- #define RFAL_FEATURE_NFCF true /*!< Enable/Disable RFAL support for NFC-F (FeliCa) */
& X7 W1 {, c! e+ L5 [6 X1 o - #define RFAL_FEATURE_NFCV true /*!< Enable/Disable RFAL support for NFC-V (ISO15693) */; c: @& o5 _- x9 S Y
- #define RFAL_FEATURE_T1T true /*!< Enable/Disable RFAL support for T1T (Topaz) */
; ?- m) W S- A; x - #define RFAL_FEATURE_T2T true /*!< Enable/Disable RFAL support for T2T (Mifare) */
7 a- W* h2 v& g7 w& n. P8 }5 V: G - #define RFAL_FEATURE_T4T true /*!< Enable/Disable RFAL support for T4T */! S9 x, U& s! {$ j0 M# g0 ^# X
- #define RFAL_FEATURE_ST25TB true /*!< Enable/Disable RFAL support for ST25TB */
* v/ v' c& y9 Z9 e* b - #define RFAL_FEATURE_ST25xV true /*!< Enable/Disable RFAL support for ST25TV/ST25DV */4 g6 Z3 Y5 Q/ f: ?( ^- f
- #define RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG false /*!< Enable/Disable Analog Configs to be dynamically updated (RAM) */9 C3 h8 Z V. D9 Z- Z! E2 `6 K
- #define RFAL_FEATURE_DPO false /*!< Enable/Disable RFAL dynamic power support */5 J7 [! J% }2 [8 {5 c5 i* i
- #define RFAL_FEATURE_ISO_DEP true /*!< Enable/Disable RFAL support for ISO-DEP (ISO14443-4) */# m2 @, n+ X0 x3 T$ n) S
- #define RFAL_FEATURE_ISO_DEP_POLL true /*!< Enable/Disable RFAL support for Poller mode (PCD) ISO-DEP (ISO14443-4) */1 N# N! r3 s2 z6 Z. o( r1 T& j" T4 f
- #define RFAL_FEATURE_ISO_DEP_LISTEN true /*!< Enable/Disable RFAL support for Listen mode (PICC) ISO-DEP (ISO14443-4) */
3 l) k- V* G5 }$ a - #define RFAL_FEATURE_NFC_DEP true /*!< Enable/Disable RFAL support for NFC-DEP (NFCIP1/P2P) */; r, g$ A' z1 n' i
- ) n2 K+ p4 V5 b& U. ]5 h7 q
- #define RFAL_FEATURE_ISO_DEP_IBLOCK_MAX_LEN 256U /*!< ISO-DEP I-Block max length. Please use values as defined by rfalIsoDepFSx */# t) Y/ a$ I# `/ @# ^7 P# K
- #define RFAL_FEATURE_NFC_DEP_BLOCK_MAX_LEN 254U /*!< NFC-DEP Block/Payload length. Allowed values: 64, 128, 192, 254 */4 x6 J! N! C C% k w9 c- X2 r) X
- #define RFAL_FEATURE_NFC_RF_BUF_LEN 258U /*!< RF buffer length used by RFAL NFC layer */
4 `; e. h# |4 i/ L/ h
2 r. v) q; m" W% h: }* S- D# {- #define RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN 512U /*!< ISO-DEP APDU max length. Please use multiples of I-Block max length */+ S) O2 x' _# a; [' I
- #define RFAL_FEATURE_NFC_DEP_PDU_MAX_LEN 512U /*!< NFC-DEP PDU max length. */
复制代码 0 d: h" y' G5 d# h' R n8 g
: ]$ J& d3 k! `% R& w/ k效果演示:
/ a: a! A& M# ^5 m
' i# ~4 N; I* D7 W$ J) Z q读取M1卡卡号,不支持M1协议,但是支持NRFA。
& S9 i2 @4 i: [" ?. p4 Q2 s! e1 ~& w/ a
5 Q1 r- i2 \# k) g' z手机读取板子,识别为NFCF协议了,其实是因为手机啥都支持,读到的就看板子处在那种模式。
" |4 k# n6 y9 x" ^' c, F
1 \ x; m2 j1 d) o/ C; x
5 c2 q7 Q/ f6 s f3 H' b1 c) P
相关打印
' ~; z R" ~* ~7 g* p! v) n
/ T/ q7 ~8 j" c: j! Z. a最后附上程序,注:为了减小代码体积,删除了CMSIS的DSP相关文件
4 ^6 Q+ F, v2 W
nfc.zip
(6.59 MB, 下载次数: 0)
|