STM32F303K8T6で24LC1025を使うプログラム

Dependencies:   mbed 24LC1025

Files at this revision

API Documentation at this revision

Comitter:
sashida_h
Date:
Wed Aug 05 10:16:13 2020 +0000
Parent:
1:15721e85977d
Commit message:
initial commit

Changed in this revision

24LC1025.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
--- a/24LC1025.lib	Wed Nov 20 04:04:36 2019 +0000
+++ b/24LC1025.lib	Wed Aug 05 10:16:13 2020 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/sashida_h/code/24LC1025/#8047024a08c2
+https://os.mbed.com/users/sashida_h/code/24LC1025/#41cf2e3bb7f3
--- a/main.cpp	Wed Nov 20 04:04:36 2019 +0000
+++ b/main.cpp	Wed Aug 05 10:16:13 2020 +0000
@@ -1,34 +1,54 @@
 #include "mbed.h"
 #include "24LC1025.h"
-Serial pc(PA_2, PA_3);
-I2CEEprom i2c;
+
+Serial pc(PA_2, PA_3, 115200);
+
+LC1025 eeprom = LC1025(PB_7, PB_6);
 
 int main()
 {
-  pc.baud(115200);
-  pc.printf("Hello OSHIMA\r\n");
-  unsigned char x;
-  char a[1000];
+    pc.printf("Hello OSHIMA\r\n");
+    char x;
+    char a[256];
   // 書き込む場合
- 
-        for(int i=0; i<8; i++, x++)
-        {
-            a[0] = 'T';
-            a[1] = 'A';
-            a[2] = 'K';
-            a[3] = 'E';
-            a[4] = 'Y';
-            a[5] = 'U';
-            a[6] = 'K';
-            a[7] = 'I';
-            i2c.write(i, a[i]);
-        }
+
+    a[0x0000] = 'T';
+    a[0x0001] = 'A';
+    a[0x0002] = 'K';
+    a[0x0003] = 'E';
+    a[0x0004] = 'Y';
+    a[0x0005] = 'U';
+    a[0x0006] = 'K';
+    a[0x0007] = 'I';
+
+    //1バイトずつ書き込む
+    for(uint16_t i=0x0000; i<0x0008; i++)
+    {
+        eeprom.writeByte(ADDRESS_24LC1025_BLOCK0, i ,a[i]);
+        pc.printf("%c:0x%x\r\n",a[i],a[i]);
+        wait(0.1);
+        
+    }
+
+    //書き込むバイト数を指定して連続で書き込む
+    eeprom.PageWrite(ADDRESS_24LC1025_BLOCK1,0x0000,a,8);
  
  // 読み込む場合
-        for(int i=0; i<8; i++)
-        {
-            x = i2c.read(i);
-            pc.printf("%04x,%c ",i,x);
-        }
-        pc.printf("\n");
-}
\ No newline at end of file
+    for(uint16_t i=0x0000; i<0x0008; i++)
+    {
+        x = eeprom.RandomRead(ADDRESS_24LC1025_BLOCK0, i);
+        pc.printf("%04x,%c ",i,x);
+        wait(0.1);
+    }
+    pc.printf("\r\n");
+    for(uint16_t i=0x0000; i<0x0008; i++)
+    {
+        x = eeprom.RandomRead(ADDRESS_24LC1025_BLOCK1, i);
+        pc.printf("%04x,%c ",i,x);
+        wait(0.1);
+    }
+    pc.printf("\r\n");
+}
+
+/*
+*/
\ No newline at end of file