-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- fix #42 ReadObject, WriteObject for FRAM32 - add examples - minor edits
- Loading branch information
1 parent
711800a
commit 221e8dc
Showing
10 changed files
with
216 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// | ||
// FILE: FRAM11_writeObject.ino | ||
// AUTHOR: Rob Tillaart | ||
// PURPOSE: demo writing reading objects | ||
// URL: https://github.com/RobTillaart/FRAM_I2C | ||
// | ||
// experimental | ||
|
||
|
||
#include "FRAM.h" | ||
|
||
FRAM11 fram; | ||
|
||
uint32_t start; | ||
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() | ||
{ | ||
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 -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// | ||
// FILE: FRAM32_writeObject.ino | ||
// AUTHOR: Rob Tillaart | ||
// PURPOSE: demo writing reading objects | ||
// URL: https://github.com/RobTillaart/FRAM_I2C | ||
// | ||
// experimental | ||
|
||
|
||
#include "FRAM.h" | ||
|
||
FRAM32 fram; | ||
|
||
uint32_t start; | ||
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() | ||
{ | ||
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 -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name=FRAM_I2C | ||
version=0.5.4 | ||
version=0.6.0 | ||
author=Rob Tillaart <[email protected]> | ||
maintainer=Rob Tillaart <[email protected]> | ||
sentence=Arduino library for I2C FRAM for persistent storage. | ||
|