Library to use on memories 24Cxx

Committer:
lucasmoraeseng
Date:
Wed Mar 02 01:11:22 2016 +0000
Revision:
0:0a68754e37e4
Library to use on memories 24Cxx

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lucasmoraeseng 0:0a68754e37e4 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
lucasmoraeseng 0:0a68754e37e4 2 *
lucasmoraeseng 0:0a68754e37e4 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
lucasmoraeseng 0:0a68754e37e4 4 * and associated documentation files (the "Software"), to deal in the Software without
lucasmoraeseng 0:0a68754e37e4 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
lucasmoraeseng 0:0a68754e37e4 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
lucasmoraeseng 0:0a68754e37e4 7 * Software is furnished to do so, subject to the following conditions:
lucasmoraeseng 0:0a68754e37e4 8 *
lucasmoraeseng 0:0a68754e37e4 9 * The above copyright notice and this permission notice shall be included in all copies or
lucasmoraeseng 0:0a68754e37e4 10 * substantial portions of the Software.
lucasmoraeseng 0:0a68754e37e4 11 *
lucasmoraeseng 0:0a68754e37e4 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
lucasmoraeseng 0:0a68754e37e4 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
lucasmoraeseng 0:0a68754e37e4 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
lucasmoraeseng 0:0a68754e37e4 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
lucasmoraeseng 0:0a68754e37e4 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
lucasmoraeseng 0:0a68754e37e4 17 */
lucasmoraeseng 0:0a68754e37e4 18
lucasmoraeseng 0:0a68754e37e4 19 #ifndef M24CXX_H
lucasmoraeseng 0:0a68754e37e4 20 #define M24CXX_H
lucasmoraeseng 0:0a68754e37e4 21
lucasmoraeseng 0:0a68754e37e4 22 #include "mbed.h"
lucasmoraeseng 0:0a68754e37e4 23
lucasmoraeseng 0:0a68754e37e4 24 class M24CXX
lucasmoraeseng 0:0a68754e37e4 25 {
lucasmoraeseng 0:0a68754e37e4 26 public:
lucasmoraeseng 0:0a68754e37e4 27
lucasmoraeseng 0:0a68754e37e4 28 M24CXX(PinName SDA, PinName SCL,int Adr);
lucasmoraeseng 0:0a68754e37e4 29 ~M24CXX();
lucasmoraeseng 0:0a68754e37e4 30
lucasmoraeseng 0:0a68754e37e4 31 /* Write just one byte on memory */
lucasmoraeseng 0:0a68754e37e4 32
lucasmoraeseng 0:0a68754e37e4 33 int Write(int EEAddres, uint8_t Data);
lucasmoraeseng 0:0a68754e37e4 34 int write(int EEAddres, uint8_t Data);
lucasmoraeseng 0:0a68754e37e4 35
lucasmoraeseng 0:0a68754e37e4 36
lucasmoraeseng 0:0a68754e37e4 37 /* How to write more than once byte on memory
lucasmoraeseng 0:0a68754e37e4 38
lucasmoraeseng 0:0a68754e37e4 39 #include "mbed.h"
lucasmoraeseng 0:0a68754e37e4 40 #include "M24CXX.h"
lucasmoraeseng 0:0a68754e37e4 41
lucasmoraeseng 0:0a68754e37e4 42 PinName const SDA = PTB4;
lucasmoraeseng 0:0a68754e37e4 43 PinName const SCL = PTB3;
lucasmoraeseng 0:0a68754e37e4 44
lucasmoraeseng 0:0a68754e37e4 45 int main()
lucasmoraeseng 0:0a68754e37e4 46 {
lucasmoraeseng 0:0a68754e37e4 47 int alfa=0;
lucasmoraeseng 0:0a68754e37e4 48 uint8_t datas[12] = {'L','u','c','a','s',' ','M','o','r','a','e','s'};
lucasmoraeseng 0:0a68754e37e4 49
lucasmoraeseng 0:0a68754e37e4 50 M24CXX memory (SDA,SCL,0);
lucasmoraeseng 0:0a68754e37e4 51
lucasmoraeseng 0:0a68754e37e4 52 printf("Memory Started\r\n");
lucasmoraeseng 0:0a68754e37e4 53 while (true) {
lucasmoraeseng 0:0a68754e37e4 54 printf("Try to write\r\n");
lucasmoraeseng 0:0a68754e37e4 55 alfa = memory.writePage(0x00,(uint8_t*)datas,sizeof(datas));
lucasmoraeseng 0:0a68754e37e4 56 printf("Result is %d\r\n",alfa);
lucasmoraeseng 0:0a68754e37e4 57 wait(0.5);
lucasmoraeseng 0:0a68754e37e4 58 }
lucasmoraeseng 0:0a68754e37e4 59 }
lucasmoraeseng 0:0a68754e37e4 60
lucasmoraeseng 0:0a68754e37e4 61 */
lucasmoraeseng 0:0a68754e37e4 62 int writePage(int EEAddres, uint8_t* Data, int Length);
lucasmoraeseng 0:0a68754e37e4 63 int WritePage(int EEAddres, uint8_t* Data, int Length);
lucasmoraeseng 0:0a68754e37e4 64
lucasmoraeseng 0:0a68754e37e4 65
lucasmoraeseng 0:0a68754e37e4 66 /* Read a single byte from memory */
lucasmoraeseng 0:0a68754e37e4 67
lucasmoraeseng 0:0a68754e37e4 68 uint8_t read(int EEAddress);
lucasmoraeseng 0:0a68754e37e4 69 uint8_t Read(int EEAddress);
lucasmoraeseng 0:0a68754e37e4 70
lucasmoraeseng 0:0a68754e37e4 71
lucasmoraeseng 0:0a68754e37e4 72 /* Read sequential of bytes from memory */
lucasmoraeseng 0:0a68754e37e4 73
lucasmoraeseng 0:0a68754e37e4 74 // memory.readPage(0,13,(uint8_t*) datas);
lucasmoraeseng 0:0a68754e37e4 75
lucasmoraeseng 0:0a68754e37e4 76 void readPage(int EEAddress,int Length,uint8_t* Data);
lucasmoraeseng 0:0a68754e37e4 77 void ReadPage(int EEAddress,int Length,uint8_t* Data);
lucasmoraeseng 0:0a68754e37e4 78
lucasmoraeseng 0:0a68754e37e4 79 private:
lucasmoraeseng 0:0a68754e37e4 80 I2C m_i2c;
lucasmoraeseng 0:0a68754e37e4 81 int m_Address;
lucasmoraeseng 0:0a68754e37e4 82
lucasmoraeseng 0:0a68754e37e4 83 };
lucasmoraeseng 0:0a68754e37e4 84
lucasmoraeseng 0:0a68754e37e4 85 #endif