![](/media/cache/profiles/bca57eca4ea2eaf33880deb0989442f3.jpg.50x50_q85.jpg)
This sketch read a single byte into a variable, then, the variable is added by two, the result is written into memory. Finally, byte is readed again. the values are printed to serial port too.
Dependencies: Hotboards_eeprom mbed
Revision 0:696194ed3c66, committed 2016-02-05
- Comitter:
- Hotboards
- Date:
- Fri Feb 05 19:06:02 2016 +0000
- Commit message:
- first release: eeprom write_byte
Changed in this revision
diff -r 000000000000 -r 696194ed3c66 Hotboards_eeprom.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Hotboards_eeprom.lib Fri Feb 05 19:06:02 2016 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/Hotboards/code/Hotboards_eeprom/#38fad00cc45b
diff -r 000000000000 -r 696194ed3c66 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Feb 05 19:06:02 2016 +0000 @@ -0,0 +1,64 @@ +/* + Hotboards eeprom Library - write_byte + Demonstrates the use a spi eeprom. The Hotboards_eeprom + library works with all Microchip 25xxx serial memory series + like the one presented eeprom board (http://www.hotboards.org). + This sketch read a single byte into a variable, then, the variable is added by two, + the result is written into memory. Finally, byte is readed again. + the values are printed to serial port too. + + The circuit: + * VDD --> 3.3v + * SO --> PB_14 + * SI --> PB_15 + * SCK --> PB_13 + * CS --> PC_4 + * GND --> GND + + Library created by Diego from Hotboards + example added by Pedro from Hotboards + */ + +#include "mbed.h" +#include "Hotboards_eeprom.h" + +/*Open an instance of serial port*/ +Serial pc(USBTX,USBRX); +/* initialize an instance of SPI bus,setting the SPI pins*/ +SPI device(PB_15,PB_14,PB_13); /* SO, SI, SCK*/ +/*initialize the library with the numbers of the interface pins*/ +Hotboards_eeprom eeprom(device,PC_4,HT_EEPROM25xx_32Kb); /* (spi,Cs,Density) */ + +int main() +{ + /*SPI transfer at 8 bits, MODE = 3*/ + device.format(8,3); + /* set the spi frequency to 5MHz */ + device.frequency(5000000); + /*initialize CS pin*/ + eeprom.init(); + + /* variable to read data*/ + char Data; + + /* read firts byte*/ + Data=eeprom.read(0); + /* send to serial port*/ + printf("%X \n",Data); + + /* readed data is added by two */ + Data+= 2; + /* write the result*/ + eeprom.write(0,Data); + + /* read firts byte again*/ + Data=eeprom.read(0); + /* send to serial port */ + printf("%X \n",Data); + + while(1) + { + /*loop*/ + } + +} \ No newline at end of file
diff -r 000000000000 -r 696194ed3c66 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Feb 05 19:06:02 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/6f327212ef96 \ No newline at end of file