This program illustrates how to use the 24LCxx_I2C library In this version, NTP service was added to set RTC time

Dependencies:   NetServices mbed

Files at this revision

API Documentation at this revision

Comitter:
Yann
Date:
Thu Nov 25 13:34:01 2010 +0000
Parent:
0:944015c441cb
Commit message:
V0.0.2

Changed in this revision

24LCxx_I2C.lib Show annotated file Show diff for this revision Revisions of this file
DebugLibrary.lib Show annotated file Show diff for this revision Revisions of this file
NetServices.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 944015c441cb -r 71ea5acdee1b 24LCxx_I2C.lib
--- a/24LCxx_I2C.lib	Thu Nov 25 06:59:09 2010 +0000
+++ b/24LCxx_I2C.lib	Thu Nov 25 13:34:01 2010 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/Yann/code/24LCxx_I2C/#295d84866a47
+http://mbed.org/users/Yann/code/24LCxx_I2C/#1892f6f9f7f5
diff -r 944015c441cb -r 71ea5acdee1b DebugLibrary.lib
--- a/DebugLibrary.lib	Thu Nov 25 06:59:09 2010 +0000
+++ b/DebugLibrary.lib	Thu Nov 25 13:34:01 2010 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/Yann/code/DebugLibrary/#ce74b6c101b9
+http://mbed.org/users/Yann/code/DebugLibrary/#be0c7a9bd686
diff -r 944015c441cb -r 71ea5acdee1b NetServices.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NetServices.lib	Thu Nov 25 13:34:01 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/NetServices/#350011bf8be7
diff -r 944015c441cb -r 71ea5acdee1b main.cpp
--- a/main.cpp	Thu Nov 25 06:59:09 2010 +0000
+++ b/main.cpp	Thu Nov 25 13:34:01 2010 +0000
@@ -1,12 +1,14 @@
 #include <string>
 
 #include "24LCxx_I2C.h"
+#include "EthernetNetIf.h"
+#include "NTPClient.h"
 
 /*
  * Declare functions
  */
 
-void AvailableIndicator();
+void AvailableIndicator(); // LED1 flashing for program while program is alive
 char DisplayMenuAndGetChoice(); // Display and get the user choice
 void RunStateMachine_WithStdStringValue(); // Write and read a string
 void RunStateMachine_WithByteValue(); // Write and read a byte
@@ -18,26 +20,44 @@
 /*
  * Declare statics
  */
+EthernetNetIf g_eth;
+
 enum States {
-    Idle,
-    Write,
-    Written,
-    Read
+    Idle, // Idle state / Read memory operation done
+    Write, // Write memory operation
+    Written, // Write memory operation done
+    Read // Read memory operation
 };
 States g_state; // Process states for memory operations
 
 DigitalOut g_availableLed(LED1); // To verify if program in running
 Ticker g_available; // LED1 will flash with a period of 2s
 
+#define __3_3V__
+#ifdef __3_3V__
 C2424LCXX_I2C g_myEEPROM(p28, p27, 0x01, p5, 400000); // Create an instance of the class C2424LCXX_I2C, p28: SDA, p29:SDL, p5: wired to WP input of 24LCxx, address: A3=0,A2=0,A=1, on 3.3V I2C bus
+#else // __3_3V__
+C2424LCXX_I2C g_myEEPROM(p28, p27, 0x07, p7, 400000); // Create an instance of the class C2424LCXX_I2C, p28: SDA, p29:SDL, p7: wired to WP input of 24LCxx, address: A3=1,A2=1,A=1, on 5V I2C bus
+#endif // __3_3V__
 
 int main() {
 
-    wait(1); // Needed after startup
+    // Launch available indicator
+    g_available.attach(&AvailableIndicator, 2.0);
+
+    // Initialize Ethernet
+    g_eth.setup();
+    
+    wait(1); // Needed after Ethernet startup
    
-    // Launch available indocator
-    g_available.attach(&AvailableIndicator, 2.0);
-    
+    IpAddr ip = g_eth.getIp();
+    printf("IP address: %d:%d:%d:%d\r\n", ip[0], ip[1], ip[2], ip[3]);
+
+    // Update time
+    Host ntpServer(IpAddr(), 123, "ntp.unice.fr");
+    NTPClient ntp;
+    ntp.setTime(ntpServer);
+
     g_myEEPROM.WriteProtect(false); // Disabe WP (pin 7) - See DS21203M - Clause 2.4 Write-Protect (WP)
     
     while (true) { // Interrupt driven processing
@@ -127,7 +147,11 @@
                 str += " UTC";
                 printf("RunStateMachine_WithStdStringValue: Write '%s'\r\n", str.c_str());
                 if (!g_myEEPROM.Write(256, str)) { // Write the string, including the length indicator
+#ifdef __DEBUG
                     DEBUG_FATAL("RunStateMachine_WithStdStringValue: write failed at address 256")
+#else // __DEBUG
+                    printf("RunStateMachine_WithStdStringValue: write failed at address 256\r\n");
+#endif // __DEBUG
                     g_state = Idle;
                 } else {
                     g_state = Written;