AT24C1024の機能を簡単に使えるようにするライブラリー

Committer:
r113330akki
Date:
Wed Dec 13 05:23:42 2017 +0000
Revision:
3:8957e88b3334
Parent:
1:3d1e7763c6f5
doxygen???; ; ????????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
r113330akki 1:3d1e7763c6f5 1 #include "at24c1024b.h"
r113330akki 1:3d1e7763c6f5 2
r113330akki 1:3d1e7763c6f5 3 AT24C1024B::AT24C1024B(PinName sda, PinName scl, int addr) :
r113330akki 1:3d1e7763c6f5 4 SDA(sda), SCL(scl), i2c(sda, scl)
r113330akki 1:3d1e7763c6f5 5 {
r113330akki 1:3d1e7763c6f5 6
r113330akki 1:3d1e7763c6f5 7 }
r113330akki 1:3d1e7763c6f5 8 AT24C1024B::AT24C1024B(PinName sda, PinName scl) :
r113330akki 1:3d1e7763c6f5 9 SDA(sda), SCL(scl), i2c(sda, scl)
r113330akki 1:3d1e7763c6f5 10 {
r113330akki 1:3d1e7763c6f5 11 }
r113330akki 1:3d1e7763c6f5 12 AT24C1024B::AT24C1024B(PinName sda, PinName scl) :
r113330akki 1:3d1e7763c6f5 13 SDA(sda), SCL(scl), i2c(sda, scl)
r113330akki 1:3d1e7763c6f5 14 {
r113330akki 1:3d1e7763c6f5 15 }
r113330akki 1:3d1e7763c6f5 16 AT24C1024B::AT24C1024B(PinName sda, PinName scl) :
r113330akki 1:3d1e7763c6f5 17 SDA(sda), SCL(scl), i2c(sda, scl)
r113330akki 1:3d1e7763c6f5 18 {
r113330akki 1:3d1e7763c6f5 19 }
r113330akki 1:3d1e7763c6f5 20
r113330akki 1:3d1e7763c6f5 21 int AT24C1024B::write(int addr, int page, char data)
r113330akki 1:3d1e7763c6f5 22 {
r113330akki 1:3d1e7763c6f5 23 char array[1]=data;
r113330akki 1:3d1e7763c6f5 24 int buff;
r113330akki 1:3d1e7763c6f5 25 buff = write(addr, page, array, 1);
r113330akki 1:3d1e7763c6f5 26 return buff;
r113330akki 1:3d1e7763c6f5 27 }
r113330akki 1:3d1e7763c6f5 28
r113330akki 1:3d1e7763c6f5 29 int AT24C1024B::write(int addr, int page, char *data, int length)
r113330akki 1:3d1e7763c6f5 30 {
r113330akki 1:3d1e7763c6f5 31 char buffCommand[2];
r113330akki 1:3d1e7763c6f5 32 if(length<1) {
r113330akki 1:3d1e7763c6f5 33 return -1;
r113330akki 1:3d1e7763c6f5 34 }
r113330akki 1:3d1e7763c6f5 35 buffCommand[0]=(char)addr&0xff00;//上位8ビットを代入
r113330akki 1:3d1e7763c6f5 36 buffCommand[1]=(char)addr&0x00ff;//下位8ビットを代入
r113330akki 1:3d1e7763c6f5 37 i2c.write(AT24C1024B_ADDRESS,buffCommand,2,true);//次の書き込み命令と同時に送信
r113330akki 1:3d1e7763c6f5 38 i2c.write(AT24C1024B_ADDRESS,data,length);
r113330akki 1:3d1e7763c6f5 39 wait(0.005);
r113330akki 1:3d1e7763c6f5 40 }
r113330akki 1:3d1e7763c6f5 41
r113330akki 1:3d1e7763c6f5 42 int read(int addr, int page)
r113330akki 1:3d1e7763c6f5 43 {
r113330akki 1:3d1e7763c6f5 44 char array[1]=data;
r113330akki 1:3d1e7763c6f5 45 read(addr, page, array, 1);
r113330akki 1:3d1e7763c6f5 46 return array[0];
r113330akki 1:3d1e7763c6f5 47 }
r113330akki 1:3d1e7763c6f5 48
r113330akki 1:3d1e7763c6f5 49 int AT24C1024B::read(int addr, int page, char *data, int length)
r113330akki 1:3d1e7763c6f5 50 {
r113330akki 1:3d1e7763c6f5 51 char buffCommand[2];
r113330akki 1:3d1e7763c6f5 52 if(length<1) {
r113330akki 1:3d1e7763c6f5 53 return -1;
r113330akki 1:3d1e7763c6f5 54 }
r113330akki 1:3d1e7763c6f5 55 buffCommand[0]=(char)addr&0xff00;//上位8ビットを代入
r113330akki 1:3d1e7763c6f5 56 buffCommand[1]=(char)addr&0x00ff;//下位8ビットを代入
r113330akki 1:3d1e7763c6f5 57 i2c.write(AT24C1024B_ADDRESS,buffCommand,2);
r113330akki 1:3d1e7763c6f5 58 i2c.read(AT24C1024B_ADDRESS,data,length);
r113330akki 1:3d1e7763c6f5 59 return 0;
r113330akki 1:3d1e7763c6f5 60 }
r113330akki 1:3d1e7763c6f5 61