NT3H

A driver for the NXP NT3H2111 NFC EEPROM.

Reads and writes memory on the NT3H2111 EEPROM using I2C. The memory is organised into 16-byte blocks from the I2C perspective.

BLOCK0 contains configuration data such as the Capability Container.

Defines

ADDR_7b_MIN

Minimum value of a 7-bit device address.

ADDR_7b_MAX

Maximum value of a 7-bit device address.

WRONG_DEVADDR

A wrong NFC EEPROM device address.

BLOCK0

Address of the first memory block.

BLOCK_SESSION

Address of the memory block used for session registers.

DEVADDR_OFFSET

Byte-offset of the Device Address within the first memory block.

CC_OFFSET

Byte-offset of the Capability Container within the first memory block.

NSREG_OFFSET

Byte-offset of the NS_REG session register.

NSREG_EEPROM_WR_BUSY

Select the EEPROM Write Busy bit from NS_REG. Set to 1’b1 when a write is in progress.

BLOCKSIZE

Block size in bytes.

CC0_MAGIC

Byte 0 of the Capability Container. Magic number.

CC1_VER

Byte 1 of the Capability Container. Version.

CC2_NBYTESBY8

Byte 2 of the Capability Container. The number of bytes in memory divided by 8.

Functions

void nt3h_init_wrongaddress(void)

Deliberately assign the wrong device address to the NFC EEPROM.

This can be called to re-create a problem where the NFC EEPROM ends up with the wrong device address.

Unfortunately, the device address is mutable and located in byte 0 of memory.

When power is running low, an unwanted transaction can occur (a series of zeroes) that clears the device address.

int nt3h_check_address(void)

Ensure that the NFC EEPROM is at the expected device address.

Check that the NFC EEPROM responds. If it does not, find it on the bus by scanning all available addresses. Once found, correct the address so there is no need to scan next time.

Check that the capability container is correct. If an external device has written to the tag, it may have been altered. It is not safe to write the capability container just-in-case. This will wear out the EEPROM block.

Returns

0 if OK or 1 if the Capability Container is not correct.

void nt3h_update_cc(void)

Write the Capability Container.

Sets the CC to the values required for long NDEF messages.

The CC is 0 from the factory. It can also be altered by a phone that writes to the tag.

This is a blocking operation. It will not return until the write is done.

int nt3h_writetag(int eepromBlock, char *blkdata)

Write one block to the NFC EEPROM.

Parameters
  • eepromBlock[in] index of the block to write

  • blkdata[in] 16-byte array containing data to write

Returns

A negative value if the write has failed.

int nt3h_readtag(int eepromBlock, char *blkdata)

Read one 16-byte block from the NFC EEPROM.

Parameters
  • eepromBlock[in] index of the block to read.

  • blkdata[out] 16-byte array into which the EEPROM block contents will be read.

void nt3h_clearlock(void)

Intended to clear the I2C_LOCKED bit in the NS_REG session register.

BUG. Does not affect NS_REG. Instead writes 0x06 to NC_REG, 0x40 to LAST_NDEF_BLOCK and 0x00 to SRAM_MIRROR_BLOCK.

Does not do any harm, because the device is powered down immediately afterwards anyway. Remove in future.

int nt3h_eepromwritedone(void)

Check if an EEPROM write is in-progress.

Returns

2 when a write is in progress. Otherwise 0 when EEPROM access is possible.

Variables

unsigned char rxData[BLOCKSIZE] = {0}

Holds the content of one block.

int nsreg2
int nsreg3