MB85RC FRAM Issue


#1

I am getting an address for an FRAM even with out one being connected

Here is a code snippet:
local i2c = hardware.i2c0; //hardware.i2cJK or hardware.i2c0
i2c.configure(CLOCK_SPEED_400_KHZ);

local fram1 = MB85RC(i2c, 0xA0, 256, null, true);
//addresses are 0xA0, 0xA2, 0xA4, 0xA6, 0xA6, 0xA8, 0xAA, 0xAC, 0xAE

//this is used allow the use of upto 8 FRAMs as if they were 1
//local fram2 = MB85RC(i2c, 0xA2, 256);
//local fram3 = MB85RC(i2c, 0xA4, 256);
//local fram4 = MB85RC(i2c, 0xA6, 256);
//…

server.log(“fram :” + fram1); //testing only

if (fram1 == null)
{
server.log(“FRAM Error”);
//set error
}
else
{
server.log(“FRAM OK”);
//set continue flag??
}

Here is the response:

2018-03-24 13:50:28 +10:30 [Status] Agent restarted: reload.
2018-03-24 13:50:28 +10:30 [Agent] Agent Started
2018-03-24 13:50:29 +10:30 [Device] fram :(instance : 0x53dfb8)
2018-03-24 13:50:29 +10:30 [Device] FRAM OK

Any ideas?


#2

It’s been a while since I wrote this, so let me check, but IIRC, it doesn’t test for the presence of a FRAM device at the address passed into the constructor. Your test (fram1 == null)) will therefore always pass because the object is always instantiated.


#3

I found this as a suggestion for validating FRAM connection

if (i2c.read(address, “”, 1) != null)

Thoughts?


#4

Also:
writeByte(address, value)
Allows you to write a value from 0x00—0xFF to the FRAM. An 8bit uint, Great.

readByte(address)
Returns the unsigned 8-bit value located at address. The returned value is a single-character string.
Not good as there appears to be no way of converting the single-character string into an 8 bit int again.

Even using a blob with int type ‘b’ fails.

How do I retrieve the 8bit uint a value (from 0x00—0xFF) from the FRAM?


#5

That’ll do it. I’m in the process of updating the MB85RC library and plan to update the function checkFramInfo() as follows (the key change is the addition of the third line):

function checkFramInfo() {
  local bytes = _i2c.read(0xF8, _i2cAddr.tochar(), 3);
  if (bytes == null) return false;
  local manufID = (bytes[0] << 4) + (bytes[1]  >> 4);
  local prodID = ((bytes[1] & 0x0F) << 8) + bytes[2];
  if (manufID != 0x00A) {
    if (_debug) server.error("Unexpected Manufacturer ID: 0x" + manufID + " for chip at I2C address: " + format("0x%02X", _i2cAddr));
    return false;
  }

  if (prodID != 0x510) {
    if (_debug) server.error("Unexpected Product ID: 0x" + prodID + " for chip at I2C address: " + format("0x%02X", _i2cAddr));
    return false;
  }

  if (_debug) {
    server.log("FRAM I2C Address: " + format("0x%02X", _i2cAddr));
    server.log(" Manufacturer ID: " + format("0x%02X", manufID));
    server.log("      Product ID: " + format("0x%02X", prodID));
    server.log("            Size: " + _size + "Kb (" + (_size / 8) + "KB)");
    server.log("   Address Range: " + format("0x%04X", _minAddress) + "-" + format("0x%04X", _maxAddress - 1));
  }

  return true;
}

This way you can call this function after calling the constructor as a check.


#6

What would be a great enhancement is making it SPI. There is better options with SPI FRAM and more cost effective. Any chance?


#7

Just ordered a couple of SPI breakouts to try.


#8

Spi would be nice as I believe it is a little more robust.


#9

Any Ideas on this issue?

writeByte(address, value)
Allows you to write a value from 0x00—0xFF to the FRAM. An 8bit uint, Great.

readByte(address)
Returns the unsigned 8-bit value located at address. The returned value is a single-character string.
Not good as there appears to be no way of converting the single-character string into an 8 bit int again.

Even using a blob with int type ‘b’ fails.

How do I retrieve the 8bit uint a value (from 0x00—0xFF) from the FRAM?


#10

Won’t readByte(address)[0] give you what you want?


#11

Indeed it does. Thank you very much.


#12

A pre-release update to the library can be found at our GitHub repo here, if you’d like to try it out. Resolves some of the issues raised above (eg. readByte returns an integer not a string) and includes a stack of refactoring and other fixes.

This is not available yet via #require so you’ll need to copy and paste it into your code for now.