Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed commands BLE_API nRF51822
Storage.cpp
- Committer:
- dkester
- Date:
- 2015-06-01
- Revision:
- 3:a3e1a06c486d
- Parent:
- 1:b44bd62c542f
- Child:
- 4:2a5a08b14539
File content as of revision 3:a3e1a06c486d:
#include "Storage.h"
SPI spi(p20, p22, p25); // mosi, miso, sclk
DigitalOut cs(p14);
Storage* Storage::instance = new Storage();
Storage::Storage()
{
cs = 1;
spi.format(8,0);
spi.frequency(300000);
}
Storage* Storage::getInstance()
{
return instance;
}
void Storage::setup(){
}
void Storage::endAction(){
cs = 1;
}
bool Storage::setWREN(){
cs = 0;
spi.write(0x06);
cs = 1;
cs = 0;
spi.write(0x05);
if(spi.write(0x00) & 0x2){
cs = 0;
return true;
} else {
cs = 0;
return 1;
}
}
bool Storage::isBusy(){
cs = 0;
spi.write(0x05);
if(spi.write(0x00) & 0x1){
cs = 0;
return true;
} else {
cs = 0;
return 1;
}
}
void Storage::pageProgram(int32_t addr){
cs = 0;
spi.write(0x12);
for(int i = 3; i >= 0; i--){
spi.write((addr >> (8*i)) & 0xff);
}
}
void Storage::writeData(int8_t data){
spi.write(data);
}
void Storage::read(int32_t addr){
cs = 0;
spi.write(0x13);
//char[4] bytes;
//bytes[0] = (addr >> 24) & 0xff;
//bytes[1] = (addr >> 16) & 0xff;
//bytes[2] = (addr >> 8) & 0xff;
//bytes[3] = addr & 0xff;
for(int i = 3; i < 0; i--){
spi.write((addr >> (8*i)) & 0xff);
}
}
int8_t Storage::readData(){
return spi.write(0x00);
}