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.
M24512 Class Reference
Driver for reading and writing to M24512 eeprom. More...
#include <M24512.h>
Public Types | |
| enum | status_t { M24512_SUCCESS = 0, M24512_I2C_ERROR = 1, M24512_RDY_TIMEOUT = 2, M24512_MEM_OVERFLOW = 3 } |
Return values for each function. More... | |
Public Member Functions | |
| M24512 (PinName sda, PinName scl, uint8_t address=M24512_DEFAULT_ADDRESS) | |
| Initialise M24512 Interface. | |
| ~M24512 (void) | |
| Destructor. | |
| status_t | read (uint16_t addr, char *data, uint16_t size) |
| Read continuous from address. | |
| status_t | write (uint16_t addr, const char *data, uint16_t size) |
| Write continuous to address. | |
| void | frequency (uint32_t hz) |
| Set the i2c frequency. | |
| uint16_t | get_page_size () const |
| Get page size. | |
| uint16_t | get_page_count () const |
| Get page count. | |
| uint32_t | get_total_memory () const |
| Get memory size in KiB. | |
| status_t | ready (void) |
| Check status of Memory chip after writing data. | |
Detailed Description
Driver for reading and writing to M24512 eeprom.
Example:
// Write "test" to page 0 and read back #include "M24512.h" M24512 eeprom(I2C_SDA, I2C_SCL); int main() { M24512::status_t ret; char data[32] = {'t','e','s','t'}; ret = eeprom.write(0, (char*)data, 4); if ( ret != M24512::M24512_SUCCESS ) { printf("Error writing this! %2.2X\n", ret ); } memset( data, 0, sizeof(data) ); ret = eeprom.read(0, (char*)&data, 4); if ( ret != M24512::M24512_SUCCESS ) { printf("Error reading %2.2X!\n", ret ); } printf("Read: %s\n", data ); return 0; }
Definition at line 64 of file M24512.h.
Member Enumeration Documentation
| enum status_t |
Constructor & Destructor Documentation
| M24512 | ( | PinName | sda, |
| PinName | scl, | ||
| uint8_t | address = M24512_DEFAULT_ADDRESS |
||
| ) |
Initialise M24512 Interface.
- Parameters:
-
sda - I2C Data pin scl - I2C Clock pin addr - Hardware address of device (defaults to 0x50)
Definition at line 33 of file M24512.cpp.
| ~M24512 | ( | void | ) |
Destructor.
Definition at line 39 of file M24512.cpp.
Member Function Documentation
| void frequency | ( | uint32_t | hz ) |
| uint16_t get_page_count | ( | ) | const |
Get page count.
Definition at line 63 of file M24512.cpp.
| uint16_t get_page_size | ( | ) | const |
Get page size.
Definition at line 57 of file M24512.cpp.
| uint32_t get_total_memory | ( | ) | const |
Get memory size in KiB.
Definition at line 51 of file M24512.cpp.
| M24512::status_t read | ( | uint16_t | addr, |
| char * | data, | ||
| uint16_t | size | ||
| ) |
Read continuous from address.
- Parameters:
-
addr - address to start reading from data - pointer to data buffer (must be allocated) size - size of data to read back into data pointer
Definition at line 92 of file M24512.cpp.
| M24512::status_t ready | ( | void | ) |
Check status of Memory chip after writing data.
- Returns:
- -
- See also:
- status_t enum typedef
Definition at line 69 of file M24512.cpp.
| M24512::status_t write | ( | uint16_t | addr, |
| const char * | data, | ||
| uint16_t | size | ||
| ) |
Write continuous to address.
- Parameters:
-
addr - address to start writing at data - pointer to data buffer must be allocated size - size of data to write
Definition at line 173 of file M24512.cpp.
Generated on Wed Jul 13 2022 10:03:02 by
1.7.2