2021-01-29 06:31:58 -05:00
|
|
|
//
|
|
|
|
// FILE: testFRAMPerformance.ino
|
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
// PURPOSE: test for FRAM library for Arduino
|
|
|
|
// URL: https://github.com/RobTillaart/FRAM_I2C
|
|
|
|
//
|
|
|
|
|
2021-12-18 09:02:32 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
#include "FRAM.h"
|
|
|
|
|
2021-12-18 09:02:32 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
FRAM fram;
|
|
|
|
|
|
|
|
uint32_t start;
|
|
|
|
uint32_t stop;
|
|
|
|
|
2024-01-09 12:48:24 -05:00
|
|
|
int ar[600]; // == 1200 bytes
|
2021-12-18 09:02:32 -05:00
|
|
|
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.println(__FILE__);
|
|
|
|
Serial.print("FRAM_LIB_VERSION: ");
|
|
|
|
Serial.println(FRAM_LIB_VERSION);
|
|
|
|
Serial.println();
|
|
|
|
Serial.println();
|
|
|
|
|
|
|
|
Wire.begin();
|
|
|
|
|
|
|
|
int rv = fram.begin(0x50);
|
|
|
|
if (rv != 0)
|
|
|
|
{
|
|
|
|
Serial.println(rv);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-01-09 12:48:24 -05:00
|
|
|
for (int s = 1; s < 9; s++) // test up to 800 KB
|
2021-01-29 06:31:58 -05:00
|
|
|
{
|
|
|
|
uint32_t speed = s * 100000UL;
|
|
|
|
Serial.print("CLOCK: ");
|
|
|
|
Serial.println(speed);
|
|
|
|
Wire.setClock(speed);
|
|
|
|
testReadWriteLarge();
|
|
|
|
}
|
|
|
|
Wire.setClock(100000);
|
|
|
|
}
|
|
|
|
Serial.println("done...");
|
|
|
|
}
|
|
|
|
|
2021-12-18 09:02:32 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-12-18 09:02:32 -05:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
void testReadWriteLarge()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 600; i++) ar[i] = i;
|
|
|
|
|
2022-03-18 08:37:57 -04:00
|
|
|
start = micros();
|
2021-01-29 06:31:58 -05:00
|
|
|
fram.write(1000, (uint8_t*)ar, 1200);
|
2022-03-18 08:37:57 -04:00
|
|
|
stop = micros();
|
|
|
|
Serial.print("WRITE 1200 bytes TIME: \t");
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.print(stop - start);
|
2022-03-18 08:37:57 -04:00
|
|
|
Serial.print(" us ==> \t");
|
|
|
|
Serial.print((stop - start) / 1200.0, 2);
|
|
|
|
Serial.println(" us/byte.");
|
|
|
|
delay(100);
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
for (int i = 0; i < 600; i++) ar[i] = 0;
|
|
|
|
|
2022-03-18 08:37:57 -04:00
|
|
|
start = micros();
|
2021-01-29 06:31:58 -05:00
|
|
|
fram.read(1000, (uint8_t*)ar, 1200);
|
2022-03-18 08:37:57 -04:00
|
|
|
stop = micros();
|
|
|
|
Serial.print("READ 1200 bytes TIME: \t");
|
2021-01-29 06:31:58 -05:00
|
|
|
Serial.print(stop - start);
|
2022-03-18 08:37:57 -04:00
|
|
|
Serial.print(" us ==> \t");
|
|
|
|
Serial.print((stop - start) / 1200.0, 2);
|
|
|
|
Serial.println(" us/byte.");
|
|
|
|
delay(100);
|
2021-01-29 06:31:58 -05:00
|
|
|
|
|
|
|
for (int i = 0; i < 600; i++)
|
|
|
|
{
|
|
|
|
if (ar[i] != i)
|
|
|
|
{
|
|
|
|
Serial.print("FAIL: \t");
|
|
|
|
Serial.print(ar[i]);
|
|
|
|
Serial.print('\t');
|
|
|
|
Serial.println(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Serial.println();
|
|
|
|
}
|
|
|
|
|
2021-12-18 09:02:32 -05:00
|
|
|
|
2024-01-09 12:48:24 -05:00
|
|
|
// -- END OF FILE --
|
2021-12-18 09:02:32 -05:00
|
|
|
|