Go Down

Topic: MB85RS64V FRAM connections to DUE (Read 1 time) previous topic - next topic

mlucas

Hello All,

Not sure if this is the right Forum for this question, but it is about a DUE, so here goes...

I have a MB85RS64V FRAM) from Adafruit I would like to connect to my Due.

There is a wiring diagram for the UNO (nod DUE) here.

A summary of the pin connection for the UNO is:

You can easily wire this breakout to any microcontroller, we'll be using an Arduino

• Connect Vcc to the power supply, 3V or 5V is fine. Use the same voltage that the microcontroller logic is based off of. For most Arduinos, that is 5V
•Connect GND to common power/data ground
•Connect the SCK pin to the SPI clock pin on your Arduino. We'll be using Digital #13 which is also the hardware SPI pin on an Uno
•Connect the MISO pin to the SPI MISO pin on your Arduino. We'll be using Digital #12 which is also the hardware SPI pin on an Uno.
•Connect the MOSI pin to the SPI MOSI pin on your Arduino. We'll be using Digital #11 which is also the hardware SPI pin on an Uno.
•Connect the CS pin to the SPI CS pin on your Arduino. We'll be using Digital #10 but any pin can be used later


On the DUE, it looks like the SPI connector is in the middle of the board close to the CPU chip, correct?
So that means I want to connect the MISO, MOSI, SCK and power there, right?
It looks like the SPI CP pin is D10. 

Is that correct? 

I'm already using SCL1 and SDA1 for a RTC module.  The SDA1 pin is also labelled as SCK0.  If I need to use that pin for the FRAM as well, can both modules share the connection?

Thanks,
Michael

ard_newbie

On the DUE, it looks like the SPI connector is in the middle of the board close to the CPU chip, correct?
So that means I want to connect the MISO, MOSI, SCK and power there, right?

Yes . The CS pin can be 4(SPI CS1), 10(SPI CS0) or 52(SPI CS2).

The SDA1 pin is also labelled as SCK0.  If I need to use that pin for the FRAM as well, can both modules share the connection?


No. It is written (see Greynomad pinout diagram): SCK0 allows Serial1 to be used for SPI, because USART0(Serial1) and USART1(Serial2) can be programmed in SPI mode, but they don't use SPI pins of the SPI connector.

mlucas


mlucas

Connected FRAM now works and I can read/write using the Adafruit_FRAM_SPI library and example provided by Adafruit.

Thanks for the help ard_newbie!

I would like to read/write a double which is the same as a float, however, on the Due, doubles have 8 - byte (64 bit) precision.

I'm converting the double to a byte array using a union:

Code: [Select]

union EngineRunMs {
double m_double;
uint8_t  m_bytes[sizeof(double)];
};

double       runSeconds;
uint8_t      bytes[sizeof(double)];
EngineRunMs  myEngineRunMs;




In my function to write the bytes to the FRAM, I use a loop to write the values:

Code: [Select]

// convert double to bytes
*(double*)(bytes) = runSeconds;

// assign a double to union
myEngineRunMs.m_double = runSeconds;


fram.writeEnable(true);

for (int i = 0; i < sizeof(double); i++)
{
fram.write8(framAddrEngRunMs + i, myEngineRunMs.m_bytes[i]);
}

fram.writeEnable(false);


There has to be a better way to write the bytes without using a loop, right?

ard_newbie

#4
May 12, 2018, 06:49 am Last Edit: May 12, 2018, 11:19 am by ard_newbie
The Adafruit library has this function when you want to write several bytes:

fram.write (uint32_t addr, const uint8_t *values, size_t count);

Since your double values are positive values, something like this code should work( Note that printf and Serial.print can sometimes give weird ressults when you print 64-bit values, depending on the compiler version your are using...):

Code: [Select]

double var0 = 65432.123456789, varfinal;
uint64_t var1;
uint8_t Array[8];

void setup() {
  Serial.begin(250000);
}

void loop() {

  var1 = (uint64_t)(var0 * 1000000000);
  printf("\n %lld\n", var1);
  printf(" 0x%llX\n", var1);

  Serial.print(" 0x");
  *(uint64_t*)&Array[0] = var1;
  for (int i = 0; i < 8; i++) {
    Serial.print(Array[i], HEX);
  }
  // Write 8 bytes of Array in FRAM
  // fram.write(...);

  // Read 8 bytes of Array in FRAM
  // fram.read(...);
  *(uint64_t*)&var1 = *(uint64_t*)&Array[0];

  Serial.println("    ");
  printf("\n 0x%llX\n", var1);
  varfinal = (double)(var1 / 1000000000.0);

  Serial.print(" "); Serial.println(varfinal, 9);
  if (var0 == varfinal) {
    Serial.println(" OK ");
  }
  else {
    Serial.println(" Not OK ");
  }
  while (1);

}






BTW, runSeconds should be an uint64_t , not a double !!

mlucas

Thank you again ard_newbie!

Michael

Xirimiri

Dear Sirs;


I have one Adafruit SPI Non-Volatile like this:  https://www.mouser.es/ProductDetail/Adafruit/1897?qs=%2Fha2pyFaduggLwrL12g9PfakPkXfQUUjxIBvbu8idJc%3D

and I want to use it with an Arduino Due.

I would like to test and understand the operation of the FRAM with the Arduino Due.

For this, I want to use the example of the library of the Arduino IDE platform.
I want to use the sample program called FRAMInfo.ino

    https://github.com/adafruit/Adafruit_FRAM_SPI/blob/master/examples/FRAMInfo/FRAMInfo.ino

To do this, the FRAM I should connect it to the Arduino Due using the SPI connection and then load the example sketch into the Arduino Due.


Once this is done, I would like to do tests with it and be able to understand how it works.

But I do not know how to do it, I can not find any help reference.

I only have this one here:
https://learn.adafruit.com/adafruit-spi-fram-breakout/wiring-and-test

I would appreciate your help.

I want to know how to do tests with that example sketch mentioned.
Using that example sketch, if it works on the Arduino Due.

ard_newbie

#7
Apr 04, 2019, 08:43 am Last Edit: Apr 04, 2019, 08:45 am by ard_newbie
Power the FRAM breakout board with 3.3V, and use the DUE SPI connector (Don't use the 5V of the SPI connector !).

From Tronixmaker web site:


See Graynomad pinout diagram for more details.

Go Up