161007_BDK_EEPROM

Dependencies:   mbed

Fork of 161006_BDK_SPImaster by CUBEBITE

Revision:
7:d2710f5d6f66
Parent:
6:50376de8d756
Child:
8:2599e5a13e05
--- a/main.cpp	Thu Oct 06 08:28:29 2016 +0000
+++ b/main.cpp	Fri Oct 07 08:16:15 2016 +0000
@@ -25,7 +25,8 @@
     pc_serial.printf("Set SPI format..\n");
     spi_master.format(8,0);
     pc_serial.printf("Set frequency to default..\n");
-    spi_master.frequency(1000000); // default 1MHz
+    //spi_master.frequency(50000000); // default 1MHz
+    spi_master.frequency(1000000);
 }
 /*
 void SPI_Write()
@@ -85,12 +86,13 @@
 }
 */
 
-#define EEPROM_WREN     0x06        // Write Enable
-#define EEPROM_WRDI     0x04        // Write Disable
-#define EEPROM_RDSR     0x05        // Read Status Register
-#define EEPROM_WRSR     0x01        // Write Status Register
-#define EEPROM_READ     0x03        // Read EEPROM Memory
-#define EEPROM_WRITE    0x02        // Write EEPROM Memory
+#define EEPROM_WREN         0x06        // Write Enable
+#define EEPROM_WRDI         0x04        // Write Disable
+#define EEPROM_RDSR         0x05        // Read Status Register
+#define EEPROM_WRSR         0x01        // Write Status Register
+#define EEPROM_READ         0x03        // Read EEPROM Memory
+#define EEPROM_WRITE        0x02        // Write EEPROM Memory
+#define EEPROM_MULTIREAD    0x07        // Write EEPROM Memory
 
 
 enum cubeMenu { EEPROM_Write_Enable = 1 , 
@@ -107,14 +109,14 @@
 {
     pc_serial.printf("\n\n\n\n\n\n\n"); 
      pc_serial.printf("-----------[MENU]----------\n");
-     pc_serial.printf("%d) Write Enable\n", cubeMenu.EEPROM_Write_Enable);
-     pc_serial.printf("%d) Write Disable\n", cubeMenu.EEPROM_Write_Disable);
-     pc_serial.printf("%d) Read Status Register\n", cubeMenu.EEPROM_Read_Status);
-     pc_serial.printf("%d) Write Status Register\n",cubeMenu.EEPROM_Write_Status);
-     pc_serial.printf("%d) Write Memory\n", cubeMenu.EEPROM_Write_Memory);
-     pc_serial.printf("%d) Read Memory\n", cubeMenu.EEPROM_Read_Memory);
-     pc_serial.printf("%d) multi byte read test\n", cubeMenu.TEST_Multi_Byte_Read);
-     pc_serial.printf("%d) Exit program\n", cubeMenu.EXIT_Program);
+     pc_serial.printf("1) Write Enable\n");//, cubeMenu.EEPROM_Write_Enable);
+     pc_serial.printf("2) Write Disable\n");//, cubeMenu.EEPROM_Write_Disable);
+     pc_serial.printf("3) Read Status Register\n");//, cubeMenu.EEPROM_Read_Status);
+     pc_serial.printf("4) Write Status Register\n");//,cubeMenu.EEPROM_Write_Status);
+     pc_serial.printf("5) Write Memory\n");//, cubeMenu.EEPROM_Write_Memory);
+     pc_serial.printf("6) Read Memory\n");//, cubeMenu.EEPROM_Read_Memory);
+     pc_serial.printf("7) multi byte read\n");//, cubeMenu.TEST_Multi_Byte_Read);
+     pc_serial.printf("9) Exit program\n");//, cubeMenu.EXIT_Program);
      pc_serial.printf("---------------------------\n");
      pc_serial.printf("input menu : ");
 }
@@ -187,7 +189,7 @@
      char dummyRead;
      char inputMenuNum = 0;
      char statusReg = 0x00;
-     
+     char test_data[10]={0};
      
      int spiTxCnt = 0;
      int spiRxCnt = 0; 
@@ -412,6 +414,54 @@
              break;
              
              
+             case 7:
+                pc_serial.printf("\n[DEBUG] TEST_Multi_Byte_Read\n");
+                
+                maxInputCnt = 3;
+                while(maxInputCnt--)
+                {
+                    pc_serial.printf("input Address (hex format : 00~FF) : ");
+                    for(int iCnt = 0 ; iCnt < 2 ; ++iCnt)                
+                    {   
+                        eepAddrBuf[iCnt] = pc_serial.getc();    
+                        pc_serial.printf("%c", eepAddrBuf[iCnt]); 
+                    }
+                    
+                    ret = converHex(&eepAddr , eepAddrBuf, 2);
+                    
+                    if(0 == ret)
+                    {
+                        spi_master.write(EEPROM_MULTIREAD);
+                        spi_master.write(eepAddr); 
+                        
+                        
+                        for(int i=0;i<10;i++)
+                        {   
+                            //test_data[i] = spi_master.write(0);
+                            //spi_master.write(++eepAddr); 
+                            test_data[i] = spi_master.write(0);
+                            
+                        }
+                        
+                        for(int i=0;i<10;i++)
+                        {   
+                            printf("\n[DEBUG] Read EEPROM Data[0x%02X]\n",test_data[i]);
+                        }
+                        
+                        //pc_serial.printf("\n[DEBUG] Read EEPROM Addr[0x%02X]\n", eepAddr);
+                        break;
+                    }
+                    else        // error
+                    {
+                        pc_serial.printf("\n[INFO] hex formet error!\n");
+                        continue;
+                    }                     
+                }
+                
+                
+             break;
+             
+