Skip to content

Commit 7ef1c92

Browse files
committed
Add class SFE_ST25DV64KC_NDEF. Add writeCCFile methods
1 parent 9006a22 commit 7ef1c92

6 files changed

+136
-9
lines changed

keywords.txt

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ END_REGISTERS KEYWORD1
1313

1414
SFE_ST2525DV64KC_IO KEYWORD1
1515

16+
SFE_ST2525DV64KC_NDEF KEYWORD1
17+
1618
#######################################
1719
# Methods and Functions KEYWORD2
1820
#######################################
@@ -56,6 +58,9 @@ setRegisterBit KEYWORD2
5658
clearRegisterBit KEYWORD2
5759
isBitSet KEYWORD2
5860

61+
writeCCFile4Byte KEYWORD2
62+
writeCCFile8Byte KEYWORD2
63+
5964
#######################################
6065
# Constants LITERAL1
6166
#######################################

src/SparkFun_ST25DV64KC_Arduino_Library.cpp

+11-6
Original file line numberDiff line numberDiff line change
@@ -304,23 +304,28 @@ bool SFE_ST25DV64KC::getEEPROMWriteProtectionBit(uint8_t memoryArea)
304304
return false;
305305
}
306306

307-
void SFE_ST25DV64KC::writeEEPROM(uint16_t baseAddress, uint8_t *data, uint16_t dataLength)
307+
bool SFE_ST25DV64KC::writeEEPROM(uint16_t baseAddress, uint8_t *data, uint16_t dataLength)
308308
{
309309
// Disable FTM temporarily if enabled
310310
bool ftmEnabled = st25_io.isBitSet(SF_ST25DV64KC_ADDRESS::DATA, REG_FTM, BIT_FTM_MB_MODE);
311+
312+
bool success = true;
313+
311314
if (ftmEnabled)
312-
st25_io.clearRegisterBit(SF_ST25DV64KC_ADDRESS::SYSTEM, REG_FTM, BIT_FTM_MB_MODE);
315+
success &= st25_io.clearRegisterBit(SF_ST25DV64KC_ADDRESS::SYSTEM, REG_FTM, BIT_FTM_MB_MODE);
313316

314-
st25_io.writeMultipleBytes(SF_ST25DV64KC_ADDRESS::DATA, baseAddress, data, dataLength);
317+
success &= st25_io.writeMultipleBytes(SF_ST25DV64KC_ADDRESS::DATA, baseAddress, data, dataLength);
315318

316319
// Restore FTM if previously enabled
317320
if (ftmEnabled)
318-
st25_io.setRegisterBit(SF_ST25DV64KC_ADDRESS::SYSTEM, REG_FTM, BIT_FTM_MB_MODE);
321+
success &= st25_io.setRegisterBit(SF_ST25DV64KC_ADDRESS::SYSTEM, REG_FTM, BIT_FTM_MB_MODE);
322+
323+
return success;
319324
}
320325

321-
void SFE_ST25DV64KC::readEEPROM(uint16_t baseAddress, uint8_t *data, uint16_t dataLength)
326+
bool SFE_ST25DV64KC::readEEPROM(uint16_t baseAddress, uint8_t *data, uint16_t dataLength)
322327
{
323-
st25_io.readMultipleBytes(SF_ST25DV64KC_ADDRESS::DATA, baseAddress, data, dataLength);
328+
return st25_io.readMultipleBytes(SF_ST25DV64KC_ADDRESS::DATA, baseAddress, data, dataLength);
324329
}
325330

326331
bool SFE_ST25DV64KC::setMemoryAreaEndAddress(uint8_t memoryArea, uint8_t endAddressValue)

src/SparkFun_ST25DV64KC_Arduino_Library.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ class SFE_ST25DV64KC
9999
bool getEEPROMWriteProtectionBit(uint8_t memoryArea);
100100

101101
// Reads block of data from EEPROM.
102-
void readEEPROM(uint16_t baseAddress, uint8_t *data, uint16_t dataLength);
102+
bool readEEPROM(uint16_t baseAddress, uint8_t *data, uint16_t dataLength);
103103

104104
// Writes block of data to EEPROM.
105-
void writeEEPROM(uint16_t baseAddress, uint8_t *data, uint16_t dataLength);
105+
bool writeEEPROM(uint16_t baseAddress, uint8_t *data, uint16_t dataLength);
106106

107107
// Sets memory area boundary. memoryNumber ranges from 1 to 4.
108108
// endAddressValue must comply with datasheet's area size specifications (page 14).
@@ -151,4 +151,6 @@ class SFE_ST25DV64KC
151151
bool getEH_CTRL_DYNBit(uint8_t bitMask);
152152
};
153153

154+
#include "SparkFun_ST25DV64KC_NDEF.h"
155+
154156
#endif

src/SparkFun_ST25DV64KC_IO.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ bool SFE_ST2525DV64KC_IO::writeMultipleBytes(const SF_ST25DV64KC_ADDRESS address
4545
{
4646
uint8_t bytesToWrite; // Write the data in chunks of readWriteChunkSize max
4747
if ((packetLength - bytesWritten) > ((uint16_t)readWriteChunkSize))
48-
bytesToWrite = readWriteChunkSize;
48+
bytesToWrite = readWriteChunkSize - 2; // Write a maximum of readWriteChunkSize bytes total - including the register address
4949
else
5050
bytesToWrite = packetLength - bytesWritten;
5151

src/SparkFun_ST25DV64KC_NDEF.cpp

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
This is a library written for the ST25DV64KC Dynamic RFID Tag.
3+
SparkFun sells these at its website:
4+
https://www.sparkfun.com/products/
5+
6+
Do you like this library? Help support open source hardware. Buy a board!
7+
8+
Written by Paul CLark @ SparkFun Electronics, August 5th, 2021
9+
This file declares the additional functions used to read/write NDEF
10+
records from/to the ST25DV64KC Dynamic RFID Tag.
11+
12+
This program is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU General Public License for more details.
16+
You should have received a copy of the GNU General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#include "SparkFun_ST25DV64KC_NDEF.h"
21+
22+
bool SFE_ST25DV64KC_NDEF::writeCCFile4Byte(uint32_t val)
23+
{
24+
uint8_t CCFile[4];
25+
CCFile[0] = val >> 24;
26+
CCFile[1] = (val >> 16) & 0xFF;
27+
CCFile[2] = (val >> 8) & 0xFF;
28+
CCFile[3] = val & 0xFF;
29+
30+
return writeEEPROM(0x0, CCFile, 0x4);
31+
}
32+
33+
/*
34+
The Capacity Container File is written to the first eight bytes of user memory:
35+
36+
0xE2 0x40 0x00 0x01 0x00 0x00 0x03 0xFF
37+
38+
Byte 0: Magic Number
39+
The ST25DV64KC has 8kBytes of user memory so we need to select 0xE2 to select two-byte addressing
40+
Byte 1: Version and Access Condition
41+
b7 b6 = 0b01 Major Version
42+
b5 b4 = 0b00 Minor Version
43+
b3 b2 = 0x00 Read Access: Always
44+
b1 b0 = 0x00 Write Access: Always
45+
Byte 2: 0x00
46+
Byte 3: Additional Feature Information
47+
b7 b6 b5 = 0b000 RFU (Reserved Future Use)
48+
b4 = 0b0 Special Frame
49+
b3 = 0b0 Lock Block
50+
b2 b1 = 0b00 RFU
51+
b0 = 0b1 MBREAD: Read Multiple Block is supported
52+
Byte 4: 0x00 RFU (Reserved Future Use)
53+
Byte 5: 0x00 RFU (Reserved Future Use)
54+
Byte 6 + Byte 7: MLEN Encoded Memory Length
55+
MLEN = T5T_Area / 8
56+
MLEN encoding for a ST25DV64K (8192 bytes memory size) and 8 bytes capability container (CC):
57+
If the entire user memory full, user memory is used to store NDEF, T5T_Area=8192-8
58+
MLEN = (8192 – 8) / 8 = 1023 (0x03FF)
59+
*/
60+
61+
bool SFE_ST25DV64KC_NDEF::writeCCFile8Byte(uint32_t val1, uint32_t val2)
62+
{
63+
uint8_t CCFile[8];
64+
CCFile[0] = val1 >> 24;
65+
CCFile[1] = (val1 >> 16) & 0xFF;
66+
CCFile[2] = (val1 >> 8) & 0xFF;
67+
CCFile[3] = val1 & 0xFF;
68+
CCFile[4] = val2 >> 24;
69+
CCFile[5] = (val2 >> 16) & 0xFF;
70+
CCFile[6] = (val2 >> 8) & 0xFF;
71+
CCFile[7] = val2 & 0xFF;
72+
73+
return writeEEPROM(0x0, CCFile, 0x8);
74+
}

src/SparkFun_ST25DV64KC_NDEF.h

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
This is a library written for the ST25DV64KC Dynamic RFID Tag.
3+
SparkFun sells these at its website:
4+
https://www.sparkfun.com/products/
5+
6+
Do you like this library? Help support open source hardware. Buy a board!
7+
8+
Written by Ricardo Ramos @ SparkFun Electronics, January 6th, 2021
9+
This file declares all functions used in the ST25DV64KC Dynamic RFID Tag Arduino Library.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
You should have received a copy of the GNU General Public License
16+
along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#ifndef _SPARKFUN_ST25DV64KC_NDEF_
20+
#define _SPARKFUN_ST25DV64KC_NDEF_
21+
22+
#include "SparkFun_ST25DV64KC_Arduino_Library.h"
23+
24+
class SFE_ST25DV64KC_NDEF : public SFE_ST25DV64KC
25+
{
26+
public:
27+
// Default constructor.
28+
SFE_ST25DV64KC_NDEF(){};
29+
30+
// Default destructor.
31+
~SFE_ST25DV64KC_NDEF(){};
32+
33+
// Write a 4-byte CC File to user memory (e.g. ST25DV04K)
34+
bool writeCCFile4Byte(uint32_t val = 0xE1403F00);
35+
36+
// Write an 8-byte CC File to user memory (ST25DV64K)
37+
bool writeCCFile8Byte(uint32_t val1 = 0xE2400001, uint32_t val2 = 0x000003FF);
38+
39+
};
40+
41+
#endif

0 commit comments

Comments
 (0)