n-Blocks-HALL / RM25C512C-L_driver
Revision:
6:0434e89c2d68
Parent:
4:17e602b21ac5
Child:
7:c562fe4d48de
--- a/rm25c512cl.cpp	Wed Sep 12 16:10:05 2018 +0000
+++ b/rm25c512cl.cpp	Thu Sep 13 12:17:25 2018 +0000
@@ -11,15 +11,16 @@
 * @brief    write_enable()
 * @details  Sets write enable latch to 1 to enable writing to eeprom uses the WREN opcode
 * @param    NA
-* @return   NA
+* @return   Success or failure of command
 * @warning  Write or erase instructions will be ignored if this instruction is not issued first
 * 
 */
 
-void rm25c512cl :: write_enable(){
+bool rm25c512cl :: write_enable(){
     
     char cmd[1];
     char data_buffer[1];// not used here but required for spi.write() as a parameter
+    char status;
     
     cmd[0] = WREN;
     
@@ -33,9 +34,21 @@
     
     _spi.unlock();
     
-    wait_us(20);   
+    status = read_status_reg();
+    status = status & 0x2;
+    
+    /* make sure write enable is completed, if not somthing is wrong with device*/
     
-    
+    if(status == 2){ // device is enabled WEL bit = 1
+        
+        return SUCCESS;
+        
+    }
+    else{// WEL bit is 0 device is dissabled
+        
+        return FAILURE;
+        
+    }   
     
 }
 
@@ -84,17 +97,18 @@
 * @param    Starting address to write to.
 * @param    Pointer to the data array containg bytes to be stored.
 * @param    Size of the data array in bytes.
-* @return   NA
+* @return   Sucess or failure of write
 * @warning  A page write(128 bytes) can take up to 5 ms to complete
 * 
 */
 
-void rm25c512cl :: write_bytes(uint16_t address, char* data, uint16_t data_size){
+bool rm25c512cl :: write_bytes(uint16_t address, char* data, uint16_t data_size){
     
     char cmd[3];
     char data_buffer[1];// not used here but required for spi.write() as a parameter
-    
-    
+    char status;
+    uint32_t i = TIMEOUT_BYTES;
+     
     
     cmd[0] = WR;
     cmd[1] = address >> 8;
@@ -111,8 +125,26 @@
     
     _spi.unlock();
     
-    wait_ms(5); 
+    /* make sure data has been written sucessfully by reading bit zero in status register*/
+    
+   do{
+    
+    status = read_status_reg();
+    status = status & 0x1; 
     
+    i--; 
+      
+    }while(status == 1 && i>0);
+    
+    /* if timeout elapses*/
+    
+    if( i < 1){
+        
+        return FAILURE;
+    }
+    else {
+        return SUCCESS;
+    }   
     
 }