Skip to content

Commit

Permalink
0.8.2 FRAM_I2C
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed Feb 6, 2025
1 parent f13d003 commit 7c712b7
Show file tree
Hide file tree
Showing 10 changed files with 255 additions and 18 deletions.
6 changes: 6 additions & 0 deletions libraries/FRAM_I2C/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.8.2] - 2025-02-03
- support AVR_ATtiny85 / 84, kudos to GiorgosXou
- add **FRAM_ATTINY85_COMPILE_TEST.ino** for testing
- update readme.md with ATTINY section
- improve FRAM32_Performance.ino RAM usage with F()

## [0.8.1] - 2024-07-19
- Fix #56, performance sketch
- minor edits
Expand Down
2 changes: 1 addition & 1 deletion libraries/FRAM_I2C/FRAM.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// FILE: FRAM.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.8.1
// VERSION: 0.8.2
// DATE: 2018-01-24
// PURPOSE: Arduino library for I2C FRAM
// URL: https://github.com/RobTillaart/FRAM_I2C
Expand Down
18 changes: 13 additions & 5 deletions libraries/FRAM_I2C/FRAM.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@
//
// FILE: FRAM.h
// AUTHOR: Rob Tillaart
// VERSION: 0.8.1
// VERSION: 0.8.2
// DATE: 2018-01-24
// PURPOSE: Arduino library for I2C FRAM
// URL: https://github.com/RobTillaart/FRAM_I2C


#include "Arduino.h"
#include "Wire.h"


#define FRAM_LIB_VERSION (F("0.8.1"))
#if (defined(ARDUINO_attiny) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny85__)) && !defined(TwoWire_h)
#include "TinyWireM.h"
#define Wire TinyWireM
#define TwoWire USI_TWI
#pragma message(" [WARNING] Defaulting to 'TinyWireM.h'. 'Wire' is defined as 'TinyWireM', and 'TwoWire' as 'USI_TWI'.")
#pragma message(" [WARNING] To override or fall back, include 'Wire.h' above the library.")
#else
#include "Wire.h"
#endif


#define FRAM_LIB_VERSION (F("0.8.2"))


#define FRAM_OK 0
Expand Down
2 changes: 1 addition & 1 deletion libraries/FRAM_I2C/LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018-2024 Rob Tillaart
Copyright (c) 2018-2025 Rob Tillaart

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
18 changes: 18 additions & 0 deletions libraries/FRAM_I2C/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,24 @@ Not tested: expect the **MB85RC1MT** can be addressed with 2 instances of **FRAM
too with adjacent addresses.


### ATTINY (experimental)

- https://github.com/RobTillaart/FRAM_I2C/pull/58

Since 0.8.2 there is **experimental** support of the ATtiny85 device.
With the FRAM the (persistent) storage of an ATtiny increases a lot.

The library is not tested by me with ATtiny hardware, however compilation
is confirmed to work with IDE 1.8.19 (FRAM_ATTINY85_COMPILE_TEST.ino only)

NOTE: the examples of the library won't work with an ATtiny85 as they are
written for the **Wire.h** where ATtiny uses **TinyWireM.h**.
They can however be used as a guide how to call the library functions.

The code is expected to work with other ATTINY devices too.
If you encounter problems or success, please open an issue on GitHub.


### Related

- https://github.com/RobTillaart/I2C_EEPROM (eeprom)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("FRAM_LIB_VERSION: ");
Serial.print(F("FRAM_LIB_VERSION: "));
Serial.println(FRAM_LIB_VERSION);
Serial.println();
Serial.println();
Expand All @@ -37,7 +37,7 @@ void setup()
for (int s = 1; s < 9; s++) // test up to 800 KB
{
uint32_t speed = s * 100000UL;
Serial.print("CLOCK: ");
Serial.print(F("CLOCK: "));
Serial.println(speed);
Wire.setClock(speed);
testReadWriteLarge();
Expand All @@ -60,30 +60,30 @@ void testReadWriteLarge()
start = micros();
fram.write(1000, (uint8_t*)ar, 1200);
stop = micros();
Serial.print("WRITE 1200 bytes TIME: \t");
Serial.print(F("WRITE 1200 bytes TIME: \t"));
Serial.print(stop - start);
Serial.print(" us ==> \t");
Serial.print(F(" us ==> \t"));
Serial.print((stop - start) / 1200.0, 2);
Serial.println(" us/byte.");
Serial.println(F(" us/byte."));
delay(100);

for (int i = 0; i < 600; i++) ar[i] = 0;

start = micros();
fram.read(1000, (uint8_t*)ar, 1200);
stop = micros();
Serial.print("READ 1200 bytes TIME: \t");
Serial.print(F("READ 1200 bytes TIME: \t"));
Serial.print(stop - start);
Serial.print(" us ==> \t");
Serial.print(F(" us ==> \t"));
Serial.print((stop - start) / 1200.0, 2);
Serial.println(" us/byte.");
Serial.println(F(" us/byte."));
delay(100);

for (int i = 0; i < 600; i++)
{
if (ar[i] != i)
{
Serial.print("FAIL: \t");
Serial.print(F("FAIL: \t"));
Serial.print(ar[i]);
Serial.print('\t');
Serial.println(i);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:

packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json

compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
# - uno
# - due
# - zero
# - leonardo
# - m4
# - esp32
# - esp8266
# - mega2560
# - rpipico
# - nano_every

Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
//
// FILE: FRAM_ATTINY85_COMPILE_TEST.ino
// AUTHOR: Rob Tillaart
// PURPOSE: compile test for FRAM library with ATTINY85
// URL: https://github.com/RobTillaart/FRAM_I2C
//
//
// WARNING: not tested with hardware, only compilation.
// this example is for checking if there are compile errors.
// TESTED: IDE: 1.8.19 ATTINY85
//


#include "TinyWireM.h"
#include "FRAM.h"


FRAM fram;

uint32_t start;
uint32_t stop;


void setup()
{
TinyWireM.begin();

fram.begin(0x50);

testID();
testFRAMmemory();
testReadWriteSmall();
testReadWriteLarge();
// testWriteText();
// testReadText1();
// testReadText2();
}


void loop()
{
}


void testID()
{
int x = fram.getManufacturerID();
int y = fram.getProductID();
int s = fram.getSize();
}

void testFRAMmemory()
{

start = millis();
uint8_t val = 0x55;
for (uint16_t addr = 0; addr < 32768; addr++)
{
fram.write8(addr, val);
if (fram.read8(addr) != 0x55)
{
}
if (addr % 1000 == 0)
{
}
}
stop = millis();
}


void testReadWriteSmall()
{
uint8_t t8 = 0xFE;
fram.write8(1000, t8);
if (fram.read8(1000) != 0xFE)
{
}
else
{
}


uint16_t t16 = 0xFADE;
fram.write16(1000, t16);
if (fram.read16(1000) != 0xFADE)
{

}
else
{

}


uint32_t t32 = 0xFADEFACE;
fram.write32(1000, t32);
if (fram.read32(1000) != 0xFADEFACE)
{

}
else
{
}

}


void testReadWriteLarge()
{
uint8_t ar[20];
for (int i = 0; i < 20; i++) ar[i] = i;

start = millis();
fram.write(1000, ar, 20);
stop = millis();

for (int i = 0; i < 20; i++) ar[i] = 0;

start = millis();
fram.read(1000, ar, 20);
stop = millis();

for (int i = 0; i < 20; i++)
{
if (ar[i] != i)
{
}
}

}


void testWriteText()
{
char str[5][16] =
{
"Hello world 0",
"Hello world 1",
"Hello world 2",
"Hello world 3",
"Hello world 4",
};

start = millis();
fram.write(2000, (uint8_t *)str, 80);
stop = millis();
}


void testReadText1()
{
char str[5][16];

start = millis();
fram.read(2000, (uint8_t *)str, 80);
stop = millis();

for (int i = 0; i < 5; i++)
{
}
}


void testReadText2()
{
char str[16];

for (int i = 0; i < 5; i++)
{
fram.read(2000 + 16 * i, (uint8_t *)str, 16);
}
}



// -- END OF FILE --
2 changes: 1 addition & 1 deletion libraries/FRAM_I2C/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.8.1",
"version": "0.8.2",
"license": "MIT",
"frameworks": "*",
"platforms": "*",
Expand Down
2 changes: 1 addition & 1 deletion libraries/FRAM_I2C/library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=FRAM_I2C
version=0.8.1
version=0.8.2
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 7c712b7

Please sign in to comment.