Skip to content

Commit

Permalink
Fix #51 - bug in FRAM32::_readBlock()
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed Jan 15, 2024
1 parent 768065a commit 241e7d0
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 41 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ 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()

----

## [0.7.1] - 2024-01-09
- improve getSize() to support Infineon FM24V10 and FM24V05 (#49)
- update readme.md
Expand Down
4 changes: 2 additions & 2 deletions FRAM.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -623,7 +623,7 @@ void FRAM32::_readBlock(uint32_t memAddr, uint8_t * obj, uint8_t size)
uint8_t _addr = _address;
if (memAddr & 0x00010000) _addr += 0x01;

_wire->beginTransmission(_address);
_wire->beginTransmission(_addr);
_wire->write((uint8_t) (memAddr >> 8));
_wire->write((uint8_t) (memAddr & 0xFF));
_wire->endTransmission();
Expand Down
4 changes: 2 additions & 2 deletions FRAM.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
99 changes: 64 additions & 35 deletions examples/FRAM32_writeObject/FRAM32_writeObject.ino
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,6 @@ uint32_t stop;
uint32_t sizeInBytes = 0;


void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("FRAM_LIB_VERSION: ");
Serial.println(FRAM_LIB_VERSION);

Wire.begin();

int rv = fram.begin(0x50);
if (rv != 0)
{
Serial.print("INIT ERROR: ");
Serial.println(rv);
}

// get size in bytes
sizeInBytes = fram.getSize() * 1024;
// clear FRAM
for (uint32_t addr = 0; addr < sizeInBytes; addr++)
{
fram.write8(addr, 0x00);
}

test_float();
test_struct();

}


void loop()
{
}


void test_float()
{
Expand All @@ -64,14 +30,16 @@ void test_float()
Serial.println(x, 6);
}


struct point
{
float x;
float y;
float z;
} P = {3.91, 5.24, 7.58};

void test_struct()

void test_struct_low_address_range()
{
Serial.println(P.x);
Serial.println(P.y);
Expand All @@ -83,6 +51,67 @@ void test_struct()
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);
Serial.println(__FILE__);
Serial.print("FRAM_LIB_VERSION: ");
Serial.println(FRAM_LIB_VERSION);

Wire.begin();

int rv = fram.begin(0x50);
if (rv != 0)
{
Serial.print("INIT ERROR: ");
Serial.println(rv);
}

// get size in bytes
sizeInBytes = fram.getSize() * 1024;
// clear FRAM
for (uint32_t addr = 0; addr < sizeInBytes; addr++)
{
fram.write8(addr, 0x00);
}

test_float();
test_struct_low_address_range();
test_struct_high_address_range();
}


void loop()
{
}


Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=FRAM_I2C
version=0.7.1
version=0.8.0
author=Rob Tillaart <[email protected]>
maintainer=Rob Tillaart <[email protected]>
sentence=Arduino library for I2C FRAM for persistent storage.
Expand Down

0 comments on commit 241e7d0

Please sign in to comment.