-->
Page 1 of 1

Fram MB85RC16 problems

PostPosted: Tue Nov 01, 2016 10:50 am
by Artur Gaspar
Good Morning.
I'm using this library: https://github.com/sosandroid/FRAM_MB85RC_I2C
Recording only a number or an array this all working perfectly.
But when trying to perform two recordings at different addresses, I have the impression that he always writes and read in the same position of memory.
My code:

Code: Select all#include <Wire.h>
#include <math.h>
#include <FRAM_MB85RC_I2C.h>

uint16_t writeaddress = 0x10;
uint16_t testaddress = 0x50;
uint16_t testaddress2 = 0x70;

//Creating object for FRAM chip
FRAM_MB85RC_I2C fram;

void setup() {
  uint8_t readvalue = 0xFF;

  Serial.begin(115200);
  Serial.println("Starting...");
  while (!Serial) ;
  Wire.begin();

  fram.begin();
  byte result;

  result = fram.readByte(writeaddress, &readvalue);
  if (result == 0) Serial.println("Read Done");
  if (result != 0) Serial.println("Read failed");
  Serial.print("Leitura:"); Serial.println(readvalue, DEC);

  result = fram.writeByte(writeaddress, 77);
  if (result == 0) Serial.println("Write Done");
  if (result != 0) Serial.println("Write failed");

  result = fram.writeByte(testaddress, 44);
  if (result == 0) Serial.println("Write Done");
  if (result != 0) Serial.println("Write failed");

  result = fram.readByte(writeaddress, &readvalue);
  if (result == 0) Serial.println("Read Done");
  if (result != 0) Serial.println("Read failed");
  Serial.print("Leitura:"); Serial.println(readvalue, DEC);

  result = fram.readByte(testaddress2, &readvalue);
  if (result == 0) Serial.println("Read Done");
  if (result != 0) Serial.println("Read failed");
  Serial.print("Leitura:"); Serial.println(readvalue, DEC);
}

void loop() {
  // nothing to do
}

Re: Fram MB85RC16 problems

PostPosted: Tue Nov 01, 2016 1:02 pm
by Artur Gaspar
Another test.
Same error.

Code: Select all#include <Wire.h>
int fram = 0x50;
uint16_t writeaddress = 0x20;
uint16_t testaddress = 0x30;
uint16_t testaddress2 = 0x40;

void setup() {
  Wire.begin();

  Serial.begin(115200);
  while (!Serial) ;
  Serial.println("Starting...");

  Wire.beginTransmission(fram);
  writeAddr(writeaddress);
  if( Wire.endTransmission() > 0) Serial.print("Erro da Fram");
  Wire.requestFrom(fram, 1);
  Serial.print("Leitura 1:"); Serial.println(Wire.read(), DEC);

  Wire.beginTransmission(fram);
  writeAddr(writeaddress);
  Wire.write(77);
  Wire.endTransmission();

  Wire.beginTransmission(fram);
  writeAddr(writeaddress);
  Wire.endTransmission();
  Wire.requestFrom(fram, 1);
  Serial.print("Leitura 2:"); Serial.println(Wire.read(), DEC);

  Wire.beginTransmission(fram);
  writeAddr(testaddress);
  Wire.write(21);
  Wire.endTransmission();

  Wire.beginTransmission(fram);
  writeAddr(writeaddress);
  Wire.endTransmission();
  Wire.requestFrom(fram, 1);
  Serial.print("Leitura 3:"); Serial.println(Wire.read(), DEC);

}

void writeAddr(uint16_t addr)
{
  uint8_t highADDR = (uint8_t)((addr & 0xFF00) >> 8);
  uint8_t lowADDR = (uint8_t)(addr & 0x00FF);
  Wire.write(highADDR);
  Wire.write(lowADDR);
}

void loop() {
  // nothing to do
}

Re: Fram MB85RC16 problems

PostPosted: Fri Dec 16, 2016 7:25 am
by Artur Gaspar
And the error continues

Code: Select all#include <Wire.h>

#define disk1 0x50    //Address of 24LC256 eeprom chip

void setup(void)
{
  Serial.begin(115200);
  Wire.begin();

  for (unsigned int address = 0x0; address < 0x7D0; address++) {
    writeEEPROM(disk1, address, 321);
  }
 
  for (unsigned int address = 0x0; address < 0x7D0; address++) {
    Serial.print(address, DEC); Serial.print("=");
    Serial.println(readEEPROM(disk1, address), DEC);
  }
}

void loop() {}

void writeEEPROM(int deviceaddress, unsigned int eeaddress, byte data )
{
  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8));   // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.write(data);
  Wire.endTransmission();
}

byte readEEPROM(int deviceaddress, unsigned int eeaddress )
{
  byte rdata = 0xFF;

  Wire.beginTransmission(deviceaddress);
  Wire.write((int)(eeaddress >> 8));   // MSB
  Wire.write((int)(eeaddress & 0xFF)); // LSB
  Wire.endTransmission();

  Wire.requestFrom(deviceaddress, 1);

  if (Wire.available()) rdata = Wire.read();

  return rdata;
}