Browse Source

Merge pull request #24 from FrankBoesing/master

Add readSerialNumber(uint8_t *buf);
main
Paul Stoffregen 8 years ago
parent
commit
a493db82f4
2 changed files with 17 additions and 0 deletions
  1. +1
    -0
      SerialFlash.h
  2. +16
    -0
      SerialFlashChip.cpp

+ 1
- 0
SerialFlash.h View File

static void sleep(); static void sleep();
static void wakeup(); static void wakeup();
static void readID(uint8_t *buf); static void readID(uint8_t *buf);
static void readSerialNumber(uint8_t *buf);
static void read(uint32_t addr, void *buf, uint32_t len); static void read(uint32_t addr, void *buf, uint32_t len);
static bool ready(); static bool ready();
static void wait(); static void wait();

+ 16
- 0
SerialFlashChip.cpp View File

//Serial.printf("ID: %02X %02X %02X\n", buf[0], buf[1], buf[2]); //Serial.printf("ID: %02X %02X %02X\n", buf[0], buf[1], buf[2]);
} }


void SerialFlashChip::readSerialNumber(uint8_t *buf) //needs room for 8 bytes
{
if (busy) wait();
SPI.beginTransaction(SPICONFIG);
CSASSERT();
SPI.transfer(0x4B);
SPI.transfer16(0);
SPI.transfer16(0);
for (int i=0; i<8; i++) {
buf[i] = SPI.transfer(0);
}
CSRELEASE();
SPI.endTransaction();
// Serial.printf("Serial Number: %02X %02X %02X %02X %02X %02X %02X %02X\n", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
}

uint32_t SerialFlashChip::capacity(const uint8_t *id) uint32_t SerialFlashChip::capacity(const uint8_t *id)
{ {
uint32_t n = 1048576; // unknown chips, default to 1 MByte uint32_t n = 1048576; // unknown chips, default to 1 MByte

Loading…
Cancel
Save