This sketch write an array into a memory, then, read back the data and print them to a serial port.

Dependencies:   Hotboards_eeprom mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002   Hotboards eeprom Library - write_array
00003  Demonstrates the use a spi eeprom. The Hotboards_eeprom
00004  library works with all Microchip 25xxx serial memory series 
00005  like the one presented eeprom board (http://www.hotboards.org).
00006  This sketch write an array into a memory, then, read back the data 
00007  and print them to a serial port.
00008  
00009  The circuit:
00010  *  VDD   -->  3.3v
00011  *  SO    -->  PB_14
00012  *  SI    -->  PB_15
00013  *  SCK   -->  PB_13
00014  *  CS    -->  PC_4
00015  *  GND   -->  GND
00016  
00017  Library  created by Diego from Hotboards
00018  example added by Pedro from Hotboards
00019  */
00020 #include "mbed.h"
00021 #include "Hotboards_eeprom.h"
00022 /*Open an instance of serial port*/
00023 Serial pc(USBTX,USBRX);
00024 /* initialize an instance of SPI bus,setting the SPI pins*/
00025 SPI device(PB_15,PB_14,PB_13); /* SO, SI, SCK*/
00026 /*initialize the library with the numbers of the interface pins*/
00027 Hotboards_eeprom eeprom(device,PC_4,HT_EEPROM25xx_32Kb); /* (spi,Cs,Density) */
00028 
00029 int main() 
00030 {
00031     /*SPI transfer at 8 bits, MODE = 3*/
00032     device.format(8,3);
00033     /* set the spi frequency to 5MHz  */
00034     device.frequency(5000000);
00035     /*initialize CS pin*/
00036     eeprom.init();
00037     /*array to be write*/
00038     uint8_t write_array[]= "[25AA320-EXAMPLE]\n";
00039     /*array for read */
00040     uint8_t read_array[20];
00041 
00042     /*write the entire array starting at 0 adress*/
00043     eeprom.write(0,write_array,sizeof(write_array));
00044     
00045     /*read back to "read_array"*/
00046     eeprom.read(0,(uint8_t*)read_array,20);
00047     
00048     /*print adress and data to serial port*/
00049     printf("ADRESS|DATA \n");
00050     for(int j=0;j<17;j++)
00051     {
00052        printf("%2d      %c \n",j,read_array[j]); 
00053     }
00054     
00055     while(1) 
00056     {
00057       /*loop*/
00058     }
00059 }