GY-63_MS5611/libraries/FRAM_I2C/README.md

195 lines
8.0 KiB
Markdown
Raw Normal View History

2021-01-29 06:31:58 -05:00
[![Arduino CI](https://github.com/RobTillaart/FRAM_I2C/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
2021-12-18 09:02:32 -05:00
[![Arduino-lint](https://github.com/RobTillaart/FRAM_I2C/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/FRAM_I2C/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/FRAM_I2C/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/FRAM_I2C/actions/workflows/jsoncheck.yml)
2021-01-29 06:31:58 -05:00
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/FRAM_I2C/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/FRAM_I2C.svg?maxAge=3600)](https://github.com/RobTillaart/FRAM_I2C/releases)
# FRAM_I2C
2022-02-08 10:47:34 -05:00
Arduino library for I2C FRAM.
2021-01-29 06:31:58 -05:00
## Description
2022-02-08 10:47:34 -05:00
FRAM is a library to read from and write to (over I2C) an FRAM module.
2022-05-10 04:10:44 -04:00
The library has (since 0.4.0) two classes **FRAM** and **FRAM32**.
The first is for the 16 bit devices and the latter for the 32 bit devices.
Currently only the **MB85RC1MT** is known to be 32 bit.
**FRAM32** can also address 16 bit devices although there is some overhead in footprint.
2021-12-18 09:02:32 -05:00
FRAM stands for Ferroelectric RAM - https://en.wikipedia.org/wiki/Ferroelectric_RAM
2021-01-29 06:31:58 -05:00
2022-05-10 04:10:44 -04:00
FRAM memory is much faster than EEPROM and almost as fast as (Arduino UNO) RAM.
Another important feature FRAM has in common with EEPROM is that FRAM keeps
its content after a reboot as it is non-volatile, even for years.
That makes it ideal to store configuration or logging data in a project.
Types of FRAM that should work with this library:
2021-01-29 06:31:58 -05:00
2022-02-08 10:47:34 -05:00
| TYPE | SIZE | TESTED | NOTES |
|:----------:|-------:|:------:|:---------------------|
| MB85RC04 | 512 | | no deviceID register |
| MB85RC16 | 2 KB | | no deviceID register |
2022-05-10 04:10:44 -04:00
| MB85RC64T | 8 KB | Y | |
2022-02-08 10:47:34 -05:00
| MB85RC128A | 16 KB | | no deviceID register |
2022-05-10 04:10:44 -04:00
| MB85RC256V | 32 KB | Y | |
| MB85RC512T | 64 KB | Y | |
| MB85RC1MT | 128 KB | Y | since 0.4.0 FRAM32 only |
2021-01-29 06:31:58 -05:00
2022-05-02 10:06:10 -04:00
#### Notes
2022-05-10 04:10:44 -04:00
- Not all types of FRAM are tested. Please let me know if you have verified one that is not in the list.
2022-02-08 10:47:34 -05:00
- If there is no deviceID **getSize()** will not work correctly.
2022-05-02 10:06:10 -04:00
- Address = 0x50 (default) .. 0x57, depends on the lines A0..A2.
2022-05-10 04:10:44 -04:00
- **MB85RC1MT** uses even addresses only as it uses the next odd one internally. So 0x50 uses 0x51 internally for the upper 64 KB block.
This latter will not be shown on an I2C scanner (to be tested).
2021-01-29 06:31:58 -05:00
## Interface
2022-02-08 10:47:34 -05:00
2021-01-29 06:31:58 -05:00
### Constructor
- **FRAM(TwoWire \*wire = &Wire)** Constructor with optional Wire interface.
2022-05-10 04:10:44 -04:00
- **FRAM32(TwoWire \*wire = &Wire)** Constructor with optional Wire interface, specific for **MB85RC1MT** type of device.
2021-12-18 09:02:32 -05:00
- **int begin(uint8_t address = 0x50, int8_t writeProtectPin = -1)** address and writeProtectPin is optional.
2022-05-10 04:10:44 -04:00
Note the **MB85RC1MT** only uses even addresses.
2022-02-08 10:47:34 -05:00
- **int begin(uint8_t sda, uint8_t scl, uint8_t address = 0x50, int8_t writeProtectPin = -1)** idem for ESP32 a.o.
2021-12-18 09:02:32 -05:00
- **bool isConnected()** checks if the address is visible on the I2C bus.
2021-01-29 06:31:58 -05:00
### Write & read
2022-05-10 04:10:44 -04:00
Support for basic types and 2 calls for generic object, use casting if needed. In the **FRAM32** class these functions have an **uin32_t memaddr**.
2021-01-29 06:31:58 -05:00
2021-12-18 09:02:32 -05:00
- **void write8(uint16_t memaddr, uint8_t value)** uint8_t
- **void write16(uint16_t memaddr, uint16_t value)** uint16_t
- **void write32(uint16_t memaddr, uint32_t value)** uint32_t
2022-02-08 10:47:34 -05:00
- **void write(uint16_t memaddr, uint8_t \* obj, uint16_t size)** other types / sizes.
2021-12-18 09:02:32 -05:00
- **uint8_t read8(uint16_t memaddr)**
- **uint16_t read16(uint16_t memaddr)**
- **uint32_t read32(uint16_t memaddr)**
2022-02-08 10:47:34 -05:00
- **void read(uint16_t memaddr, uint8_t uint8_t \* obj, uint16_t size)**
One needs to allocate memory as the function won't.
2021-01-29 06:31:58 -05:00
2022-03-18 08:37:57 -04:00
(0.3.4 added template functions, see issue #13 )
2022-05-02 10:06:10 -04:00
- **uint16_t writeObject(uint16_t memaddr, T &obj)** writes an object to memaddr (and following bytes).
Returns memaddr + sizeof(obj) to get the next address to write to.
- **uint16_t readObject(uint16_t memaddr, T &obj)** reads an object from memaddr and next bytes.
Returns memaddr + sizeof(obj) to get the next address to read from.
2022-03-18 08:37:57 -04:00
2022-03-25 05:04:48 -04:00
(0.3.5 added)
- **uint32_t clear(uint8_t value = 0)** clears the whole FRAM by writing value to all addresses - default zero's.
Returns the number of bytes written..
2021-01-29 06:31:58 -05:00
2021-12-18 09:02:32 -05:00
### Miscellaneous
2021-01-29 06:31:58 -05:00
2022-02-08 10:47:34 -05:00
- **bool setWriteProtect(bool b)** make the FRAM write-protected by pulling line HIGH / LOW.
Returns true if a writeProtectPin was defined.
2022-03-18 08:37:57 -04:00
Otherwise the FRAM cannot be write protected.
Note the pin should be defined in **begin()**.
- **bool getWriteProtect()** get current write protect status.
2022-02-08 10:47:34 -05:00
- **uint16_t getManufacturerID()** idem. Fujitsu = 0x00A.
- **uint16_t getProductID()** idem. Proprietary.
- **uint16_t getSize()** returns size in kiloBYTE.
If the FRAM has no device ID, the size cannot be read.
- **uint32_t getSizeBytes()** returns size in BYTES.
Convenience wrapper, useful for iterating over the whole memory,
2022-03-18 08:37:57 -04:00
or testing the upper boundary.
2022-03-25 05:04:48 -04:00
- **void setSizeBytes(uint32_t value)** sets size in bytes for **getSizeBytes()**.
To be used only if **getSize()** cannot determine the size.
See also remark in Future section below.
2021-01-29 06:31:58 -05:00
2022-05-02 10:06:10 -04:00
### Sleep
(0.3.6 added - experimental)
- **void sleep()** puts the FRAM in sleep mode so it uses less power.
Still needs a power test for 2 types of FRAM.
- **bool wakeup(uint32_t trec = 400)** tries to wake up the device with a default recovery time of 400 microseconds.
Returns true if connected after the call.
According to the data sheets there are only three FRAM devices support the sleep command.
So use with care.
| TYPE | SIZE | SLEEP (datasheet)| CURRENT | CONFIRMED | NOTES |
|:----------:|-------:|:----------------:|:---------:|:---------:|:--------|
2022-05-10 04:10:44 -04:00
| MB85RC04 | 512 | not supported | - | N | |
| MB85RC16 | 2 KB | not supported | - | N | |
2022-05-02 10:06:10 -04:00
| MB85RC64T | 8 KB | Y Page 11 | 4.0 uA* | N | |
2022-05-10 04:10:44 -04:00
| MB85RC128A | 16 KB | not supported | - | N | |
| MB85RC256V | 32 KB | not supported | - | Y | |
2022-05-02 10:06:10 -04:00
| MB85RC512T | 64 KB | Y Page 12 | 4.0 uA* | N | |
| MB85RC1MT | 128 KB | Y Page 12 | 3.6 uA | Y | See #17 |
_current with \* are from datasheet_
### Current
Indicative power usage in uA in three modi (if supported).
| TYPE | SIZE | STANDBY | WRITE | SLEEP | NOTES |
|:----------:|-------:|:--------:|:---------:|:---------:|:--------|
| MB85RC04 | 512 | | | - | |
| MB85RC16 | 2 KB | | | - | |
| MB85RC64T | 8 KB | | | 4.0 uA | |
| MB85RC128A | 16 KB | | | - | |
| MB85RC256V | 32 KB | 10.22 uA | 93.48 uA | - | |
| MB85RC512T | 64 KB | | | 4.0 uA | |
| MB85RC1MT | 128 KB | 11.7 uA | 46-721 uA | 3.6 uA | See #17 |
2022-05-10 04:10:44 -04:00
_TODO: fill the table_
2022-05-02 10:06:10 -04:00
2021-01-29 06:31:58 -05:00
## Operational
2022-02-08 10:47:34 -05:00
2021-12-18 09:02:32 -05:00
See examples
2022-02-08 10:47:34 -05:00
2021-12-18 09:02:32 -05:00
## Future
2022-03-18 08:37:57 -04:00
### high
2022-05-10 04:10:44 -04:00
- improve **FRAM32** that can write over the 64 KB border without problems.
- Would cause extra checking ==> overhead.
- now it is responsibility user.
- do we want/need this?
2022-03-18 08:37:57 -04:00
### medium
2022-05-10 04:10:44 -04:00
2022-03-18 08:37:57 -04:00
- **write()** and **writeBlock()** might write beyond the end of FRAM
- now it is responsibility user.
- testing would degrade performance?
- error flag ?
2021-12-18 09:02:32 -05:00
- extend examples
2022-02-08 10:47:34 -05:00
- FRAM for multi language string storage
- FRAM as linear buffer for a slow stream?
- FRAM as ring buffer
- FRAM logging, unequal length strings.
- FRAM (8x) concatenated as one continuous memory.
2022-03-18 08:37:57 -04:00
### low
2022-05-10 04:10:44 -04:00
2022-03-18 08:37:57 -04:00
- test more types of FRAM
- **getSize()** scanning FRAM like EEPROM library?
- remember last written address? why?
2022-05-02 10:06:10 -04:00
- fill power usage table
2022-03-18 08:37:57 -04:00
2022-05-10 04:10:44 -04:00
2022-03-25 05:04:48 -04:00
### wont
2022-05-10 04:10:44 -04:00
2022-03-25 05:04:48 -04:00
- extend current **clear()** with partial **clear(begin, end, value)**?
- can be done by **writeBlock()** calls by user too
- would need more complex end checking
- ==> wont for now
- **dump(stream)** or printable interface?
- Print interface? expensive in performance per char..
2021-12-18 09:02:32 -05:00