L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
Loading...
Searching...
No Matches
nfc_st25dv16kc.c
Go to the documentation of this file.
1/*
2 * nfc_st25dv16kc.c
3 *
4 * Created on: 9. 3. 2026
5 * Author: Milan
6 *
7 * ST25DV16KC – Dynamic NFC/RFID Tag with 16Kbit EEPROM.
8 *
9 * I2C communication uses 16-bit register addressing throughout.
10 * All dynamic registers (0x2000-0x2107) are in the User memory address
11 * space (I2C 0xA6). System registers require password presentation before
12 * writing.
13 *
14 * Default I2C password: 8 x 0x00.
15 */
16
17#include "i2c.h"
18#include "nfc_st25dv16kc.h"
19#include <string.h>
20
21/* ---------------------------------------------------------------------------
22 * I2C addresses (8-bit, shifted for HAL)
23 * --------------------------------------------------------------------------- */
24#define ST25DV16KC_I2C_ADDR_USER (0x53 << 1) /**< User memory / EEPROM - A6 */
25#define ST25DV16KC_I2C_ADDR_SYSTEM (0x57 << 1) /**< System configuration - AE */
26
27/* ---------------------------------------------------------------------------
28 * Dynamic registers – accessible via User I2C address (16-bit addressing)
29 * --------------------------------------------------------------------------- */
30#define ST25DV16KC_REG_GPO_CTRL_DYN 0x2000U /**< GPO control (dynamic) */
31#define ST25DV16KC_REG_EH_CTRL_DYN 0x2001U /**< Energy-harvesting ctrl (dyn) */
32#define ST25DV16KC_REG_RF_MNGT_DYN 0x2002U /**< RF management (dynamic) */
33#define ST25DV16KC_REG_I2C_SSO_DYN 0x2003U /**< I2C security-session open */
34#define ST25DV16KC_REG_MB_CTRL_DYN 0x2006U /**< Mailbox control (dynamic) */
35#define ST25DV16KC_REG_MB_LEN_DYN 0x2007U /**< Mailbox message length (dyn) */
36#define ST25DV16KC_REG_MB_DATA 0x2008U /**< Mailbox RAM start (256 bytes)*/
37
38/* ---------------------------------------------------------------------------
39 * System registers – accessible via System I2C address (16-bit addressing)
40 * (require I2C password presentation for write access)
41 * --------------------------------------------------------------------------- */
42#define ST25DV16KC_SYS_REG_RF_MNGT 0x0003U /**< RF_MNGT static register */
43#define ST25DV16KC_SYS_REG_MB_MODE 0x000DU /**< Mailbox enable (static) */
44#define ST25DV16KC_SYS_REG_I2C_PWD 0x0900U /**< I2C password register */
45
46/* ---------------------------------------------------------------------------
47 * GPO_CTRL_DYN bit masks
48 * --------------------------------------------------------------------------- */
49#define ST25DV16KC_GPO_EN 0x80U /**< GPO output enable */
50#define ST25DV16KC_GPO_MSG_READY_EN 0x40U /**< GPO on mailbox message-ready */
51#define ST25DV16KC_GPO_RF_ACTIVITY 0x20U /**< GPO on RF activity */
52#define ST25DV16KC_GPO_RF_INTERRUPT 0x10U /**< GPO on RF interrupt */
53#define ST25DV16KC_GPO_FIELD_CHANGE 0x08U /**< GPO on RF field change */
54#define ST25DV16KC_GPO_RF_PUT_MSG 0x04U /**< GPO when RF writes to mailbox */
55#define ST25DV16KC_GPO_RF_GET_MSG 0x02U /**< GPO when RF reads mailbox */
56#define ST25DV16KC_GPO_RF_WRITE 0x01U /**< GPO on RF EEPROM write */
57
58/** GPO value used by nfc_st25dv16kc_On(): all events enabled */
59#define ST25DV16KC_GPO_ALL_EN (ST25DV16KC_GPO_EN | ST25DV16KC_GPO_MSG_READY_EN | \
60 ST25DV16KC_GPO_FIELD_CHANGE | ST25DV16KC_GPO_RF_WRITE)
61
62/** GPO value used by nfc_st25dv16kc_INT_On(): field-change interrupt only */
63#define ST25DV16KC_GPO_INT_EN (ST25DV16KC_GPO_EN | ST25DV16KC_GPO_FIELD_CHANGE)
64
65/* ---------------------------------------------------------------------------
66 * MB_CTRL_DYN bit masks
67 * --------------------------------------------------------------------------- */
68#define ST25DV16KC_MB_EN 0x01U /**< Enable mailbox */
69#define ST25DV16KC_MB_RF_PUT_MSG 0x02U /**< RF has written to mailbox */
70#define ST25DV16KC_MB_I2C_PUT_MSG 0x04U /**< I2C host has written to mailbox*/
71
72/* ---------------------------------------------------------------------------
73 * RF_MNGT_DYN bit masks
74 * --------------------------------------------------------------------------- */
75#define ST25DV16KC_RF_SLEEP 0x01U /**< Put RF analog block to sleep */
76#define ST25DV16KC_RF_DISABLE 0x02U /**< Fully disable RF interface */
77
78/* ---------------------------------------------------------------------------
79 * EH_CTRL_DYN bit masks
80 * --------------------------------------------------------------------------- */
81#define ST25DV16KC_EH_FIELD_ON 0x04U /**< RF field is currently detected */
82
83/* ---------------------------------------------------------------------------
84 * RF busy-wait parameters
85 * --------------------------------------------------------------------------- */
86/** Maximum number of 5 ms wait cycles before giving up (100 ms total). */
87#define ST25DV16KC_RF_BUSY_TIMEOUT 20U
88
89/* ---------------------------------------------------------------------------
90 * Mailbox size
91 * --------------------------------------------------------------------------- */
92#define ST25DV16KC_MB_SIZE 256U /**< Mailbox buffer size in bytes */
93
94/* ---------------------------------------------------------------------------
95 * Module-private state
96 * --------------------------------------------------------------------------- */
97
98/** 1 when the chip is present and successfully initialised, 0 otherwise. */
99static int8_t _isNfc = 0;
100static int8_t _isOnOff = 1; // cumulative on/off - on start is on
101#define EEPROM_TIMEOUT 5000 // because of phone and conflict with read/write the timeout must be longer
102/* ---------------------------------------------------------------------------
103 * Static (private) helpers
104 * --------------------------------------------------------------------------- */
105
106#if 0
107static HAL_StatusTypeDef nfc_st25dv16kc_PresentPassword(I2C_HandleTypeDef *hi2c)
108{
109 HAL_StatusTypeDef status;
110 uint8_t pwd_payload[17] = {0,0,0,0,0,0,0,0,9,0,0,0,0,0,0,0,0}; // toto je spravne nastavene heslo
111
112
113
114 status = HAL_I2C_Mem_Write(hi2c, ST25DV16KC_I2C_ADDR_SYSTEM, ST25DV16KC_SYS_REG_I2C_PWD, I2C_MEMADD_SIZE_16BIT, pwd_payload, sizeof(pwd_payload), 200);
115 return status;
116}
117
118
119
120/**
121 * @brief Present the default I2C password to open a security session.
122 * The payload is: [0x09 validation code] + [8-byte pwd] + [8-byte pwd].
123 * Default password is 8 x 0x00.
124 * @param hi2c Pointer to I2C handle.
125 * @retval HAL_StatusTypeDef result of the I2C write.
126 */
127static HAL_StatusTypeDef nfc_st25dv16kc_PresentPassword(I2C_HandleTypeDef *hi2c)
128{
129 HAL_StatusTypeDef status;
130// uint8_t pwd_payload[17];
131// pwd_payload[0] = 0x09; // Validation code
132
133// memset(&pwd_payload[1], 0x00, 16); // 8-byte pwd repeated twice (default)
134
135// status = HAL_I2C_Mem_Write(hi2c, ST25DV16KC_I2C_ADDR_SYSTEM, ST25DV16KC_SYS_REG_I2C_PWD, I2C_MEMADD_SIZE_16BIT, pwd_payload, 17, 200);
136
137 uint8_t pwd_payload[9];
138 pwd_payload[8] = 0x09; // Validation code
139
140 static uint8_t ppp = 0;
141 int i;
142 char buf[9] = {};
143 for (i=0; i<8; i++)
144 {
145 pwd_payload[i] = ((ppp>>i) & 1);
146 buf[i] = pwd_payload[i]+'0';
147 }
148 ++ppp;
149 writeLog(buf);
150
151
152
153 //memset(&pwd_payload[1], 0x01, 8); // 8-byte pwd repeated twice (default)
154 status = HAL_I2C_Mem_Write(hi2c, ST25DV16KC_I2C_ADDR_SYSTEM, ST25DV16KC_SYS_REG_I2C_PWD, I2C_MEMADD_SIZE_16BIT, pwd_payload, sizeof(pwd_payload), 200);
155 if (status == HAL_OK)
156 {
157
158 HAL_Delay(10);
159
160 //uint8_t lock = 0;
161 //status = HAL_I2C_Mem_Read(hi2c, ST25DV16KC_I2C_ADDR_SYSTEM, 0x0801, I2C_MEMADD_SIZE_16BIT, &lock, 1, 100);
162 //if (status == HAL_OK)
163 // writeLog("pwdOK:%d", (int)lock);
164 }
165
166
167 return status;
168}
169
170static HAL_StatusTypeDef nfc_st25dv16kc_SetRFMgmt(I2C_HandleTypeDef *hi2c, uint8_t enable)
171{
172 HAL_StatusTypeDef status = HAL_ERROR;
173 uint8_t val = enable ? 0x00 : 0x01; // 0 = RF Enabled, 1 = RF Disabled
174
175 if (_isNfc)
176 do
177 {
178 if ((status = nfc_st25dv16kc_PresentPassword(hi2c)) != HAL_OK)
179 break;
180 if ((status = HAL_I2C_Mem_Write(hi2c, ST25DV16KC_I2C_ADDR_SYSTEM, 0x0003, 2, &val, 1, 100)) != HAL_OK)
181 break;
182 }while(0);
183 return status;
184}
185
186
187#define ST25_ADDR_SYST 0xAE
188#define ST25_ADDR_USER 0xA6
189
190// Default values for common System Registers
191#define REG_GPO_DEFAULT 0x00 // All interrupts disabled, active low
192#define REG_RF_MNGT_DEFAULT 0x00 // RF enabled, no sleep
193#define REG_IT_TIME_DEFAULT 0x03 // Standard pulse duration
194static HAL_StatusTypeDef ST25_FactoryReset_Config(I2C_HandleTypeDef *hi2c)
195{
196 HAL_StatusTypeDef status;
197 uint8_t data;
198
199
200 nfc_st25dv16kc_PresentPassword(hi2c);
201
202 // 1. Reset GPO Strategy (Address 0x0000 in System Area)
203 data = REG_GPO_DEFAULT;
204 status = HAL_I2C_Mem_Write(hi2c, ST25_ADDR_SYST, 0x0000,
205 I2C_MEMADD_SIZE_16BIT, &data, 1, 100);
206 if (status != HAL_OK) return status;
207
208 // 2. Reset RF Management (Address 0x0003 in System Area)
209 data = REG_RF_MNGT_DEFAULT;
210 status = HAL_I2C_Mem_Write(hi2c, ST25_ADDR_SYST, 0x0003,
211 I2C_MEMADD_SIZE_16BIT, &data, 1, 100);
212
213 // 3. Clear User Memory (Optional but recommended for 'Full' reset)
214 // For the 16KC (2KB), we loop through blocks.
215 uint8_t empty[16] = {0};
216 for(uint16_t i = 0; i < 2048; i += 16) {
217 HAL_I2C_Mem_Write(hi2c, ST25_ADDR_USER, i,
218 I2C_MEMADD_SIZE_16BIT, empty, 16, 100);
219 HAL_Delay(5); // EEPROM write cycle time
220 }
221
222 return status;
223}
224#endif
225/**
226 * @brief Write a value to GPO_CTRL_DYN with retry to tolerate transient NACKs
227 * from the RF field.
228 * @param hi2c Pointer to I2C handle.
229 * @param value Byte value to write to GPO_CTRL_DYN.
230 * @retval HAL_StatusTypeDef result of the last I2C write attempt.
231 */
232static HAL_StatusTypeDef nfc_st25dv16kc_WriteGPO(I2C_HandleTypeDef *hi2c, uint8_t value)
233{
234 HAL_StatusTypeDef status = HAL_ERROR;
235 uint8_t reg_val = value;
236 uint8_t i;
237
238 for (i = 0; i < 5; i++)
239 {
240 status = HAL_I2C_Mem_Write(hi2c, ST25DV16KC_I2C_ADDR_USER, ST25DV16KC_REG_GPO_CTRL_DYN, I2C_MEMADD_SIZE_16BIT, &reg_val, 1, 100);
241 if (status == HAL_OK)
242 break;
243 HAL_Delay(10);
244 }
245 /* If repeated failures, the chip is no longer responding */
246 _isNfc = (status == HAL_OK);
247 return status;
248}
249
250/* ---------------------------------------------------------------------------
251 * Public API implementation
252 * --------------------------------------------------------------------------- */
253
254int8_t nfc_st25dv16kc_Is(I2C_HandleTypeDef *hi2c, int8_t tryInit)
255{
256 if (!_isNfc && tryInit)
258 return _isNfc;
259}
260
261HAL_StatusTypeDef nfc_st25dv16kc_Init(I2C_HandleTypeDef *hi2c)
262{
263 HAL_StatusTypeDef status;
264
265 do
266 {
267 /* 1. Verify the chip is on the I2C bus */
268 if ((status = I2C_IsDeviceReadyMT(hi2c, ST25DV16KC_I2C_ADDR_USER, 10, 100)) != HAL_OK)
269 break;
270
271
272 // on ST25DV16KC-J - LoRa_PHT v1 is mail box not available
273#if 0
274
275
276 /* 2. Enable the Mailbox (MB_EN bit in MB_CTRL_DYN).
277 * Use a retry loop because an active RF field may cause a NACK.*/
278
279 // before mailbox - the password
280 if ((status = nfc_st25dv16kc_PresentPassword(hi2c)) != HAL_OK)
281 break;
282
283
284
285 uint8_t reg_val = ST25DV16KC_MB_EN;
286 uint8_t i;
287 for (i = 0; i < 5; i++)
288 {
289 status = HAL_I2C_Mem_Write(hi2c, ST25DV16KC_I2C_ADDR_USER, ST25DV16KC_REG_MB_CTRL_DYN, I2C_MEMADD_SIZE_16BIT, &reg_val, 1, 100);
290 if (status == HAL_OK)
291 break;
292 HAL_Delay(10);
293 }
294 if (status != HAL_OK)
295 break;
296
297 /* 3. Wait for the mailbox to stabilise */
298 HAL_Delay(50);
299#endif
300
301 /* 5. Mark as present and switch GPO off (lowest-power default) */
302 _isNfc = 1;
303 nfc_st25dv16kc_Off(hi2c);
304
305 } while (0);
306
307 return status;
308}
309
310HAL_StatusTypeDef nfc_st25dv16kc_IsOn(I2C_HandleTypeDef *hi2c, uint8_t *onOff)
311{
312 HAL_StatusTypeDef status = HAL_ERROR;
313
314 if (_isNfc)
315 {
316 uint8_t reg_val = 0;
317 status = HAL_I2C_Mem_Read(hi2c, ST25DV16KC_I2C_ADDR_USER, ST25DV16KC_REG_GPO_CTRL_DYN, I2C_MEMADD_SIZE_16BIT, &reg_val, 1, 100);
318 if (status == HAL_OK && onOff != NULL)
319 *onOff = (reg_val & ST25DV16KC_GPO_EN) ? 1U : 0U;
320 }
321 return status;
322}
323
324HAL_StatusTypeDef nfc_st25dv16kc_On(I2C_HandleTypeDef *hi2c)
325{
326 HAL_StatusTypeDef status = HAL_ERROR;
327
328 if (_isNfc)
329 {
330 status = HAL_OK;
331 if (_isOnOff++ == 0)
332 {
333 /* Enable GPO with all relevant event bits:
334 * GPO_EN | MSG_READY | FIELD_CHANGE | RF_WRITE = 0xC9 */
336 }
337 }
338 return status;
339}
340
341HAL_StatusTypeDef nfc_st25dv16kc_Off(I2C_HandleTypeDef *hi2c)
342{
343 HAL_StatusTypeDef status = HAL_ERROR;
344
345 if (_isNfc)
346 {
347 status = HAL_OK;
348
349 if (_isOnOff > 0)
350 {
351 if (--_isOnOff == 0)
352 {
353 /* Disable GPO output */
354 //status = nfc_st25dv16kc_WriteGPO(hi2c, 0x00); //leave all to by availble on phone
355 status = nfc_st25dv16kc_WriteGPO(hi2c, ST25DV16KC_GPO_EN); // GPO-INT
356
357 /* Put RF to sleep for minimum current consumption (~1 µA).
358 * RF_MNGT_DYN is a dynamic register – no password required. */
359 if (status == HAL_OK)
360 {
361 uint8_t rf_val = ST25DV16KC_RF_SLEEP;
362 status = HAL_I2C_Mem_Write(hi2c, ST25DV16KC_I2C_ADDR_USER, ST25DV16KC_REG_RF_MNGT_DYN, I2C_MEMADD_SIZE_16BIT, &rf_val, 1, 100);
363 }
364 }
365 }
366 }
367 return status;
368}
369
370#if 0
371int8_t nfc_st25dv16kc_IsRFBusy(I2C_HandleTypeDef *hi2c)
372{
373 uint8_t reg_val = 0;
374
375 if (_isNfc)
376 {
377
378 /* Read RF_MNGT_DYN (0x2002); bit 1 = FIELD_ON – RF field is present.
379 * If the I2C read fails assume the field is not active. */
380 if (HAL_I2C_Mem_Read(hi2c, ST25DV16KC_I2C_ADDR_USER, ST25DV16KC_REG_RF_MNGT_DYN, // <-- was REG_EH_CTRL_DYN
381 I2C_MEMADD_SIZE_16BIT, &reg_val, 1, 50) != HAL_OK)
382 return 0;
383
384 /* FIELD_ON is bit 1 of RF_MNGT_DYN */
385 }
386 return (reg_val & 0x02U) ? 1 : 0; // <-- was 0x04 on EH_CTRL_DYN
387}
388#endif
389
390HAL_StatusTypeDef nfc_st25dv16kc_WriteEEPROM(I2C_HandleTypeDef *hi2c, uint16_t addr, uint8_t *pData, uint16_t len)
391{
392 HAL_StatusTypeDef status = HAL_ERROR;
393
394 if (_isNfc)
395 {
396 status = HAL_OK;
397
398 /* Wait for RF write to complete
399 uint8_t retry_count = 0;
400 while (nfc_st25dv16kc_IsRFBusy(hi2c))
401 {
402 HAL_Delay(5);
403 if (++retry_count >= ST25DV16KC_RF_BUSY_TIMEOUT)
404 {
405 status = HAL_TIMEOUT;
406 break;
407 }
408 }*/
409 if (status == HAL_OK)
410 do
411 {
412 uint16_t i = 0;
413 while (i < len)
414 {
415 /* ST25DV page size is 4 bytes for write operations */
416 /* Clip chunk to: remaining bytes, max 4, and must not cross 4-byte page */
417 uint16_t page_offset = (addr + i) % 4; // offset within current 4-byte page
418 uint16_t max_in_page = 4 - page_offset; // bytes left in this page
419 uint16_t remaining = len - i;
420 uint16_t chunk = remaining < max_in_page ? remaining : max_in_page;
421
422 /* Poll for ACK — device NACKs during internal write cycle */
423 uint8_t retry = 0;
424 do
425 {
426 if ((status = HAL_I2C_Mem_Write(hi2c, ST25DV16KC_I2C_ADDR_USER, addr + i, I2C_MEMADD_SIZE_16BIT, &pData[i], chunk, EEPROM_TIMEOUT)) == HAL_OK)
427 break; // break on HAL_OK, do no need more attempts
428 HAL_Delay(2);
429 } while (++retry < 10);
430
431 if (status != HAL_OK)
432 break;
433 i += chunk;
434 HAL_Delay(6); // tW: ensure write cycle completes before next page
435 }
436 } while (0);
437 }
438 return status;
439}
440
441HAL_StatusTypeDef nfc_st25dv16kc_ReadEEPROM(I2C_HandleTypeDef *hi2c, uint16_t addr, uint8_t *pData, uint16_t len)
442{
443 HAL_StatusTypeDef status = HAL_ERROR;
444
445 if (_isNfc)
446 status = HAL_I2C_Mem_Read(hi2c, ST25DV16KC_I2C_ADDR_USER, addr, I2C_MEMADD_SIZE_16BIT, pData, len, EEPROM_TIMEOUT);
447 return status;
448}
449
450HAL_StatusTypeDef nfc_st25dv16kc_ProcessMailBox(I2C_HandleTypeDef *hi2c)
451{
452 uint8_t mb_ctrl = 0;
453 uint8_t mb_len = 0;
454
455 if (!_isNfc)
456 return HAL_ERROR;
457
458 /* Read mailbox control register to check for an RF-sourced message */
459 if (HAL_I2C_Mem_Read(hi2c, ST25DV16KC_I2C_ADDR_USER,
460 ST25DV16KC_REG_MB_CTRL_DYN, I2C_MEMADD_SIZE_16BIT, &mb_ctrl, 1, 100) != HAL_OK)
461 return HAL_ERROR;
462
463 if (mb_ctrl & ST25DV16KC_MB_RF_PUT_MSG)
464 {
465 /* Get message length (register value = length - 1) */
466 if (HAL_I2C_Mem_Read(hi2c, ST25DV16KC_I2C_ADDR_USER,
467 ST25DV16KC_REG_MB_LEN_DYN, I2C_MEMADD_SIZE_16BIT, &mb_len, 1, 100) != HAL_OK)
468 return HAL_ERROR;
469
470 uint16_t msg_len = (uint16_t) mb_len + 1U;
471 if (msg_len > ST25DV16KC_MB_SIZE)
472 msg_len = ST25DV16KC_MB_SIZE;
473
474 uint8_t buffer[ST25DV16KC_MB_SIZE];
475 if (HAL_I2C_Mem_Read(hi2c, ST25DV16KC_I2C_ADDR_USER,
476 ST25DV16KC_REG_MB_DATA, I2C_MEMADD_SIZE_16BIT, buffer, msg_len, 300) != HAL_OK)
477 return HAL_ERROR;
478
479 nfc_st25dv16kc_OnMailboxData(buffer, msg_len);
480 return HAL_OK;
481 }
482
483 return HAL_ERROR; /* No RF message pending */
484}
485
486HAL_StatusTypeDef nfc_st25dv16kc_WriteMailBox(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t len)
487{
488 HAL_StatusTypeDef status = HAL_ERROR;
489 uint8_t reg_val;
490
491 if (_isNfc)
492 {
493 if (len > ST25DV16KC_MB_SIZE)
494 len = ST25DV16KC_MB_SIZE;
495
496 do
497 {
498 /* Enable mailbox before writing */
499 reg_val = ST25DV16KC_MB_EN;
500 if ((status = HAL_I2C_Mem_Write(hi2c, ST25DV16KC_I2C_ADDR_USER, ST25DV16KC_REG_MB_CTRL_DYN, I2C_MEMADD_SIZE_16BIT, &reg_val, 1, 100)) != HAL_OK)
501 break;
502
503 /* Write payload into mailbox RAM */
504 if ((status = HAL_I2C_Mem_Write(hi2c, ST25DV16KC_I2C_ADDR_USER, ST25DV16KC_REG_MB_DATA, I2C_MEMADD_SIZE_16BIT, pData, len, 300)) != HAL_OK)
505 break;
506 }while(0);
507 }
508 return status;
509}
510
511__weak void nfc_st25dv16kc_OnMailboxData(uint8_t *data, uint16_t len)
512{
513 /* Override in application code to handle received mailbox messages */
514 (void) data;
515 (void) len;
516}
This file contains all the function prototypes for the i2c.c file.
HAL_StatusTypeDef I2C_IsDeviceReadyMT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint32_t Trials, uint32_t Timeout)
Wrapper around HAL_I2C_IsDeviceReady() that recovers from a busy bus. If the HAL I2C bus is in a BUSY...
Definition i2c.c:158
void writeLog(const char *format,...)
Format and send a log message over UART (printf-style). Available only when WRITELOG is defined; comp...
Definition main.c:105
HAL_StatusTypeDef nfc_st25dv16kc_WriteMailBox(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t len)
Write raw data into the Mailbox so the RF reader (phone) can retrieve it.
#define ST25DV16KC_MB_SIZE
#define ST25DV16KC_GPO_ALL_EN
HAL_StatusTypeDef nfc_st25dv16kc_ReadEEPROM(I2C_HandleTypeDef *hi2c, uint16_t addr, uint8_t *pData, uint16_t len)
Read data from the EEPROM user memory.
#define ST25DV16KC_SYS_REG_I2C_PWD
#define ST25DV16KC_REG_RF_MNGT_DYN
#define ST25DV16KC_REG_MB_DATA
HAL_StatusTypeDef nfc_st25dv16kc_On(I2C_HandleTypeDef *hi2c)
Turn the NFC GPO ON (all events: MsgReady, FieldChange, RFWrite). Enables host-side reading/writing v...
#define ST25DV16KC_RF_SLEEP
HAL_StatusTypeDef nfc_st25dv16kc_ProcessMailBox(I2C_HandleTypeDef *hi2c)
Process incoming data from the RF Mailbox. Checks MB_CTRL_DYN for an RF message; if present reads it ...
#define ST25DV16KC_REG_MB_LEN_DYN
#define EEPROM_TIMEOUT
#define ST25DV16KC_I2C_ADDR_USER
HAL_StatusTypeDef nfc_st25dv16kc_Off(I2C_HandleTypeDef *hi2c)
Turn the NFC GPO OFF and enable GPO RF to achieve minimum current (~1 µA).
__weak void nfc_st25dv16kc_OnMailboxData(uint8_t *data, uint16_t len)
Weak callback invoked by nfc_st25dv16kc_ProcessMailBox() when new data has arrived in the Mailbox....
HAL_StatusTypeDef nfc_st25dv16kc_IsOn(I2C_HandleTypeDef *hi2c, uint8_t *onOff)
#define ST25DV16KC_REG_MB_CTRL_DYN
int8_t nfc_st25dv16kc_Is(I2C_HandleTypeDef *hi2c, int8_t tryInit)
Check whether the ST25DV16KC has been successfully initialised.
HAL_StatusTypeDef nfc_st25dv16kc_WriteEEPROM(I2C_HandleTypeDef *hi2c, uint16_t addr, uint8_t *pData, uint16_t len)
Write data to the EEPROM user memory (4-byte page writes).
#define ST25DV16KC_MB_EN
HAL_StatusTypeDef nfc_st25dv16kc_Init(I2C_HandleTypeDef *hi2c)
Check the I2C bus and try to find the NFC chip. Enables the mailbox, clears it, and turns GPO off (lo...
static HAL_StatusTypeDef nfc_st25dv16kc_WriteGPO(I2C_HandleTypeDef *hi2c, uint8_t value)
Write a value to GPO_CTRL_DYN with retry to tolerate transient NACKs from the RF field.
#define ST25DV16KC_I2C_ADDR_SYSTEM
#define ST25DV16KC_GPO_EN
#define ST25DV16KC_MB_RF_PUT_MSG
static int8_t _isNfc
static int8_t _isOnOff
#define ST25DV16KC_REG_GPO_CTRL_DYN
void HAL_Delay(__IO uint32_t Delay)
Definition sys_app.c:369