M0 Feather and i2c FRAM

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ironman0917
 
Posts: 4
Joined: Wed Jun 26, 2013 11:53 pm

M0 Feather and i2c FRAM

Post by ironman0917 »

Hello,
I am relatively new to the Arduino community, and have successfully used the i2c FRAM units from Adafruit on a UNO and MEGA, but am experiencing problems with the M0 Feather. When i use the FRAM library, the serial monitor does not work and seems to not even make it to the void setup() section of the example. i did use the #define Serial SerialUSB line and this does work in my other sketches. when i uncomment the lines pertaining to the FRAM library (fram.begin(), etc.) and only leave the Serial commands, i then will get the serial monitor to work, but it just generally seems to fail when used with the library. If there is any help or assistance i would greatly appreciate it as (to my knowledge) the M0 feather does not have any EEPROM or other permanent memory. Thank you.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: M0 Feather and i2c FRAM

Post by adafruit_support_mike »

The Feather uses an ATmega32u4 microcontroller, which has 1k of built-in EEPROM.

The ATmega32u4 also handles USB communication internally, so you have to start the Serial interface a bit differently. Instead of just using Serial.begin(), you have to wait while the firmware for that interface gets up and running:

Code: Select all

    Serial.begin( 9600 );

    while ( ! Serial ) {
        delay( 1 );
    }
You also need to use different pins for the I2C connection than are listed in the FRAM example code. The Feather's I2C pins are #2 and #3 (marked SDA and SCL on the PCB).

User avatar
ironman0917
 
Posts: 4
Joined: Wed Jun 26, 2013 11:53 pm

Re: M0 Feather and i2c FRAM

Post by ironman0917 »

Thank you very much Mike. I will try this out when I get home this evening but wanted to clarify something as I see a potential flaw in your post (I say potential only because I think I understand what I am reading but will openly admit I may be wrong). I noticed in your post you are referencing the Feather using a ATmega32u4, but the Feather I am using is the M0 variant and I believe (from my reading) it uses the ATSAMD21. Just to add to my original post, I tried the M0 Feather with the 9 DOF board (https://www.adafruit.com/products/1714) with the "pitchrollheading" example and it worked without any issues on its i2c program. So just to summarize my own little tests for this post: i2c works on 9 DOF breakout but not on the i2c Fram breakout both using the M0 Feather. Also, I see your point on changing the pins on the FRAM from A4 & A5 (digital pins 18 & 19 on the uno) to the pins on the M0 Feather digital pins 20 & 21) but cannot find how/where to do this. Thank you once again Mike for your efforts and assistance. I greatly appreciate it.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: M0 Feather and i2c FRAM

Post by adafruit_support_mike »

You're right, I was thinking of the rest of the Feather line. Those are ATmega32u4 boards.

Let me check with some of the folks who are more familiar with the M0 version.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: M0 Feather and i2c FRAM

Post by adafruit_support_rick »

Let's see if we can get a little debug information out of the library

In Adafruit_FRAM_I2C.cpp, which is in the Adafruit_FRAM_I2C folder in your libraries folder, add three lines to redefine SerialUSB to Serial for the library:

Code: Select all

//#include <avr/pgmspace.h>
//#include <util/delay.h>
#include <stdlib.h>
#include <math.h>

//add these three lines to redefine Serial as SerialUSB on an M0 processor
#if defined(ARDUINO_ARCH_SAMD)
  #define Serial SerialUSB
#endif

#include "Adafruit_FRAM_I2C.h"

User avatar
adafruit2
 
Posts: 22148
Joined: Fri Mar 11, 2005 7:36 pm

Re: M0 Feather and i2c FRAM

Post by adafruit2 »

the M0 does 'fake' EEPROM by using a chunk of flash. we havent tested *all* libraries with the m0
in general we've noticed that yeah the Serial thing is annoying and need fixing
see also
https://learn.adafruit.com/adafruit-fea ... ches-to-m0
some effort may be required to 'port' libraries over, the core is very new!

User avatar
adafruit2
 
Posts: 22148
Joined: Fri Mar 11, 2005 7:36 pm

Re: M0 Feather and i2c FRAM

Post by adafruit2 »

K i just pushed a version that removes the Serial prints, plz redownload & try again!

User avatar
csundra
 
Posts: 6
Joined: Fri Jul 18, 2014 8:49 pm

Re: M0 Feather and i2c FRAM

Post by csundra »

Hi, Adafruit! I'm having the same issue with initialization using the FRAM with an Arduino Zero (SAMD21 M0+). The good news is that if you ignore the results of getDeviceID and set "_framInitialised" to true, the FRAM appears to read and write normally.

Here's what I've tracked down:

[*] The FRAM isn't returning the Manufacturer and Product ID. The *manufacturerID and *productID loaded by getDeviceID are all 1's.
[*] Looking at the bytes transmitted by getDeviceID on an oscilloscope, I'm seeing normal ACKS from the FRAM after it receives the first 2 write bytes (the slave ID and the I2C address).
[*] There's a stop bit, bus is briefly idle, then a start bit.
[*] The third byte is the slave ID (a read byte, ending in 1), but it's then NACKed by the FRAM. This causes the Zero to stop transmission, bus is IDLE.

Looking at the FRAM's datasheet, I think the problem is that there should be a repeated start between the write bytes and the read byte, not a full stop/start. I know this has been an on and off problem in the Arduino Wire library, but I'm using 1.6.6 and the release notes state there was a bug fix for AVR for repeated start conditions. Perhaps there is still a bug for ARM M0+?

I attached a scope pic. The last byte is the read, you'll see the stop/start condition between it and the previous byte.
IMG_7795.JPG
IMG_7795.JPG (479.68 KiB) Viewed 2940 times

User avatar
adafruit2
 
Posts: 22148
Joined: Fri Mar 11, 2005 7:36 pm

Re: M0 Feather and i2c FRAM

Post by adafruit2 »

yah this is a 'known bug' in the current core. there's a Pullreq but not merged in
https://github.com/arduino/ArduinoCore-samd/pull/66
meanwhile you can comment out the manufacturer/device id test

User avatar
csundra
 
Posts: 6
Joined: Fri Jul 18, 2014 8:49 pm

Re: M0 Feather and i2c FRAM

Post by csundra »

Cool, thanks for the quick response. Hopefully a fix will be pushed soon!

User avatar
jferguson75
 
Posts: 8
Joined: Wed Nov 13, 2013 5:15 pm

Re: M0 Feather and i2c FRAM

Post by jferguson75 »

Does anyone know of an update to this? I'm having the exact same problem as the original poster. I was wondering if there is a library update that I need or something.

Thanks.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: M0 Feather and i2c FRAM

Post by adafruit_support_rick »

That pull was merged back in January. You must be having a different problem. Can you describe it in detail, and post the code that demonstrates the problem?

User avatar
jferguson75
 
Posts: 8
Joined: Wed Nov 13, 2013 5:15 pm

Re: M0 Feather and i2c FRAM

Post by jferguson75 »

I was running the example script for the FRAM. It started working for me as I was working with it last night. One thing I changed was to enter in the fram address explicitly in the begin. I don't think that was the problem because it was the same address as the code defaulted to so it shouldn't have made a difference. I'm wondering if I wasn't getting a good connection on my breadboard. It may have just been from moving the wires a little giving it better contact.

What I find really strange is when it doesn't work, you get no serial outputs to the serial monitor at all. Even outputs written before fram.begin is called. It makes it very hard to debug.

I did notice that even when it started working, fram.begin was returning an error. I would get the output:

I2C FRAM not identified ... check your connections?
Will continue in case this processor doesn't support repeated start

Is this normal?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: M0 Feather and i2c FRAM

Post by adafruit_support_rick »

Add the following line before the Serial.begin:
while (!Serial);
This will make the M0 wait for the serial connection before proceeding.

fram.begin will return an error if the manufacturer ID or product ID are not what's expected. Can you make a small change to the library code to print out some debug information?
In FRAM_I2C.cpp, find the begin function and uncomment the Serial.print statements. Let's see what it's reading for those values:

Code: Select all

/**************************************************************************/
/*!
    Initializes I2C and configures the chip (call this function before
    doing anything else)
*/
/**************************************************************************/
boolean Adafruit_FRAM_I2C::begin(uint8_t addr) 
{
  i2c_addr = addr;
  Wire.begin();
  
  /* Make sure we're actually connected */
  uint16_t manufID, prodID;
  getDeviceID(&manufID, &prodID);
  if (manufID != 0x00A)
  {
    Serial.print("Unexpected Manufacturer ID: 0x");
    Serial.println(manufID, HEX);
    return false;
  }
  if (prodID != 0x510)
  {
    Serial.print("Unexpected Product ID: 0x");
    Serial.println(prodID, HEX);
    return false;
  }

  /* Everything seems to be properly initialised and connected */
  _framInitialised = true;

  return true;
}

User avatar
jferguson75
 
Posts: 8
Joined: Wed Nov 13, 2013 5:15 pm

Re: M0 Feather and i2c FRAM

Post by jferguson75 »

Thank you for the response. I'll post that later tonight.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”