Martyn Gilbertson / M24512
Revision:
5:431b0b0c00d3
Parent:
4:336ef5db5e78
--- 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);