mirror of
https://github.com/RobTillaart/I2C_EEPROM.git
synced 2026-07-27 20:06:07 +00:00
Develop (#35)
* build-CI + badges * add setExtraWriteCycleTIme() to adjust some timing.
This commit is contained in:
+7
-3
@@ -2,6 +2,10 @@ compile:
|
||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||
platforms:
|
||||
- uno
|
||||
- leonardo
|
||||
- due
|
||||
- zero
|
||||
# - due
|
||||
# - zero
|
||||
# - leonardo
|
||||
- m4
|
||||
- esp32
|
||||
# - esp8266
|
||||
# - mega2560
|
||||
@@ -4,10 +4,14 @@ name: Arduino CI
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
arduino_ci:
|
||||
runTest:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: Arduino-CI/action@master
|
||||
# Arduino-CI/action@v0.1.1
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.6
|
||||
- run: |
|
||||
gem install arduino_ci
|
||||
arduino_ci.rb
|
||||
|
||||
+5
-3
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: I2C_eeprom.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 1.5.0
|
||||
// VERSION: 1.5.1
|
||||
// PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al.
|
||||
// URL: https://github.com/RobTillaart/I2C_EEPROM.git
|
||||
//
|
||||
@@ -39,6 +39,7 @@
|
||||
// 1.4.2 2021-01-31 add updateBlock()
|
||||
// 1.4.3 2021-05-05 adjust buffer size AVR / ESP +rename
|
||||
// 1.5.0 2021-06-30 #28 fix addressing 24LC04/08/16
|
||||
// 1.5.1 2021-10-14 function to add extra for write cycle (experimental)
|
||||
|
||||
|
||||
#include <I2C_eeprom.h>
|
||||
@@ -371,10 +372,11 @@ uint8_t I2C_eeprom::_ReadBlock(const uint16_t memoryAddress, uint8_t* buffer, co
|
||||
void I2C_eeprom::_waitEEReady()
|
||||
{
|
||||
#define I2C_WRITEDELAY 5000
|
||||
|
||||
// Wait until EEPROM gives ACK again.
|
||||
// this is a bit faster than the hardcoded 5 milliSeconds
|
||||
while ((micros() - _lastWrite) <= I2C_WRITEDELAY)
|
||||
// TWR = WriteCycleTime
|
||||
uint32_t waitTime = I2C_WRITEDELAY + _extraTWR * 1000UL; // do the math once.
|
||||
while ((micros() - _lastWrite) <= waitTime)
|
||||
{
|
||||
_wire->beginTransmission(_deviceAddress);
|
||||
int x = _wire->endTransmission();
|
||||
|
||||
+8
-2
@@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: I2C_eeprom.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 1.5.0
|
||||
// VERSION: 1.5.1
|
||||
// PURPOSE: Arduino Library for external I2C EEPROM 24LC256 et al.
|
||||
// URL: https://github.com/RobTillaart/I2C_EEPROM.git
|
||||
//
|
||||
@@ -13,7 +13,7 @@
|
||||
#include "Wire.h"
|
||||
|
||||
|
||||
#define I2C_EEPROM_VERSION (F("1.5.0"))
|
||||
#define I2C_EEPROM_VERSION (F("1.5.1"))
|
||||
|
||||
|
||||
#define I2C_DEVICESIZE_24LC512 65536
|
||||
@@ -88,11 +88,17 @@ public:
|
||||
uint8_t getPageSize(uint32_t deviceSize);
|
||||
uint32_t getLastWrite() { return _lastWrite; };
|
||||
|
||||
// TWR = WriteCycleTime
|
||||
// 5 ms is minimum, one can add extra ms here to adjust timing of both read() and write()
|
||||
void setExtraWriteCycleTime(uint8_t ms) { _extraTWR = ms; };
|
||||
uint8_t getExtraWriteCycleTime() { return _extraTWR; };
|
||||
|
||||
private:
|
||||
uint8_t _deviceAddress;
|
||||
uint32_t _lastWrite; // for waitEEReady
|
||||
uint32_t _deviceSize;
|
||||
uint8_t _pageSize;
|
||||
uint8_t _extraTWR = 0; // milliseconds
|
||||
|
||||
// 24LC32..24LC512 use two bytes for memory address
|
||||
// 24LC01..24LC16 use one-byte addresses + part of device address
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
|
||||
[](https://github.com/marketplace/actions/arduino_ci)
|
||||
[](https://github.com/RobTillaart/I2C_EEPROM/actions/workflows/arduino-lint.yml)
|
||||
[](https://github.com/RobTillaart/I2C_EEPROM/actions/workflows/jsoncheck.yml)
|
||||
[](https://github.com/RobTillaart/I2C_EEPROM/blob/master/LICENSE)
|
||||
[](https://github.com/RobTillaart/I2C_EEPROM/releases)
|
||||
|
||||
@@ -54,7 +56,7 @@ The debug flag gives some output to Serial.
|
||||
Test results
|
||||
|
||||
| Type | returns | Memory | Page Size | Notes |
|
||||
|:--------|:--------|:---------|:-----:|:------|
|
||||
|:--------|:--------|:---------|:---------:|:------|
|
||||
| - | 0 | | | connect error, check device address / wiring |
|
||||
| 24LC512 | 65536 | 64 KB | 128 | |
|
||||
| 24LC256 | 32768 | 32 KB | 64 | |
|
||||
@@ -84,6 +86,18 @@ If data is changed often between writes, **updateBlock()** is slower than **writ
|
||||
So you should verify if your sketch can make use of the advantages of **updateBlock()**
|
||||
|
||||
|
||||
#### ExtraWriteCycleTime (experimental)
|
||||
|
||||
(new since 1.5.1)
|
||||
|
||||
To improve support older I2C EEPROMs e.g. IS24C16 two functions were added to increase
|
||||
the waiting time before a read and/or write as some older devices have a larger timeout
|
||||
than 5 milliseconds which is the minimum.
|
||||
|
||||
- **void setExtraWriteCycleTime(uint8_t ms)** idem
|
||||
- **uint8_t getExtraWriteCycleTime()** idem
|
||||
|
||||
|
||||
## Limitation
|
||||
|
||||
The library does not offer multiple EEPROMS as one continuous storage device.
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
//
|
||||
// FILE: I2C_eeprom_struct.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo I2C_EEPROM library store /retrieve struct
|
||||
//
|
||||
|
||||
// uses a 24LC256 (32KB) EEPROM
|
||||
// as this test writes a lot it might wear out EEPROMs eventually.
|
||||
//
|
||||
|
||||
|
||||
#include "Wire.h"
|
||||
#include "I2C_eeprom.h"
|
||||
|
||||
|
||||
I2C_eeprom ee(0x50, I2C_DEVICESIZE_24LC256);
|
||||
|
||||
|
||||
uint32_t start, duration;
|
||||
|
||||
struct
|
||||
{
|
||||
float temperature;
|
||||
float humidity;
|
||||
float pressure;
|
||||
} measurement;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial); // wait for Serial to connect.
|
||||
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("VERSION: ");
|
||||
Serial.println(I2C_EEPROM_VERSION);
|
||||
Serial.println();
|
||||
|
||||
ee.begin();
|
||||
if (! ee.isConnected())
|
||||
{
|
||||
Serial.println("ERROR: Can't find eeprom (stopped)...");
|
||||
// while (1);
|
||||
}
|
||||
|
||||
Serial.print("size: \t");
|
||||
Serial.println(sizeof(measurement));
|
||||
|
||||
// clear EEPROM part
|
||||
ee.setBlock(0, 0, sizeof(measurement));
|
||||
|
||||
// make measurement here
|
||||
measurement.temperature = 22.5;
|
||||
measurement.humidity = 53.1;
|
||||
measurement.pressure = 1000.9;
|
||||
|
||||
// store it in EEPROM
|
||||
start = micros();
|
||||
ee.writeBlock(0, (uint8_t *) &measurement, sizeof(measurement));
|
||||
duration = micros() - start;
|
||||
Serial.print("write: \t");
|
||||
Serial.println(duration);
|
||||
delay(10);
|
||||
|
||||
// clear measurement struct
|
||||
measurement.temperature = 0;
|
||||
measurement.humidity = 0;
|
||||
measurement.pressure = 0;
|
||||
|
||||
// retrieve old measurement
|
||||
start = micros();
|
||||
ee.readBlock(0, (uint8_t *) &measurement, sizeof(measurement));
|
||||
duration = micros() - start;
|
||||
Serial.print("read: \t");
|
||||
Serial.println(duration);
|
||||
delay(10);
|
||||
|
||||
Serial.print("temp:\t");
|
||||
Serial.println(measurement.temperature);
|
||||
Serial.print("hum:\t");
|
||||
Serial.println(measurement.humidity);
|
||||
Serial.print("pres:\t");
|
||||
Serial.println(measurement.pressure);
|
||||
|
||||
Serial.println("\ndone...");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
// -- END OF FILE
|
||||
@@ -1,128 +0,0 @@
|
||||
|
||||
Try this (not tested)
|
||||
[code]
|
||||
//#include <UTFT.h>
|
||||
#include <SD.h>
|
||||
#include <Wire.h>
|
||||
#include <ArduCAM.h>
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
#define SD_CS 9
|
||||
|
||||
|
||||
//UTFT(byte model, int RS, int WR, int RD, int CS)
|
||||
//UTFT myGLCD(ITDB32S,A2,A1,A0,10); // Remember to change the model parameter to suit your display module!
|
||||
//ArduCAM(byte model,int RS, int WR, int RD, int REG_CS, int FIFO_CS)
|
||||
ArduCAM myCAM(OV2640,A2,A1,A0,A3,10); // Remember to change the model parameter to suit your canera module!
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200); // <<<<<<<<<<<<<<<<<<<<<<<
|
||||
Serial.println("Start arducam test");
|
||||
|
||||
//Initialize I2C Bus
|
||||
Wire.begin();
|
||||
//Switch to FIFO Mode
|
||||
myCAM.write_reg(ARDUCHIP_TIM, MODE_MASK);
|
||||
//Set sensor to JPEG mode. Note don't all the camera modules support JPEG mode
|
||||
myCAM.OV2640_set_format(JPEG);
|
||||
//Initialize Camera Module
|
||||
myCAM.InitCAM();
|
||||
myCAM.OV2640_set_JPEG_size(OV2640_320x240);
|
||||
|
||||
Serial.println("SD.begin");
|
||||
//Initialize SD Card
|
||||
if (!SD.begin(SD_CS))
|
||||
{
|
||||
Serial.println("SD card failed");
|
||||
//while (1); //If failed, stop here
|
||||
}
|
||||
Serial.println("SD card success");
|
||||
Serial.println("End setup");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.print(millis());
|
||||
Serial.println("\tstart loop");
|
||||
|
||||
char str[8];
|
||||
File outFile;
|
||||
static int k = 0;
|
||||
uint8_t temp,temp_last;
|
||||
uint8_t start_capture = 0;
|
||||
|
||||
Serial.print(millis());
|
||||
Serial.println("\tWait trigger from shutter buttom");
|
||||
|
||||
//Wait trigger from shutter buttom
|
||||
if(myCAM.read_reg(ARDUCHIP_TRIG) & SHUTTER_MASK)
|
||||
{
|
||||
//Wait until buttom released
|
||||
while(myCAM.read_reg(ARDUCHIP_TRIG) & SHUTTER_MASK);
|
||||
start_capture = 1;
|
||||
}
|
||||
|
||||
|
||||
Serial.print(millis());
|
||||
Serial.println("\tStart capture I");
|
||||
//Start capture when detect a valid shutter press
|
||||
if(start_capture)
|
||||
{
|
||||
//Flush the FIFO
|
||||
myCAM.flush_fifo();
|
||||
//Start capture
|
||||
myCAM.start_capture();
|
||||
}
|
||||
|
||||
if(myCAM.read_reg(ARDUCHIP_TRIG) & CAP_DONE_MASK)
|
||||
{
|
||||
//Construct a file name
|
||||
k = k + 1;
|
||||
itoa(k, str, 10);
|
||||
strcat(str,".jpg");
|
||||
//Open the new file
|
||||
outFile = SD.open(str,FILE_WRITE);
|
||||
if (! outFile)
|
||||
{
|
||||
Serial.print(millis());
|
||||
Serial.println("\tfailure outfile");
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.print(millis());
|
||||
Serial.println("\toutfile succes");
|
||||
|
||||
//Enable FIFO
|
||||
myCAM.enable_fifo();
|
||||
|
||||
uint32_t bytecounter = 0;
|
||||
//Read the first dummy byte from FIFO
|
||||
temp = myCAM.read_fifo();
|
||||
|
||||
//Read JPEG data from FIFO
|
||||
while( (temp != 0xD9) | (temp_last != 0xFF) )
|
||||
{
|
||||
bytecounter++;
|
||||
if (bytecounter % 32 == 0) Serial.print('.');
|
||||
if (bytecounter % 1024 == 0) Serial.println;
|
||||
temp_last = temp;
|
||||
temp = myCAM.read_fifo();
|
||||
//Write image data to file
|
||||
outFile.write(temp);
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
//Disable FIFO when all the image data is saved to the file
|
||||
myCAM.disable_fifo();
|
||||
//Close the file
|
||||
outFile.close();
|
||||
|
||||
//Clear the capture done flag
|
||||
myCAM.clear_fifo_flag();
|
||||
//Clear the start capture flag
|
||||
start_capture = 0;
|
||||
}
|
||||
}
|
||||
|
||||
[/code]
|
||||
+1
-1
@@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/I2C_EEPROM.git"
|
||||
},
|
||||
"version": "1.5.0",
|
||||
"version": "1.5.1",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*"
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
name=I2C_EEPROM
|
||||
version=1.5.0
|
||||
version=1.5.1
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Library for I2C EEPROMS
|
||||
|
||||
Reference in New Issue
Block a user