L14-Click 1.0
STM32WLE5CC LoRaWAN Sensor Platform
Loading...
Searching...
No Matches
nfc_st25dv16kc.h
Go to the documentation of this file.
1/*
2 * nfc_st25dv16kc.h
3 *
4 * Created on: 9. 3. 2026
5 * Author: Milan
6 *
7 * ST25DV16KC Dynamic NFC/RFID Tag with 16Kbit EEPROM
8 * Datasheet: https://www.st.com/resource/en/datasheet/st25dv16kc.pdf
9 *
10 * I2C User memory address : 0x53 (7-bit) = 0xA6 / 0xA7 (8-bit R/W)
11 * I2C System config address: 0x57 (7-bit) = 0xAE / 0xAF (8-bit R/W)
12 * Default I2C password : 8 x 0x00
13 *
14 * EEPROM: 2048 bytes (4-byte page write)
15 * Mailbox: 256-byte Fast Transfer Mode buffer
16 */
17
18#ifndef INC_NFC_ST25DV16KC_H_
19#define INC_NFC_ST25DV16KC_H_
20
21#include "stm32wlxx_hal.h"
22
23/* ===========================================================================
24 * Public API
25 * =========================================================================== */
26
27/**
28 * @brief Check whether the ST25DV16KC has been successfully initialised.
29 * @param hi2c Pointer to I2C handle.
30 * @param tryInit When 1, attempt Init() if not yet initialised; 0 – no retry.
31 * @retval 1 – NFC present and ready, 0 – not available.
32 */
33int8_t nfc_st25dv16kc_Is(I2C_HandleTypeDef *hi2c, int8_t tryInit);
34
35/**
36 * @brief Check the I2C bus and try to find the NFC chip.
37 * Enables the mailbox, clears it, and turns GPO off (low-power state).
38 * @param hi2c Pointer to I2C handle.
39 * @retval HAL_OK – NFC found and initialised, HAL_ERROR – not on the bus.
40 */
41HAL_StatusTypeDef nfc_st25dv16kc_Init(I2C_HandleTypeDef *hi2c);
42
43/**
44 * @brief Turn the NFC GPO ON (all events: MsgReady, FieldChange, RFWrite).
45 * Enables host-side reading/writing via the Mailbox.
46 * @param hi2c Pointer to I2C handle.
47 * @retval HAL_OK on success, HAL_ERROR if NFC not available.
48 */
49HAL_StatusTypeDef nfc_st25dv16kc_On(I2C_HandleTypeDef *hi2c);
50
51/**
52 * @brief Turn the NFC GPO OFF and enable GPO RF to achieve minimum current (~1 µA).
53 * @param hi2c Pointer to I2C handle.
54 * @retval HAL_OK on success, HAL_ERROR if NFC not available.
55 */
56HAL_StatusTypeDef nfc_st25dv16kc_Off(I2C_HandleTypeDef *hi2c);
57
58/**
59 * @brief Write data to the EEPROM user memory (4-byte page writes).
60 * @param hi2c Pointer to I2C handle.
61 * @param addr Start address within EEPROM (0x0000–0x07FF for 16Kbit).
62 * @param pData Pointer to data buffer to write.
63 * @param len Number of bytes to write.
64 * @retval HAL_OK on success, HAL_ERROR on failure or NFC absent.
65 */
66HAL_StatusTypeDef nfc_st25dv16kc_WriteEEPROM(I2C_HandleTypeDef *hi2c, uint16_t addr, uint8_t *pData, uint16_t len);
67
68/**
69 * @brief Read data from the EEPROM user memory.
70 * @param hi2c Pointer to I2C handle.
71 * @param addr Start address within EEPROM.
72 * @param pData Pointer to destination buffer.
73 * @param len Number of bytes to read.
74 * @retval HAL_OK on success, HAL_ERROR on failure or NFC absent.
75 */
76HAL_StatusTypeDef nfc_st25dv16kc_ReadEEPROM(I2C_HandleTypeDef *hi2c, uint16_t addr, uint8_t *pData, uint16_t len);
77
78/**
79 * @brief Process incoming data from the RF Mailbox.
80 * Checks MB_CTRL_DYN for an RF message; if present reads it and
81 * invokes nfc_st25dv16kc_OnMailboxData().
82 * @param hi2c Pointer to I2C handle.
83 * @retval HAL_OK – message read, HAL_ERROR – no message or NFC absent.
84 */
85HAL_StatusTypeDef nfc_st25dv16kc_ProcessMailBox(I2C_HandleTypeDef *hi2c);
86
87/**
88 * @brief Write raw data into the Mailbox so the RF reader (phone) can retrieve it.
89 * @param hi2c Pointer to I2C handle.
90 * @param pData Pointer to data buffer.
91 * @param len Number of bytes to write (max ST25DV16KC_MB_SIZE).
92 * @retval HAL_OK on success, HAL_ERROR on failure or NFC absent.
93 */
94HAL_StatusTypeDef nfc_st25dv16kc_WriteMailBox(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t len);
95
96/**
97 * @brief Weak callback invoked by nfc_st25dv16kc_ProcessMailBox() when new
98 * data has arrived in the Mailbox. Override in main.c or application
99 * code to process the received message.
100 * @param data Pointer to received data buffer.
101 * @param len Number of bytes received.
102 */
103__weak void nfc_st25dv16kc_OnMailboxData(uint8_t *data, uint16_t len);
104
105
106#endif /* INC_NFC_ST25DV16KC_H_ */
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.
HAL_StatusTypeDef nfc_st25dv16kc_ReadEEPROM(I2C_HandleTypeDef *hi2c, uint16_t addr, uint8_t *pData, uint16_t len)
Read data from the EEPROM user memory.
HAL_StatusTypeDef nfc_st25dv16kc_On(I2C_HandleTypeDef *hi2c)
Turn the NFC GPO ON (all events: MsgReady, FieldChange, RFWrite). Enables host-side reading/writing v...
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 ...
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....
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).
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...