upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes
M24LR64E Class Reference

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
upm::M24LR64E *nfcTag = new upm::M24LR64E(M24LR64E_I2C_BUS);
// 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 = M24LR64E::EEPROM_I2C_LENGTH - 1;
printf("Address: %d\n", addr);
uint8_t byte = nfcTag->readByte(addr);
printf("Read byte: %02x\n", byte);
// Now change it to it's opposite and write it
byte = ~byte;
nfcTag->writeByte(addr, byte);
printf("Wrote inverted byte: %02x\n", byte);
// Now read it back.
byte = nfcTag->readByte(addr);
printf("Read byte: %02x\n", byte);

Public Types

enum  M24LR64E_ADDR_T {
  I2C_PASSWORD_ADDR = 2304, RF_PASSWORD_1_ADDR = 2308, RF_PASSWORD_2_ADDR = 2312, RF_PASSWORD_3_ADDR = 2316,
  DSFID_ADDR = 2320, AFI_ADDR = 2321, RESV_ADDR = 2322, CONFIG_ADDR = 2323,
  UID_ADDR = 2324, MEM_SIZE_ADDR = 2332, IC_REF_ADDR = 2335, PROG_COMP_ENERGY_HARVEST_ADDR = 2339
}
 
enum  AccessMode { USER_MODE = 0x0, ROOT_MODE = 0x1 }
 
enum  SectorAccessRight { Access_1110 = 0, Access_1111 = 1, Access_1100 = 2, Access_0111 = 3 }
 
enum  SectorSelectPassWd { noPasswd = 0, passwd_1 = 1, passwd_2 = 2, passwd_3 = 3 }
 

Public Member Functions

 M24LR64E (int bus, AccessMode mode=USER_MODE)
 
 ~M24LR64E ()
 
bool submitPasswd (uint32_t passwd)
 
bool writePasswd (uint32_t passwd)
 
void sectorProtectConfig (unsigned int sectorNumber, bool protectEnable, SectorAccessRight accessRight, SectorSelectPassWd passwd)
 
void clearSectorProtect (void)
 
void sectorWriteLockBit (unsigned int sectorNumber, bool sockEnable)
 
uint8_t getDSFID ()
 
uint8_t getAFI ()
 
uint8_t * getUID ()
 
uint32_t getMemorySize ()
 
void clearMemory ()
 
mraa::Result writeByte (unsigned int address, uint8_t data)
 
mraa::Result writeBytes (unsigned int address, uint8_t *buffer, int len)
 
uint8_t readByte (unsigned int address)
 
int readBytes (unsigned int address, uint8_t *buffer, int len)
 

Static Public Attributes

static const int EEPROM_I2C_LENGTH = 8192
 
static const int PASSWORD_LENGTH = 4
 
static const int SECTOR_SECURITY_STATUS_BASE_ADDR = 0x800
 
static const uint8_t LOCK_PROTECT_BIT = 0x01
 
static const uint8_t WRITE_READ_PROTECT_BIT = 0x02
 
static const uint8_t PASSWORD_CTRL_BIT = 0x04
 
static const int UID_LENGTH = 8
 
static const unsigned int I2C_WRITE_TIME = 5
 

Protected Member Functions

mraa::Result EEPROM_Write_Byte (unsigned int address, uint8_t data)
 
mraa::Result EEPROM_Write_Bytes (unsigned int address, uint8_t *data, int len)
 
uint8_t EEPROM_Read_Byte (unsigned int address)
 
int EEPROM_Read_Bytes (unsigned int address, uint8_t *buffer, int len)
 

Protected Attributes

mraa::I2c m_i2c
 

Member Enumeration Documentation

M24LR64E addresses, accessible only in the root mode

Constructor & Destructor Documentation

M24LR64E ( int  bus,
AccessMode  mode = USER_MODE 
)

M24LR64E constructor

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

M24LR64E destructor

Member Function Documentation

bool submitPasswd ( uint32_t  passwd)

Submits an I2C access password

Parameters
passwd4-byte access password
bool writePasswd ( uint32_t  passwd)

Writes a new I2C password

Parameters
passwd4-byte access password
void sectorProtectConfig ( unsigned int  sectorNumber,
bool  protectEnable,
SectorAccessRight  accessRight,
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 clearSectorProtect ( void  )

Clears sector protection bits. Must be in the root mode.

void sectorWriteLockBit ( unsigned int  sectorNumber,
bool  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

Here is the call graph for this function:

uint8_t getDSFID ( )

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

Returns
DSFID
uint8_t getAFI ( )

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

Returns
AFI
uint8_t * 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.
uint32_t getMemorySize ( )

Returns the memory size Must be in the root mode.

Returns
Amount of memory present
void clearMemory ( )

Sets all memory to 0, if permissions allow

Here is the call graph for this function:

mraa::Result writeByte ( unsigned int  address,
uint8_t  data 
)

Writes a byte to the EEPROM

Parameters
addressAddress to write to
dataData to write

Here is the caller graph for this function:

mraa::Result writeBytes ( unsigned int  address,
uint8_t *  buffer,
int  len 
)

Writes bytes to the EEPROM

Parameters
addressAddress to write to
dataData to write
dataLength of the data buffer
uint8_t readByte ( unsigned int  address)

Reads a byte from the EEPROM

Parameters
addressAddress to read from
Returns
data Value read
int readBytes ( unsigned int  address,
uint8_t *  buffer,
int  len 
)

Reads multiple bytes from the EEPROM

Parameters
addressAddress to read from
bufferBuffer to store data
lenNumber of bytes to read

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