-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0715af
commit 4397563
Showing
6 changed files
with
875 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# MCP25LC1024 | ||
Arduino library for MCP25LC1024 SPI Eeprom |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name=MC25LC1024 | ||
version=1.0.0 | ||
author=Sylvain Garnavault <[email protected]> | ||
maintainer=Sylvain Garnavault <[email protected]> | ||
sentence=A SPI communication library for the MC25LC1024 Eeprom Chipset. | ||
paragraph=This library allow SPI communication with the MC25LC1024 Eeprom Chipset. | ||
category=Device Control | ||
url=https://github.com/siteswapjuggler | ||
architectures=* | ||
includes=MC25LC1024.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,140 +1,140 @@ | ||
// MC25LC1024 library for Arduino | ||
// initial release by Sylvain GARNAVAULT - 2014/07/09 | ||
|
||
#include "MC25LC1024.h" | ||
|
||
//////////////////////// | ||
// INITIATION // | ||
//////////////////////// | ||
|
||
MC25LC1024::MC25LC1024(byte pin) { | ||
_cs = pin; // choose the chip select pin | ||
pinMode(_cs,OUTPUT); // set the pin as output | ||
digitalWrite(_cs,HIGH); // set the pin to default HIGH state | ||
|
||
//TODO CHANGER ÇA | ||
SPI.setBitOrder(MSBFIRST); // the chip works MSB first | ||
SPI.setClockDivider(SPI_CLOCK_DIV2); // transmission as fast as possible | ||
SPI.setDataMode(SPI_MODE0); // clock MODE0 : rising edge, low default state | ||
SPI.begin(); // initiate SPI | ||
} | ||
|
||
///////////////////////// | ||
// PRIVATE METHODS // | ||
///////////////////////// | ||
|
||
void MC25LC1024::enableWrite() { | ||
digitalWrite(_cs,LOW); // select CHIP | ||
SPI.transfer(WREN); // send WREN command | ||
digitalWrite(_cs,HIGH); // end transmission | ||
} | ||
|
||
void MC25LC1024::sendAddress(long addr) { | ||
SPI.transfer((byte)(addr>>16)); // MSB with 7 first bits beeing don't care bits | ||
SPI.transfer((byte)(addr>>8)); // MSB | ||
SPI.transfer((byte)(addr)); // LSB | ||
} | ||
|
||
bool MC25LC1024::WIP() { | ||
byte data = readStatus(); // get data byte | ||
return (data & B1); // return data | ||
} | ||
|
||
///////////////////////// | ||
// PRIVATE METHODS // | ||
///////////////////////// | ||
|
||
|
||
void MC25LC1024::writeByte(long addr, byte data) { | ||
enableWrite(); // enable write | ||
digitalWrite(_cs,LOW); // select CHIP | ||
SPI.transfer(WRITE); // send WRITE command | ||
sendAddress(addr); // send address | ||
SPI.transfer(data); // transfer data | ||
digitalWrite(_cs,HIGH); // end transmission | ||
while (WIP()) {}; // wait for writing finish | ||
} | ||
|
||
void MC25LC1024::writeArray(long addr, byte* data, int length) { | ||
enableWrite(); // enable write | ||
digitalWrite(_cs,LOW); // select chip | ||
SPI.transfer(WRITE); // send WRITE command | ||
sendAddress(addr); // send address | ||
for (int i=0; i<length; i++) { | ||
SPI.transfer(data[i]); // transfer data | ||
} | ||
digitalWrite(_cs,HIGH); // release chip, signal end transfer | ||
while (WIP()) {}; // wait for writing finish | ||
} | ||
|
||
byte MC25LC1024::readByte(long addr) { | ||
digitalWrite(_cs,LOW); // select chip | ||
SPI.transfer(READ); // send READ command | ||
sendAddress(addr); // send address | ||
byte data = SPI.transfer(0x00); // get data byte | ||
digitalWrite(_cs,HIGH); // release chip, signal end transfer | ||
return data; | ||
} | ||
|
||
void MC25LC1024::readArray(long addr, byte *data, int length) { | ||
digitalWrite(_cs,LOW); // select chip | ||
SPI.transfer(READ); // send READ command | ||
sendAddress(addr); // send address | ||
for (int i=0; i<length; i++) { | ||
data[i] = SPI.transfer(0x00); // get data byte | ||
} | ||
digitalWrite(_cs,HIGH); // release chip, signal end transfer | ||
} | ||
|
||
byte MC25LC1024::readStatus() { | ||
digitalWrite(_cs,LOW); // select chip | ||
SPI.transfer(RDSR); // send RDSR command | ||
byte data = SPI.transfer(0x00); // get status register | ||
digitalWrite(_cs,HIGH); // end transmission | ||
return data; // return status register | ||
} | ||
|
||
void MC25LC1024::writeStatus(byte data) { | ||
digitalWrite(_cs,LOW); // select chip | ||
SPI.transfer(WRSR); // send WRSR command | ||
SPI.transfer(data); // send status register | ||
digitalWrite(_cs,HIGH); // end transmission | ||
} | ||
|
||
void MC25LC1024::pageErase(long addr) { | ||
digitalWrite(_cs,LOW); // select chip | ||
SPI.transfer(PE); // send PE command | ||
sendAddress(addr); // send addres | ||
digitalWrite(_cs,HIGH); // end transmission | ||
while (WIP()) {}; // wait for writing finish | ||
} | ||
|
||
void MC25LC1024::sectorErase(long addr) { | ||
digitalWrite(_cs,LOW); // select chip | ||
SPI.transfer(SE); // send SE command | ||
sendAddress(addr); // send addres | ||
digitalWrite(_cs,HIGH); // end transmission | ||
while (WIP()) {}; // wait for writing finish | ||
} | ||
|
||
void MC25LC1024::chipErase() { | ||
digitalWrite(_cs,LOW); // select chip | ||
SPI.transfer(CE); // send CE command | ||
digitalWrite(_cs,HIGH); // end transmission | ||
while (WIP()) {}; // wait for writing finish | ||
} | ||
|
||
void MC25LC1024::deepPowerDown() { | ||
digitalWrite(_cs,LOW); // select chip | ||
SPI.transfer(DPD); // send DPD command | ||
digitalWrite(_cs,HIGH); // end transmission | ||
} | ||
|
||
byte MC25LC1024::releasePowerDown() { | ||
digitalWrite(_cs,LOW); // select chip | ||
SPI.transfer(RDID); // send RDID command | ||
sendAddress(0); // send dummy address | ||
byte data=SPI.transfer(0x00); // get signature | ||
digitalWrite(_cs,HIGH); // end transmission | ||
return data; // return signature | ||
// MC25LC1024 library for Arduino | ||
// initial release by Sylvain GARNAVAULT - 2014/07/09 | ||
|
||
#include "MC25LC1024.h" | ||
|
||
//////////////////////// | ||
// INITIATION // | ||
//////////////////////// | ||
|
||
MC25LC1024::MC25LC1024(byte pin) { | ||
_cs = pin; // choose the chip select pin | ||
pinMode(_cs,OUTPUT); // set the pin as output | ||
digitalWrite(_cs,HIGH); // set the pin to default HIGH state | ||
|
||
//TODO CHANGER ÇA | ||
SPI.setBitOrder(MSBFIRST); // the chip works MSB first | ||
SPI.setFrequency(20000000); // transmission as fast as possible | ||
SPI.setDataMode(SPI_MODE0); // clock MODE0 : rising edge, low default state | ||
SPI.begin(); // initiate SPI | ||
} | ||
|
||
///////////////////////// | ||
// PRIVATE METHODS // | ||
///////////////////////// | ||
|
||
void MC25LC1024::enableWrite() { | ||
digitalWrite(_cs,LOW); // select CHIP | ||
SPI.transfer(WREN); // send WREN command | ||
digitalWrite(_cs,HIGH); // end transmission | ||
} | ||
|
||
void MC25LC1024::sendAddress(long addr) { | ||
SPI.transfer((byte)(addr>>16)); // MSB with 7 first bits beeing don't care bits | ||
SPI.transfer((byte)(addr>>8)); // MSB | ||
SPI.transfer((byte)(addr)); // LSB | ||
} | ||
|
||
bool MC25LC1024::WIP() { | ||
byte data = readStatus(); // get data byte | ||
return (data & B1); // return data | ||
} | ||
|
||
///////////////////////// | ||
// PRIVATE METHODS // | ||
///////////////////////// | ||
|
||
|
||
void MC25LC1024::writeByte(long addr, byte data) { | ||
enableWrite(); // enable write | ||
digitalWrite(_cs,LOW); // select CHIP | ||
SPI.transfer(WRITE); // send WRITE command | ||
sendAddress(addr); // send address | ||
SPI.transfer(data); // transfer data | ||
digitalWrite(_cs,HIGH); // end transmission | ||
while (WIP()) {}; // wait for writing finish | ||
} | ||
|
||
void MC25LC1024::writeArray(long addr, byte* data, int length) { | ||
enableWrite(); // enable write | ||
digitalWrite(_cs,LOW); // select chip | ||
SPI.transfer(WRITE); // send WRITE command | ||
sendAddress(addr); // send address | ||
for (int i=0; i<length; i++) { | ||
SPI.transfer(data[i]); // transfer data | ||
} | ||
digitalWrite(_cs,HIGH); // release chip, signal end transfer | ||
while (WIP()) {}; // wait for writing finish | ||
} | ||
|
||
byte MC25LC1024::readByte(long addr) { | ||
digitalWrite(_cs,LOW); // select chip | ||
SPI.transfer(READ); // send READ command | ||
sendAddress(addr); // send address | ||
byte data = SPI.transfer(0x00); // get data byte | ||
digitalWrite(_cs,HIGH); // release chip, signal end transfer | ||
return data; | ||
} | ||
|
||
void MC25LC1024::readArray(long addr, byte *data, int length) { | ||
digitalWrite(_cs,LOW); // select chip | ||
SPI.transfer(READ); // send READ command | ||
sendAddress(addr); // send address | ||
for (int i=0; i<length; i++) { | ||
data[i] = SPI.transfer(0x00); // get data byte | ||
} | ||
digitalWrite(_cs,HIGH); // release chip, signal end transfer | ||
} | ||
|
||
byte MC25LC1024::readStatus() { | ||
digitalWrite(_cs,LOW); // select chip | ||
SPI.transfer(RDSR); // send RDSR command | ||
byte data = SPI.transfer(0x00); // get status register | ||
digitalWrite(_cs,HIGH); // end transmission | ||
return data; // return status register | ||
} | ||
|
||
void MC25LC1024::writeStatus(byte data) { | ||
digitalWrite(_cs,LOW); // select chip | ||
SPI.transfer(WRSR); // send WRSR command | ||
SPI.transfer(data); // send status register | ||
digitalWrite(_cs,HIGH); // end transmission | ||
} | ||
|
||
void MC25LC1024::pageErase(long addr) { | ||
digitalWrite(_cs,LOW); // select chip | ||
SPI.transfer(PE); // send PE command | ||
sendAddress(addr); // send addres | ||
digitalWrite(_cs,HIGH); // end transmission | ||
while (WIP()) {}; // wait for writing finish | ||
} | ||
|
||
void MC25LC1024::sectorErase(long addr) { | ||
digitalWrite(_cs,LOW); // select chip | ||
SPI.transfer(SE); // send SE command | ||
sendAddress(addr); // send addres | ||
digitalWrite(_cs,HIGH); // end transmission | ||
while (WIP()) {}; // wait for writing finish | ||
} | ||
|
||
void MC25LC1024::chipErase() { | ||
digitalWrite(_cs,LOW); // select chip | ||
SPI.transfer(CE); // send CE command | ||
digitalWrite(_cs,HIGH); // end transmission | ||
while (WIP()) {}; // wait for writing finish | ||
} | ||
|
||
void MC25LC1024::deepPowerDown() { | ||
digitalWrite(_cs,LOW); // select chip | ||
SPI.transfer(DPD); // send DPD command | ||
digitalWrite(_cs,HIGH); // end transmission | ||
} | ||
|
||
byte MC25LC1024::releasePowerDown() { | ||
digitalWrite(_cs,LOW); // select chip | ||
SPI.transfer(RDID); // send RDID command | ||
sendAddress(0); // send dummy address | ||
byte data=SPI.transfer(0x00); // get signature | ||
digitalWrite(_cs,HIGH); // end transmission | ||
return data; // return signature | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,49 @@ | ||
// MC25LC1024 library for Arduino | ||
// initial release by Sylvain GARNAVAULT - 2014/07/09 | ||
|
||
#ifndef MC25LC1024_h | ||
|
||
#define MC25LC1024_h | ||
|
||
#include "Arduino.h" // include arduino Core | ||
#include "SPI.h" // include SPI library | ||
|
||
#define READ B00000011 // read byte | ||
#define WRITE B00000010 // write byte | ||
#define WREN B00000110 // write enable | ||
#define WRDI B00000100 // write disable | ||
#define RDSR B00000101 // read status register | ||
#define WRSR B00000001 // write status register | ||
#define PE B01000010 // page erase | ||
#define SE B11011000 // sector erase | ||
#define CE B11000111 // chip erase | ||
#define RDID B10101011 // release from Deep power-down and read electronic signature | ||
#define DPD B10111001 // deep power-down mode | ||
|
||
class MC25LC1024 { | ||
public: | ||
MC25LC1024(byte pin); // initiate objet | ||
void writeByte(long addr, byte data); // write byte | ||
void writeArray(long addr, byte data[], int length); // write array | ||
|
||
byte readByte(long addr); // read byte | ||
void readArray(long addr, byte data[], int length); // read array | ||
|
||
byte readStatus(); // read status register | ||
void writeStatus(byte data); // write status register | ||
|
||
void pageErase(long addr); // erase page | ||
void sectorErase(long addr); // erase sector | ||
void chipErase(); // erase chip | ||
|
||
void deepPowerDown(); // Deep power-down mode | ||
byte releasePowerDown(); // release from Deep power-down and read electronic signature | ||
|
||
private: | ||
byte _cs; // chip select pin | ||
void enableWrite(); // enable write | ||
void sendAddress(long addr); // send 24-bit address | ||
bool WIP(); // write in progress ? | ||
}; | ||
|
||
#endif // MC25LC1024_h | ||
// MC25LC1024 library for Arduino | ||
// initial release by Sylvain GARNAVAULT - 2014/07/09 | ||
|
||
#ifndef MC25LC1024_h | ||
|
||
#define MC25LC1024_h | ||
|
||
#include "Arduino.h" // include arduino Core | ||
#include "SPI.h" // include SPI library | ||
|
||
#define READ B00000011 // read byte | ||
#define WRITE B00000010 // write byte | ||
#define WREN B00000110 // write enable | ||
#define WRDI B00000100 // write disable | ||
#define RDSR B00000101 // read status register | ||
#define WRSR B00000001 // write status register | ||
#define PE B01000010 // page erase | ||
#define SE B11011000 // sector erase | ||
#define CE B11000111 // chip erase | ||
#define RDID B10101011 // release from Deep power-down and read electronic signature | ||
#define DPD B10111001 // deep power-down mode | ||
|
||
class MC25LC1024 { | ||
public: | ||
MC25LC1024(byte pin); // initiate objet | ||
void writeByte(long addr, byte data); // write byte | ||
void writeArray(long addr, byte data[], int length); // write array | ||
|
||
byte readByte(long addr); // read byte | ||
void readArray(long addr, byte data[], int length); // read array | ||
|
||
byte readStatus(); // read status register | ||
void writeStatus(byte data); // write status register | ||
|
||
void pageErase(long addr); // erase page | ||
void sectorErase(long addr); // erase sector | ||
void chipErase(); // erase chip | ||
|
||
void deepPowerDown(); // Deep power-down mode | ||
byte releasePowerDown(); // release from Deep power-down and read electronic signature | ||
|
||
private: | ||
byte _cs; // chip select pin | ||
void enableWrite(); // enable write | ||
void sendAddress(long addr); // send 24-bit address | ||
bool WIP(); // write in progress ? | ||
}; | ||
|
||
#endif // MC25LC1024_h |