Coder Social home page Coder Social logo

Comments (13)

RobTillaart avatar RobTillaart commented on August 17, 2024

Thanks for the issue, if time permits I will try to investigate this weekend.

from fram_i2c.

Hans1972 avatar Hans1972 commented on August 17, 2024

Thanks, enjoy your weekend!

from fram_i2c.

RobTillaart avatar RobTillaart commented on August 17, 2024

At least one problem is in this line

if (!fram.begin(0x50, &I2CFRAM)) {

as there exist no begin function with these parameter type. So think that explains it.

I've written a minimal sketch based on your snippet. Can you give it a try?

#include "Arduino.h"
#include "FRAM.h"

#define I2C_SDA              21
#define I2C_SCL              22

// FRAM Memory
#define I2C_SDA_2            16
#define I2C_SCL_2            17

#define I2C_Freq            100000

// I2C1
TwoWire I2CPower = TwoWire(0);

// I2C2 for FRAM sensor
TwoWire I2CFRAM = TwoWire(1);
FRAM fram(&I2CFRAM);              //  <<<<<<<<<<<<<<<<<<<<<<<


void setup()
{
  Serial.begin(115200);
  Serial.print("FRAM_LIB_VERSION: ");
  Serial.println(FRAM_LIB_VERSION);

  // Start I2C communication
  I2CPower.begin(I2C_SDA, I2C_SCL, I2C_Freq);
  I2CFRAM.begin(I2C_SDA_2, I2C_SCL_2, I2C_Freq);

  // You might need to change the FRAM I2C address, in our case it's 0x50
  if (!fram.begin(0x50))         //  <<<<<<<<<<<<<<<<<<<<<<<
  {
    Serial.println("Could not find a valid FRAM sensor, check wiring!");
    while (1);
  }
  
  Serial.print("ManufacturerID: ");
  Serial.println(fram.getManufacturerID());
  Serial.print("     ProductID: ");
  Serial.println(fram.getProductID());
  Serial.print("     memory KB: ");
  Serial.println(fram.getSize());
}

void loop()
{
}


// -- END OF FILE --

Should print something like

ManufacturerID: 10
     ProductID: 1296
   memory size: 32

from fram_i2c.

RobTillaart avatar RobTillaart commented on August 17, 2024

FYI, I created a develop branch which fixes another issue - no relation to yours -

from fram_i2c.

Hans1972 avatar Hans1972 commented on August 17, 2024

Thanks, I tried to upload this sketch but its hanging on: I2CFRAM.begin(I2C_SDA_2, I2C_SCL_2, I2C_Freq);

Gives me the next errors:

C:\Users\..\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\libraries\Wire\src/Wire.h:79:10: note: candidate: 'bool TwoWire::begin(int, int, uint32_t)'
     bool begin(int sda=-1, int scl=-1, uint32_t frequency=0); // returns true, if successful init of i2c bus
          ^~~~~
C:\Users\..\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.4\libraries\Wire\src/Wire.h:80:10: note: candidate: 'bool TwoWire::begin(uint8_t, int, int, uint32_t)'
     bool begin(uint8_t slaveAddr, int sda=-1, int scl=-1, uint32_t frequency=0);
          ^~~~~
exit status 1
call of overloaded 'begin(int, int, int)' is ambiguous

from fram_i2c.

RobTillaart avatar RobTillaart commented on August 17, 2024

I2CFRAM.begin(I2C_SDA_2, I2C_SCL_2, I2C_Freq); is outside the library context, but still.

What is happening is that the compiler cannot decide which of the two versions of the begin() function to use.
What the compiler is missing is type information of the parameters. #define does not make the type explicit.
So better use const int or const uint32_t (32 bits unsigned integer) to give the compiler the info it needs.

Try this.

#include "Arduino.h"
#include "FRAM.h"

const int I2C_SDA = 21;
const int I2C_SCL = 22;

// FRAM Memory
const int I2C_SDA_2 = 16;
const int I2C_SCL_2 = 17;

const uint32_t I2C_Freq = 100000;

// I2C1
TwoWire I2CPower = TwoWire(0);

// I2C2 for FRAM sensor
TwoWire I2CFRAM = TwoWire(1);
FRAM fram(&I2CFRAM);              //  <<<<<<<<<<<<<<<<<<<<<<<


void setup()
{
  Serial.begin(115200);
  Serial.print("FRAM_LIB_VERSION: ");
  Serial.println(FRAM_LIB_VERSION);

  // Start I2C communication
  I2CPower.begin(I2C_SDA, I2C_SCL, I2C_Freq);
  I2CFRAM.begin(I2C_SDA_2, I2C_SCL_2, I2C_Freq);

  // You might need to change the FRAM I2C address, in our case it's 0x50
  if (!fram.begin(0x50))         //  <<<<<<<<<<<<<<<<<<<<<<<
  {
    Serial.println("Could not find a valid FRAM sensor, check wiring!");
    while (1);
  }
  
  Serial.print("ManufacturerID: ");
  Serial.println(fram.getManufacturerID());
  Serial.print("     ProductID: ");
  Serial.println(fram.getProductID());
  Serial.print("     memory KB: ");
  Serial.println(fram.getSize());
}

void loop()
{
}


// -- END OF FILE --

Note: you can use markdown syntax to enhance your posts - see https://www.markdownguide.org/cheat-sheet/

(having a lunch now, back later this afternoon)

from fram_i2c.

Hans1972 avatar Hans1972 commented on August 17, 2024

Now it compiled, and give me the next message in the serial monitor:

FRAM_LIB_VERSION: 0.4.0
Could not find a valid FRAM sensor, check wiring!

That seems strange to me, the first line gives the version number, so it looks that the FRAM memory is responding.
But it stops at the second line, the adres of the fram module is right, I tried your example files and that worked correctly.

By the way, thanks for your time!

from fram_i2c.

RobTillaart avatar RobTillaart commented on August 17, 2024

The first line only shows the version of the library.
It is the second line or so after setup()

Unfortunately I have no FRAM module nearby to replicate your hardware setup, but OK.

  • the examples work
    • fram = ok
    • wiring is ok
    • address is correct

Lets check what the function begin() returns

Can you try

#include "Arduino.h"
#include "FRAM.h"

const int I2C_SDA = 21;
const int I2C_SCL = 22;

// FRAM Memory
const int I2C_SDA_2 = 16;
const int I2C_SCL_2 = 17;

const uint32_t I2C_Freq = 100000;

// I2C1
TwoWire I2CPower = TwoWire(0);

// I2C2 for FRAM sensor
TwoWire I2CFRAM = TwoWire(1);
FRAM fram(&I2CFRAM);              //  <<<<<<<<<<<<<<<<<<<<<<<


void setup()
{
  Serial.begin(115200);
  Serial.print("FRAM_LIB_VERSION: ");
  Serial.println(FRAM_LIB_VERSION);

  // Start I2C communication
  I2CPower.begin(I2C_SDA, I2C_SCL, I2C_Freq);
  I2CFRAM.begin(I2C_SDA_2, I2C_SCL_2, I2C_Freq);

  // You might need to change the FRAM I2C address, in our case it's 0x50
  int x = fram.begin(0x50);
  Serial.println(x, HEX);
  
  Serial.print("ManufacturerID: ");
  Serial.println(fram.getManufacturerID());
  Serial.print("     ProductID: ");
  Serial.println(fram.getProductID());
  Serial.print("     memory KB: ");
  Serial.println(fram.getSize());
}

void loop()
{
}

from fram_i2c.

RobTillaart avatar RobTillaart commented on August 17, 2024

As the examples all work with the 1st I2C bus, it does not tell anything yet about the 2nd I2C bus.

  • are you sure that SDA and SCL are correct - not swapped?

Lets try to check if the pins 16 and 17 work for "Wire0"

#include "Arduino.h"
#include "FRAM.h"

// FRAM Memory
const int I2C_SDA_2 = 16;
const int I2C_SCL_2 = 17;

const uint32_t I2C_Freq = 100000;

TwoWire I2CFRAM = TwoWire(0);
FRAM fram(&I2CFRAM);  


void setup()
{
  Serial.begin(115200);
  Serial.print("FRAM_LIB_VERSION: ");
  Serial.println(FRAM_LIB_VERSION);

  // Start I2C communication
  I2CFRAM.begin(I2C_SDA_2, I2C_SCL_2, I2C_Freq);

  // You might need to change the FRAM I2C address, in our case it's 0x50
  int x = fram.begin(0x50);
  Serial.println(x, HEX);
  
  Serial.print("ManufacturerID: ");
  Serial.println(fram.getManufacturerID());
  Serial.print("     ProductID: ");
  Serial.println(fram.getProductID());
  Serial.print("     memory KB: ");
  Serial.println(fram.getSize());
}

void loop()
{
}

from fram_i2c.

RobTillaart avatar RobTillaart commented on August 17, 2024

Backgrounder: https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/

from fram_i2c.

Hans1972 avatar Hans1972 commented on August 17, 2024

Thanks, the last code works! I've read the (backgrounder) link above and tried to figure it out myself with that information before I asked here. I complemented the code in my final code and it works correctly.

from fram_i2c.

RobTillaart avatar RobTillaart commented on August 17, 2024

the last code works!

OK, means the pins work.

I complemented the code in my final code and it works correctly.

So you use only one I2C bus, OK
If your problem is solved, you may close the issue.

from fram_i2c.

Hans1972 avatar Hans1972 commented on August 17, 2024

I use now two I2C, the first part allready worked, I replaced the code:

// You might need to change the FRAM I2C address, in our case it's 0x50
if (!fram.begin(0x50)) // <<<<<<<<<<<<<<<<<<<<<<<
{
Serial.println("Could not find a valid FRAM sensor, check wiring!");
while (1);
}

by

// You might need to change the FRAM I2C address, in our case it's 0x50
int x = fram.begin(0x50);
Serial.println(x, HEX);

from fram_i2c.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.