Some test with Nucleo and SPI EEPROM.

Dependencies:   mbed

main.cpp

Committer:
kaliczp
Date:
2015-01-19
Revision:
0:a063a7db08f8
Child:
1:c667d1f8e407

File content as of revision 0:a063a7db08f8:

#include "mbed.h"

DigitalIn mybutton(USER_BUTTON); // Activate button
DigitalOut chipselect(D10); // ChipSelect (CS) pin
SPI eeprom(SPI_MOSI, SPI_MISO, SPI_SCK); // Activate SPI to ST eeprom

#define WREN 0x06
#define RDSR 0x05
#define READ_LOW 0x03
 
int main() {
    chipselect =1;
    eeprom.frequency(1000000); // set 1 MHz clock rate
    int i = 0;
    while(1) {
        if (mybutton == 0) { // Button is pressed
            chipselect = 0;
            eeprom.write(RDSR);
            eeprom.write(0x00);
            chipselect = 1;
            chipselect = 0;
            eeprom.write(WREN);
            chipselect = 1;
            wait_us(1);
            chipselect = 0;
            eeprom.write(RDSR);
            eeprom.write(0x00);
            chipselect = 1;
            chipselect = 0;
            eeprom.write(READ_LOW);
            eeprom.write(0x00);
            eeprom.write(0x00);
            chipselect = 1;
            wait(2);
        }
    }
}