upm  0.4.1
Sensor/Actuator repository for libmraa (v0.8.0)
Classes | Public Member Functions | Static Public Attributes | List of all members

C++ API for the M24LR64E-based Grove NFC Tag. More...

Detailed Description

Grove NFC tag is an 8KB electrically erasable programmable read-only memory (EEPROM) that can be written to or read from using I2C and NFC-equipped devices.

The user mode (default) allows read and write access to all 8KB of space, provided the sector security status (SSS) allows it. The root mode allows modification of the SSS data and other information, provided the proper password is submitted. The default password for a new tag is 0x00000000. See the datasheet for more details.

The Seeed Studio* wiki page for this device includes a link to an Android* application that can be used to also read and write the device via NFC, as well as set NFC passwords, which cannot be done via I2C.

m24lr64e.jpg
// Instantiate an M24LR64E on I2C bus 0
// This example accesses the device in the 'user' (default) mode,
// reads the last byte of data in the EEPROM, inverts it, writes
// it back, and then re-reads it.
// Read the last byte of the EEPROM area
int addr = upm_m24lr64e.M24LR64E.EEPROM_I2C_LENGTH - 1;
System.out.println("Address: " + addr);
short read = nfcTag.readByte(addr);
System.out.println("Read: " + read);
// Now change it to it's opposite and write it
read = (short) (~read & 0xff);
nfcTag.writeByte(addr, read);
System.out.println("Wrote: " + read);
// Now read it back
read = nfcTag.readByte(addr);
System.out.println("Read: " + read);

Classes

class  AccessMode
 
class  M24LR64E_ADDR_T
 
class  SectorAccessRight
 
class  SectorSelectPassWd
 

Public Member Functions

synchronized void delete ()
 
 M24LR64E (int bus, M24LR64E.AccessMode mode)
 
 M24LR64E (int bus)
 
boolean submitPasswd (long passwd)
 
boolean writePasswd (long passwd)
 
void sectorProtectConfig (long sectorNumber, boolean protectEnable, M24LR64E.SectorAccessRight accessRight, M24LR64E.SectorSelectPassWd passwd)
 
void clearSectorProtect ()
 
void sectorWriteLockBit (long sectorNumber, boolean sockEnable)
 
short getDSFID ()
 
short getAFI ()
 
byte[] getUID ()
 
long getMemorySize ()
 
void clearMemory ()
 
int writeByte (long address, short data)
 
int writeBytes (long address, byte[] buffer)
 
short readByte (long address)
 
int readBytes (long address, byte[] buffer)
 

Static Public Attributes

static final int EEPROM_I2C_LENGTH = javaupm_m24lr64eJNI.M24LR64E_EEPROM_I2C_LENGTH_get()
 
static final int PASSWORD_LENGTH = javaupm_m24lr64eJNI.M24LR64E_PASSWORD_LENGTH_get()
 
static final int SECTOR_SECURITY_STATUS_BASE_ADDR = javaupm_m24lr64eJNI.M24LR64E_SECTOR_SECURITY_STATUS_BASE_ADDR_get()
 
static final short LOCK_PROTECT_BIT = javaupm_m24lr64eJNI.M24LR64E_LOCK_PROTECT_BIT_get()
 
static final short WRITE_READ_PROTECT_BIT = javaupm_m24lr64eJNI.M24LR64E_WRITE_READ_PROTECT_BIT_get()
 
static final short PASSWORD_CTRL_BIT = javaupm_m24lr64eJNI.M24LR64E_PASSWORD_CTRL_BIT_get()
 
static final int UID_LENGTH = javaupm_m24lr64eJNI.M24LR64E_UID_LENGTH_get()
 
static final long I2C_WRITE_TIME = javaupm_m24lr64eJNI.M24LR64E_I2C_WRITE_TIME_get()
 

Constructor & Destructor Documentation

M24LR64E ( int  bus,
M24LR64E.AccessMode  mode 
)

M24LR64E constructor

Parameters
busI2C bus to use
modeAccess mode (user or root) to use

Member Function Documentation

void clearMemory ( )

Sets all memory to 0, if permissions allow

short getAFI ( )

Returns an application family identifier (AFI) Must be in the root mode.

Returns
AFI
short getDSFID ( )

Returns a data storage family identifier (DSFID) Must be in the root mode.

Returns
DSFID
long getMemorySize ( )

Returns the memory size Must be in the root mode.

Returns
Amount of memory present
byte [] getUID ( )

Returns a unique ID. Must be in the root mode. Maintained to preserve compatibility with older code.

Returns
buf Buffer to hold the UID. Must be UID_LENGTH bytes.
short readByte ( long  address)

Reads a byte from the EEPROM

Parameters
addressAddress to read from
Returns
data Value read
void sectorProtectConfig ( long  sectorNumber,
boolean  protectEnable,
M24LR64E.SectorAccessRight  accessRight,
M24LR64E.SectorSelectPassWd  passwd 
)

Sets a protection bit for a sector. Must be in the root mode

Parameters
sectorNumberSector whose protection you are modifying
protectEnableTrue if you are enabling protection
accessRightAccess rights to set
passwdPassword number to enable, if any
void sectorWriteLockBit ( long  sectorNumber,
boolean  sockEnable 
)

Sets or clears a sector security status lock bit for a sector. Must be in the root mode.

Parameters
sectorNumberSector whose SSS you want to modify
sockEnableTrue to set the bit, false to clear it
boolean submitPasswd ( long  passwd)

Submits an I2C access password

Parameters
passwd4-byte access password
int writeByte ( long  address,
short  data 
)

Writes a byte to the EEPROM

Parameters
addressAddress to write to
dataData to write
boolean writePasswd ( long  passwd)

Writes a new I2C password

Parameters
passwd4-byte access password

The documentation for this class was generated from the following file: