Salut les amis, j'ai un problème j'essaie temps-bien que mal de résoudre mon problème mais j'ai du mal a comprendre mon erreur j'aimerais écrire sur ma mémoire qui est a l'adresse 0x00, une valeur en décimal puis la lire mais bien que j'ai chercher sur internet je n'y arrive pas, pouvez vous m'aidez la dessus ? merci d'avance !
#include <EEPROM.h>
#include <Wire.h>
EEPROM.fram(0x00); // i2c adress is determined by state of pins A2 and A1
// for example, if A2 = VCC and A1 = GND write : FRAM fram(0b10);
void setup() {
Serial.begin(9600);
EEPROM.WriteByte(0,5,55);
Serial.println(EEPROM.ReadByte(0,5));
EEPROM.WriteInt(0,15,30000);
Serial.println(EEPROM.ReadInt(0,15));
EEPROM.WriteInt(0,20,-30000);
Serial.println(EEPROM.ReadInt(0,20));
}
void loop() {
}
/*
* EEPROM Write
*
* Stores values read from analog input 0 into the EEPROM.
* These values will stay in the EEPROM when the board is
* turned off and may be retrieved later by another sketch.
*/
#include <EEPROM.h>
/** the current address in the EEPROM (i.e. which byte we're going to write to next) **/
int addr = 0;
void setup(){ /** Empty setup. **/}
void loop()
{
/***
Need to divide by 4 because analog inputs range from
0 to 1023 and each byte of the EEPROM can only hold a
value from 0 to 255.
***/
int val = analogRead(0) / 4;
/***
Write the value to the appropriate byte of the EEPROM.
these values will remain there when the board is
turned off.
***/
EEPROM.write(addr, val);
/***
Advance to the next address, when at the end restart at the beginning.
Larger AVR processors have larger EEPROM sizes, E.g:
- Arduno Duemilanove: 512b EEPROM storage.
- Arduino Uno: 1kb EEPROM storage.
- Arduino Mega: 4kb EEPROM storage.
Rather than hard-coding the length, you should use the pre-provided length function.
This will make your code portable to all AVR processors.
***/
addr = addr + 1;
if(addr == EEPROM.length())
addr = 0;
/***
As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an
EEPROM address is also doable by a bitwise and of the length - 1.
++addr &= EEPROM.length() - 1;
***/
delay(100);
}
lecture:
/*
* EEPROM Read
*
* Reads the value of each byte of the EEPROM and prints it
* to the computer.
* This example code is in the public domain.
*/
#include <EEPROM.h>
// start reading from the first byte (address 0) of the EEPROM
int address = 0;
byte value;
void setup()
{
// initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
}
void loop()
{
// read a byte from the current address of the EEPROM
value = EEPROM.read(address);
Serial.print(address);
Serial.print("\t");
Serial.print(value, DEC);
Serial.println();
/***
Advance to the next address, when at the end restart at the beginning.
Larger AVR processors have larger EEPROM sizes, E.g:
- Arduno Duemilanove: 512b EEPROM storage.
- Arduino Uno: 1kb EEPROM storage.
- Arduino Mega: 4kb EEPROM storage.
Rather than hard-coding the length, you should use the pre-provided length function.
This will make your code portable to all AVR processors.
***/
address = address + 1;
if(address == EEPROM.length())
address = 0;
/***
As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an
EEPROM address is also doable by a bitwise and of the length - 1.
++address &= EEPROM.length() - 1;
***/
delay(500);
}
il y a peut être confusion entre l'adresse du composant mémoire sur le bus I2C et l'adresse de la case mémoire dans le composant. Il est douteux que le composant soit à l'adresse 0x00 sur le bus I2C.
2° ) Référence exacte du composant mémoire I2C utilisé ?? les mémoires I2C ne sont pas toutes des EEPROM !!
Dans le code on voit apparaitre le terme FRAM. Il n'évoque que pas une EEPROM mais une mémoire RAM Ferroéclectrique (qui conserve ses données lorsque l'alimentation est coupée.
Elle est gérée de manière spécifique.
Voir par exemple la bibliothèque d'Adafruit pour sa carte FRAM I2C si le composant mémoire I2C est une FRAM