Some test with Nucleo and SPI EEPROM.

Dependencies:   mbed

Committer:
kaliczp
Date:
Mon Jan 19 23:13:12 2015 +0000
Revision:
0:a063a7db08f8
Child:
1:c667d1f8e407
Check, write enable, recheck and finally read the first bit.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kaliczp 0:a063a7db08f8 1 #include "mbed.h"
kaliczp 0:a063a7db08f8 2
kaliczp 0:a063a7db08f8 3 DigitalIn mybutton(USER_BUTTON); // Activate button
kaliczp 0:a063a7db08f8 4 DigitalOut chipselect(D10); // ChipSelect (CS) pin
kaliczp 0:a063a7db08f8 5 SPI eeprom(SPI_MOSI, SPI_MISO, SPI_SCK); // Activate SPI to ST eeprom
kaliczp 0:a063a7db08f8 6
kaliczp 0:a063a7db08f8 7 #define WREN 0x06
kaliczp 0:a063a7db08f8 8 #define RDSR 0x05
kaliczp 0:a063a7db08f8 9 #define READ_LOW 0x03
kaliczp 0:a063a7db08f8 10
kaliczp 0:a063a7db08f8 11 int main() {
kaliczp 0:a063a7db08f8 12 chipselect =1;
kaliczp 0:a063a7db08f8 13 eeprom.frequency(1000000); // set 1 MHz clock rate
kaliczp 0:a063a7db08f8 14 int i = 0;
kaliczp 0:a063a7db08f8 15 while(1) {
kaliczp 0:a063a7db08f8 16 if (mybutton == 0) { // Button is pressed
kaliczp 0:a063a7db08f8 17 chipselect = 0;
kaliczp 0:a063a7db08f8 18 eeprom.write(RDSR);
kaliczp 0:a063a7db08f8 19 eeprom.write(0x00);
kaliczp 0:a063a7db08f8 20 chipselect = 1;
kaliczp 0:a063a7db08f8 21 chipselect = 0;
kaliczp 0:a063a7db08f8 22 eeprom.write(WREN);
kaliczp 0:a063a7db08f8 23 chipselect = 1;
kaliczp 0:a063a7db08f8 24 wait_us(1);
kaliczp 0:a063a7db08f8 25 chipselect = 0;
kaliczp 0:a063a7db08f8 26 eeprom.write(RDSR);
kaliczp 0:a063a7db08f8 27 eeprom.write(0x00);
kaliczp 0:a063a7db08f8 28 chipselect = 1;
kaliczp 0:a063a7db08f8 29 chipselect = 0;
kaliczp 0:a063a7db08f8 30 eeprom.write(READ_LOW);
kaliczp 0:a063a7db08f8 31 eeprom.write(0x00);
kaliczp 0:a063a7db08f8 32 eeprom.write(0x00);
kaliczp 0:a063a7db08f8 33 chipselect = 1;
kaliczp 0:a063a7db08f8 34 wait(2);
kaliczp 0:a063a7db08f8 35 }
kaliczp 0:a063a7db08f8 36 }
kaliczp 0:a063a7db08f8 37 }
kaliczp 0:a063a7db08f8 38