Add readUniqueId() to get unique 64 bit MAC
Reads 64 bit MAC unique ID
This commit is contained in:
parent
7b054f770f
commit
0370bec69d
21
SPIFlash.cpp
21
SPIFlash.cpp
|
|
@ -14,6 +14,8 @@
|
||||||
|
|
||||||
#include <SPIFlash.h>
|
#include <SPIFlash.h>
|
||||||
|
|
||||||
|
byte SPIFlash::UNIQUEID[8];
|
||||||
|
|
||||||
/// IMPORTANT: NAND FLASH memory requires erase before write, because
|
/// IMPORTANT: NAND FLASH memory requires erase before write, because
|
||||||
/// it can only transition from 1s to 0s and only the erase command can reset all 0s to 1s
|
/// it can only transition from 1s to 0s and only the erase command can reset all 0s to 1s
|
||||||
/// See http://en.wikipedia.org/wiki/Flash_memory
|
/// See http://en.wikipedia.org/wiki/Flash_memory
|
||||||
|
|
@ -74,6 +76,25 @@ word SPIFlash::readDeviceId()
|
||||||
return jedecid;
|
return jedecid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the 64 bit unique identifier, stores it in UNIQUEID[8]. Only needs to be called once, ie after initialize
|
||||||
|
/// Returns the byte pointer to the UNIQUEID byte array
|
||||||
|
/// Read UNIQUEID like this:
|
||||||
|
/// flash.readUniqueId(); for (byte i=0;i<8;i++) { Serial.print(flash.UNIQUEID[i], HEX); Serial.print(' '); }
|
||||||
|
/// or like this:
|
||||||
|
/// flash.readUniqueId(); byte* MAC = flash.readUniqueId(); for (byte i=0;i<8;i++) { Serial.print(MAC[i], HEX); Serial.print(' '); }
|
||||||
|
byte* SPIFlash::readUniqueId()
|
||||||
|
{
|
||||||
|
command(SPIFLASH_MACREAD);
|
||||||
|
SPI.transfer(0);
|
||||||
|
SPI.transfer(0);
|
||||||
|
SPI.transfer(0);
|
||||||
|
SPI.transfer(0);
|
||||||
|
for (byte i=0;i<8;i++)
|
||||||
|
UNIQUEID[i] = SPI.transfer(0);
|
||||||
|
unselect();
|
||||||
|
return UNIQUEID;
|
||||||
|
}
|
||||||
|
|
||||||
/// read 1 byte from flash memory
|
/// read 1 byte from flash memory
|
||||||
byte SPIFlash::readByte(long addr) {
|
byte SPIFlash::readByte(long addr) {
|
||||||
command(SPIFLASH_ARRAYREADLOWFREQ);
|
command(SPIFLASH_ARRAYREADLOWFREQ);
|
||||||
|
|
|
||||||
|
|
@ -65,9 +65,11 @@
|
||||||
#define SPIFLASH_IDREAD 0x9F // read JEDEC manufacturer and device ID (2 bytes, specific bytes for each manufacturer and device)
|
#define SPIFLASH_IDREAD 0x9F // read JEDEC manufacturer and device ID (2 bytes, specific bytes for each manufacturer and device)
|
||||||
// Example for Atmel-Adesto 4Mbit AT25DF041A: 0x1F44 (page 27: http://www.adestotech.com/sites/default/files/datasheets/doc3668.pdf)
|
// Example for Atmel-Adesto 4Mbit AT25DF041A: 0x1F44 (page 27: http://www.adestotech.com/sites/default/files/datasheets/doc3668.pdf)
|
||||||
// Example for Winbond 4Mbit W25X40CL: 0xEF30 (page 14: http://www.winbond.com/NR/rdonlyres/6E25084C-0BFE-4B25-903D-AE10221A0929/0/W25X40CL.pdf)
|
// Example for Winbond 4Mbit W25X40CL: 0xEF30 (page 14: http://www.winbond.com/NR/rdonlyres/6E25084C-0BFE-4B25-903D-AE10221A0929/0/W25X40CL.pdf)
|
||||||
|
#define SPIFLASH_MACREAD 0x4B // read unique ID number (MAC)
|
||||||
|
|
||||||
class SPIFlash {
|
class SPIFlash {
|
||||||
public:
|
public:
|
||||||
|
static byte UNIQUEID[8];
|
||||||
SPIFlash(byte slaveSelectPin, uint16_t jedecID=0);
|
SPIFlash(byte slaveSelectPin, uint16_t jedecID=0);
|
||||||
boolean initialize();
|
boolean initialize();
|
||||||
void command(byte cmd, boolean isWrite=false);
|
void command(byte cmd, boolean isWrite=false);
|
||||||
|
|
@ -81,6 +83,8 @@ public:
|
||||||
void blockErase4K(long address);
|
void blockErase4K(long address);
|
||||||
void blockErase32K(long address);
|
void blockErase32K(long address);
|
||||||
word readDeviceId();
|
word readDeviceId();
|
||||||
|
byte* readUniqueId();
|
||||||
|
|
||||||
void sleep();
|
void sleep();
|
||||||
void wakeup();
|
void wakeup();
|
||||||
void end();
|
void end();
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ chipErase KEYWORD2
|
||||||
blockErase4K KEYWORD2
|
blockErase4K KEYWORD2
|
||||||
blockErase32K KEYWORD2
|
blockErase32K KEYWORD2
|
||||||
readDeviceId KEYWORD2
|
readDeviceId KEYWORD2
|
||||||
|
readUniqueId KEYWORD2
|
||||||
|
UNIQUEID KEYWORD2
|
||||||
sleep KEYWORD2
|
sleep KEYWORD2
|
||||||
wakeup KEYWORD2
|
wakeup KEYWORD2
|
||||||
end KEYWORD2
|
end KEYWORD2
|
||||||
Loading…
Reference in New Issue