Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
MB85RCxx_I2C.h
00001 /** 00002 ****************************************************************************** 00003 * @file MB85RCxx_I2C.h 00004 * @author Toyomasa Watarai 00005 * @version V1.0.0 00006 * @date 22 April 2017 00007 * @brief This file contains the class of an MB85RCxx FRAM library with I2C interface 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * Permission is hereby granted, free of charge, to any person obtaining a copy 00012 * of this software and associated documentation files (the "Software"), to deal 00013 * in the Software without restriction, including without limitation the rights 00014 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00015 * copies of the Software, and to permit persons to whom the Software is 00016 * furnished to do so, subject to the following conditions: 00017 * 00018 * The above copyright notice and this permission notice shall be included in 00019 * all copies or substantial portions of the Software. 00020 * 00021 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00022 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00023 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00024 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00025 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00026 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00027 * THE SOFTWARE. 00028 */ 00029 00030 #ifndef MBED_MB85RCxx_I2C_H 00031 #define MBED_MB85RCxx_I2C_H 00032 00033 #include "mbed.h" 00034 00035 #define MB85_DENSITY_64K 0x3 00036 #define MB85_DENSITY_256K 0x5 00037 #define MB85_DENSITY_512K 0x6 00038 #define MB85_DENSITY_1M 0x7 00039 #define MB85_DENSITY_2M 0x8 00040 #define MB85RC_I2C_ADDRESS 0xA0 00041 #define I2C_WRITE 0 00042 #define I2C_READ 1 00043 00044 /** Interface for accessing Fujitsu MB85RCxx FRAM 00045 * 00046 * @code 00047 * #include "mbed.h" 00048 * #include "MB85RCxx_I2C.h" 00049 * 00050 * Serial pc(USBTX, USBRX); 00051 * 00052 * #if defined(TARGET_LPC1768) 00053 * MB85RCxx_I2C fram(p28, p27); 00054 * #else 00055 * MB85RCxx_I2C fram(D14, D15); 00056 * #endif 00057 * 00058 * int main() 00059 * { 00060 * char buf[16]; 00061 * uint32_t address; 00062 * 00063 * fram.fill(0, 0, 256); 00064 * 00065 * for (int i = 0; i < 16; i++) { 00066 * buf[i] = i; 00067 * } 00068 * fram.write(0, buf, 16); 00069 * 00070 * for (address = 0; address < 0x80; address += 16) { 00071 * fram.read(address, buf, 16); 00072 * pc.printf("%08X : ", address); 00073 * for (int i = 0; i < 16; i++) { 00074 * pc.printf("%02X ", buf[i]); 00075 * } 00076 * pc.printf("\n"); 00077 * } 00078 * } 00079 * 00080 * @endcode 00081 */ 00082 00083 /** MB85RCxx_I2C class 00084 * 00085 * MB85RCxx_I2C: A library to access Fujitsu MB85RCxx_I2C FRAM 00086 * 00087 */ 00088 class MB85RCxx_I2C 00089 { 00090 public: 00091 00092 /** Create an MB85RCxx_I2C instance 00093 * which is connected to specified I2C pins with specified address 00094 * 00095 * @param sda I2C data line pin 00096 * @param scl I2C clock line pin 00097 * @param slave_adr (option) I2C slave address (default: 0xA0) 00098 */ 00099 MB85RCxx_I2C(PinName sda, PinName scl, char slave_adr = MB85RC_I2C_ADDRESS); 00100 00101 /** Destructor of MB85RCxx_I2C 00102 */ 00103 virtual ~MB85RCxx_I2C(); 00104 00105 /** Read device ID from MB85RCxx FRAM 00106 * 00107 * @param device_id Pointer to the byte-array to read data in to 00108 * 00109 * @returns memory dencity 00110 */ 00111 int read_device_id(char* device_id); 00112 00113 /** Read data from memory address 00114 * 00115 * @param address Memory address 00116 * @param data Pointer to the byte-array to read data in to 00117 * @param length Number of bytes to read 00118 * 00119 */ 00120 void read(uint32_t address, char *data, uint32_t length); 00121 00122 /** Write data to memory address 00123 * 00124 * @param address Memory address 00125 * @param data Pointer to the byte-array data to write 00126 * @param length Number of bytes to write 00127 * 00128 */ 00129 void write(uint32_t address, char *data, uint32_t length); 00130 00131 /** Write data to memory address 00132 * 00133 * @param address Memory address 00134 * @param data data to write out to memory 00135 * 00136 */ 00137 void write(uint32_t address, char data); 00138 00139 /** Fill data to memory address 00140 * 00141 * @param address Memory address 00142 * @param data data to fill out to memory 00143 * @param length Number of bytes to write 00144 * 00145 */ 00146 void fill(uint32_t address, uint8_t data, uint32_t length); 00147 00148 private: 00149 I2C *_i2c_p; 00150 I2C &_i2c; 00151 char _address; 00152 }; 00153 00154 #endif
Generated on Tue Jul 12 2022 21:16:29 by
1.7.2
Fujitsu I2C FRAM MB85RCxx