0.8.0 FRAM_I2C

This commit is contained in:
Rob Tillaart 2024-01-16 11:43:21 +01:00
parent 6f5ba8c069
commit 7276c4cb9a
7 changed files with 96 additions and 45 deletions

View File

@ -5,6 +5,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.8.0] - 2024-01-15
- Fix #51 - bug in FRAM32::_readBlock()
- improve fram32 example to test both low and high addresses
- add memory address guarding for the FRAM32 _readBlock() and _writeBlock()
- update readme.md.
----
## [0.7.1] - 2024-01-09
- improve getSize() to support Infineon FM24V10 and FM24V05 (#49)
- update readme.md

View File

@ -1,7 +1,7 @@
//
// FILE: FRAM.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.7.1
// VERSION: 0.8.0
// DATE: 2018-01-24
// PURPOSE: Arduino library for I2C FRAM
// URL: https://github.com/RobTillaart/FRAM_I2C
@ -604,7 +604,8 @@ uint32_t FRAM32::clear(uint8_t value)
void FRAM32::_writeBlock(uint32_t memAddr, uint8_t * obj, uint8_t size)
{
uint8_t _addr = _address;
if (memAddr & 0x00010000) _addr += 0x01;
if (memAddr & 0xFFFE0000) return; // ignore invalid memory addresses
if ((memAddr & 0x00010000) == 0x00010000) _addr += 0x01;
_wire->beginTransmission(_addr);
_wire->write((uint8_t) (memAddr >> 8));
@ -621,9 +622,10 @@ void FRAM32::_writeBlock(uint32_t memAddr, uint8_t * obj, uint8_t size)
void FRAM32::_readBlock(uint32_t memAddr, uint8_t * obj, uint8_t size)
{
uint8_t _addr = _address;
if (memAddr & 0x00010000) _addr += 0x01;
if (memAddr & 0xFFFE0000) return; // ignore invalid memory addresses
if ((memAddr & 0x00010000) == 0x00010000) _addr += 0x01;
_wire->beginTransmission(_address);
_wire->beginTransmission(_addr);
_wire->write((uint8_t) (memAddr >> 8));
_wire->write((uint8_t) (memAddr & 0xFF));
_wire->endTransmission();

View File

@ -2,7 +2,7 @@
//
// FILE: FRAM.h
// AUTHOR: Rob Tillaart
// VERSION: 0.7.1
// VERSION: 0.8.0
// DATE: 2018-01-24
// PURPOSE: Arduino library for I2C FRAM
// URL: https://github.com/RobTillaart/FRAM_I2C
@ -12,7 +12,7 @@
#include "Wire.h"
#define FRAM_LIB_VERSION (F("0.7.1"))
#define FRAM_LIB_VERSION (F("0.8.0"))
#define FRAM_OK 0

View File

@ -305,6 +305,14 @@ Its interface is described in **FRAM_MULTILANGUAGE.md**.
See examples.
## FRAM32
Since version 0.8.0 the FRAM32 internal **readBlock()** and **writeBlock()**
guard for memory addresses that are out of range.
This prevents interference with valid address ranges.
These will just be ignored for now and no error flag whatever is set.
## FRAM11 + FRAM9
- 0.5.0 added, see issue #28
@ -330,6 +338,10 @@ Use **getSizeBytes()** to get 512.
#### Should
- **FRAM32** invalid memory address handling.
- user should be notified of success / failure? how?
- **bool validAddress(uint32_t memAddress)** as preventive strategy.
- or setting an error flag? return value? (impact in class hierarchy).
- Improve **getSize()** to have **clear()** working properly.
- **MB85RC128A** only (hard code fall back?).
- **getSize()** scanning FRAM like EEPROM library?

View File

@ -16,6 +16,70 @@ uint32_t stop;
uint32_t sizeInBytes = 0;
void test_float()
{
float x = 3.14159265;
Serial.println(x, 6);
fram.writeObject(100, x);
x = 1.0/x;
Serial.println(x, 6);
fram.readObject(100, x);
Serial.println(x, 6);
}
struct point
{
float x;
float y;
float z;
} P = {3.91, 5.24, 7.58};
void test_struct_low_address_range()
{
Serial.println(P.x);
Serial.println(P.y);
Serial.println(P.z);
fram.writeObject(50, P);
struct point Q;
fram.readObject(50, Q);
Serial.println(Q.x);
Serial.println(Q.y);
Serial.println(Q.z);
if ((P.x != Q.x) || (P.y != Q.y) || (P.z != Q.z))
{
Serial.println("ERROR!");
}
}
void test_struct_high_address_range()
{
Serial.println(P.x);
Serial.println(P.y);
Serial.println(P.z);
fram.writeObject(70000, P);
struct point Q;
fram.readObject(70000, Q);
Serial.println(Q.x);
Serial.println(Q.y);
Serial.println(Q.z);
if ((P.x != Q.x) || (P.y != Q.y) || (P.z != Q.z))
{
Serial.println("ERROR!");
}
}
void setup()
{
Serial.begin(115200);
@ -41,8 +105,8 @@ void setup()
}
test_float();
test_struct();
test_struct_low_address_range();
test_struct_high_address_range();
}
@ -51,39 +115,4 @@ void loop()
}
void test_float()
{
float x = 3.14159265;
Serial.println(x, 6);
fram.writeObject(100, x);
x = 1.0/x;
Serial.println(x, 6);
fram.readObject(100, x);
Serial.println(x, 6);
}
struct point
{
float x;
float y;
float z;
} P = {3.91, 5.24, 7.58};
void test_struct()
{
Serial.println(P.x);
Serial.println(P.y);
Serial.println(P.z);
fram.writeObject(50, P);
struct point Q;
fram.readObject(50, Q);
Serial.println(Q.x);
Serial.println(Q.y);
Serial.println(Q.z);
}
// -- END OF FILE --

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/FRAM_I2C.git"
},
"version": "0.7.1",
"version": "0.8.0",
"license": "MIT",
"frameworks": "*",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=FRAM_I2C
version=0.7.1
version=0.8.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for I2C FRAM for persistent storage.