Martyn Gilbertson / M24512

Files at this revision

API Documentation at this revision

Comitter:
martyn gilbertson
Date:
Thu Feb 13 13:55:59 2020 +0000
Parent:
4:336ef5db5e78
Commit message:
v1.0.3 - 13 February 2020

[+] Improved Timeout on read
[+] Decreased default i2c frequency for stability

Changed in this revision

M24512.cpp Show annotated file Show diff for this revision Revisions of this file
M24512.h Show annotated file Show diff for this revision Revisions of this file
--- a/M24512.cpp	Wed Oct 16 13:30:15 2019 +0100
+++ b/M24512.cpp	Thu Feb 13 13:55:59 2020 +0000
@@ -2,13 +2,15 @@
  * Copyright (C) 2019 - Invisible Systems Ltd. All Rights Reserved.
  */
 #include "M24512.h"
+#include "mbed.h"
+
 
 
 /** I2C Frequency
      Roughly calculate time to write a full page based on freq
 	 ((1 / 500000) * (130*9) * 1000) + 5
 */
-#define M24512_DEFAULT_FREQUENCY (uint32_t)500000
+#define M24512_DEFAULT_FREQUENCY (uint32_t)50000
 
 /** Read command | on device address
 */
@@ -68,15 +70,18 @@
 {
 	int8_t ack;
 	char cmd[2] = {0,0};
-	int timeout = 20;
+	int timeout = 60;
 
 	// Wait for end of write
 	do{
 		// read from addr 0 with a length of 0 just to check the i2c state
 		ack = _i2c.write( _addr | M24512_COMMAND_READ, cmd, 0 );
-		if (timeout-- == 0)
+		if (ack == 0 || timeout-- == 0)
 		{
 			return (ack == 0) ? M24512::M24512_SUCCESS : M24512::M24512_RDY_TIMEOUT;
+		}else
+		{
+			//printf("waiting for ready...\r\n");
 		}
 	}while(ack != 0);
 
@@ -89,6 +94,7 @@
 	int ret = 0;
 	char cmd[2];
 
+
 	// check for overflow
 	if ( ( addr + size) > (get_page_size() * get_page_count()) )
 	{
@@ -172,6 +178,7 @@
 	int16_t dlen = size; // data length remaining
 	int16_t addr_ofst = 0; // address to write
 
+
 	while (dlen > 0)
 	{
 		wlen = ((dlen > get_page_size()) ? get_page_size() : dlen);
--- a/M24512.h	Wed Oct 16 13:30:15 2019 +0100
+++ b/M24512.h	Thu Feb 13 13:55:59 2020 +0000
@@ -9,12 +9,21 @@
  * <p>
  *  v1.0.0   - 06 June 2019
  *          [+] Initial release
+ *
  *  v1.0.1   - 16 September 2019
  *          [+] Add retry to Write()
+ *
+ * *  v1.0.2   - 16 October 2019
+ *          [*] Decreased retry limit as to not WDT
+ *  		[+] Allow ready routine from public
+ *
  *  v1.0.2   - 16 October 2019
  *          [*] Decreased retry limit as to not WDT
- *  		[+] Allow ready routine from public
- * </p>
+ *          [+] Allow ready routine from public
+ *
+ *  v1.0.3   -  13 February 2020
+ *          [+] Improved Timeout on read
+ *          [+] Decreased default i2c frequency for stability
  */
 #ifndef _M24512_H_
 #define _M24512_H_