Lib. for Atmel 1Mbits Serial EEPROM, AT24C1024B
Dependents: LPC1114_data_logger dmx_to_stepper BSM02 LPC1114_barometer_with_data_logging
AT24C1024.h
00001 /* 00002 * mbed library program 00003 * Control AT24C1024 EEPROM 00004 * 00005 * Copyright (c) 2014,'15,'17 Kenji Arai / JH1PJL 00006 * http://www.page.sannet.ne.jp/kenjia/index.html 00007 * http://mbed.org/users/kenjiArai/ 00008 * Created: June 17th, 2014 00009 * Revised: August 23rd, 2017 00010 */ 00011 00012 #ifndef AT24C1024_H 00013 #define AT24C1024_H 00014 00015 #include "mbed.h" 00016 00017 /** Interface for 1Mbit Serial EEPROM (I2C Interface) Atmel Corp. AT24C1024B 00018 * 00019 * @code 00020 * #include "mbed.h" 00021 * 00022 * // I2C Communication 00023 * AT24C1024 at24c1024(dp5,dp27);// SDA, SCL 00024 * // If you connected I2C line not only this device but also other devices, 00025 * // you need to declare following method. 00026 * I2C i2c(dp5,dp27); // SDA, SCL 00027 * AT24C1024 at24c1024(i2c); // Atmel 1Mbit EE-PROM 00028 * 00029 * int main() { 00030 * at24c1024.write(0,dt); // write addr=0 data=dt 00031 * dt = at24c1024.read(0); // read addr=0 00032 * // page write mode, addr top=0x1ff00, 256bytes data (save it in eep_buf[]) 00033 * status = at24c1024.write_page(0x1ff00, eep_buf, sizeof(eep_buf)); 00034 * } 00035 * @endcode 00036 */ 00037 00038 // EEPROM Atmel AT24C1024 00039 // Address b7=1,b6=0,b5=1,b4=0,b3=A2pin,b2=A1pin,b1=page addr, b0=R/W 00040 #define AT24C1024ADDR 0xa0 // as initial data (A2=A1=GND) 00041 00042 typedef enum { 00043 AT24C_OK = 0, 00044 AT24C_BUSY, 00045 AT24C_WRONG_BF_SIZE, 00046 AT24C_WRONG_TOP_ADDR, 00047 AT24C_ERROR 00048 } AT24C_STATUS; 00049 00050 class AT24C1024 00051 { 00052 public: 00053 /** Configure data pin 00054 * @param data SDA and SCL pins 00055 */ 00056 AT24C1024(PinName p_sda, PinName p_scl); 00057 00058 /** Configure data pin (with other devices on I2C line) 00059 * @param I2C previous definition 00060 */ 00061 AT24C1024(I2C& p_i2c); 00062 00063 /** Read one data from EEPROM 00064 * @param dat_address (0 to 0x1ffff) 00065 * @return read data 00066 */ 00067 uint8_t read(uint32_t addr); 00068 00069 /** Write one data to EEPROM 00070 * @param data_address (o to 0x1ffff), data (byte) 00071 * @return none 00072 */ 00073 void write(uint32_t addr, uint8_t dt); 00074 00075 /** Page read (256 bytes) from EEPROM 00076 * @param top_address (o to 0x1ffxx) e.g. 0x00,0x100,0x200 --- 0x1fe00, 0x1ff00 00077 * @param dt -> buffer (at least need to keep 258 bytes), data top = buffer[0] 00078 * @param size -> sizeof(buffer) 00079 * @return status 0=OK, others=Error 00080 */ 00081 AT24C_STATUS read_page(uint32_t addr_page_top, uint8_t *dt, int size); 00082 00083 /** Page write (256 bytes) to EEPROM 00084 * @param top_address (o to 0x1ffxx) e.g. 0x00,0x100,0x200 --- 0x1fe00, 0x1ff00 00085 * @param dt -> buffer (at least need to keep 258 bytes), data top = buffer[0] 00086 * @param size -> sizeof(buffer) 00087 * @return status 0=OK, others=Error 00088 */ 00089 AT24C_STATUS write_page(uint32_t addr_page_top, uint8_t *dt, int size); 00090 00091 /** Set I2C clock frequency 00092 * @param freq. 00093 * @return none 00094 */ 00095 void frequency(int hz); 00096 00097 protected: 00098 I2C *_i2c_p; 00099 I2C &_i2c; 00100 00101 private: 00102 uint8_t AT24C1024_addr; 00103 }; 00104 00105 #endif // AT24C1024_H 00106
Generated on Fri Jul 15 2022 21:20:42 by 1.7.2