Error: no matching function for call to 'INA3221::begin(ina3221_addr_t)'

Hello Forum!

I need your help.

I'm programming a stm32 family 103 and I would like to measure some loads on the output of three channels with a sensor the INA3221. However, I'm trying to make it communicate with the TCA9548A multiplexer with address 0x70 (AO -> GND) and the INA with address 0x40 (AO -> GND).

The program is showing error "no matching function for call to 'INA3221::begin(ina3221_addr_t)' ".

Can anyone help?

Below is the code with the error.

#include <SoftWire.h>
#include <INA3221.h>
#define muxI2C 0x70

SoftWire SWire(PB10, PB11, SOFT_FAST);

#define SERIAL_SPEED     115200  // serial baud rate
#define PRINT_DEC_POINTS 3       // decimal points to print

INA3221 ina_0(INA3221_ADDR40_GND);

void tcaselect(uint8_t i)
{
  if (i > 7) return;
  
  SWire.beginTransmission(muxI2C);
  SWire.write(1 << i);
  SWire.endTransmission();
}

void current_measure_init()
{
  ina_0.begin(INA3221_ADDR40_GND);
  ina_0.reset();
  ina_0.setShuntRes(10, 10, 10);
}

void setup()
{
  SWire.begin();
  Serial.begin(SERIAL_SPEED);
  Serial.println("\nTCA9548A Scanner ready!");
  current_measure_init();
  
  while (!Serial)
  {
    delay(1);
  }
}

void loop()
{
  for (uint8_t addr = 0; addr <= 127; addr++)
  {
    tcaselect(0);
    if (addr == muxI2C) continue;

    SWire.beginTransmission(addr);
    float current[3];
    float current_compensated[3];
    float voltage[3];

    current[0]             = ina_0.getCurrent(INA3221_CH1);
    current_compensated[0] = ina_0.getCurrentCompensated(INA3221_CH1);
    voltage[0]             = ina_0.getVoltage(INA3221_CH1);

    current[1]             = ina_0.getCurrent(INA3221_CH2);
    current_compensated[1] = ina_0.getCurrentCompensated(INA3221_CH2);
    voltage[1]             = ina_0.getVoltage(INA3221_CH2);

    current[2]             = ina_0.getCurrent(INA3221_CH3);
    current_compensated[2] = ina_0.getCurrentCompensated(INA3221_CH3);
    voltage[2]             = ina_0.getVoltage(INA3221_CH3);

    Serial.print("Channel 1: \n Current: ");
    Serial.print(current[0], PRINT_DEC_POINTS);
    Serial.print("A\n Compensated current: ");
    Serial.print(current_compensated[0], PRINT_DEC_POINTS);
    Serial.print("\n Voltage: ");
    Serial.print(voltage[0], PRINT_DEC_POINTS);
    Serial.println("V");

    Serial.print("Channel 2: \n Current: ");
    Serial.print(current[1], PRINT_DEC_POINTS);
    Serial.print("A\n Compensated current: ");
    Serial.print(current_compensated[1], PRINT_DEC_POINTS);
    Serial.print("\n Voltage: ");
    Serial.print(voltage[1], PRINT_DEC_POINTS);
    Serial.println("V");

    Serial.print("Channel 3: \n Current: ");
    Serial.print(current[2], PRINT_DEC_POINTS);
    Serial.print("A\n Compensated current: ");
    Serial.print(current_compensated[2], PRINT_DEC_POINTS);
    Serial.print("\n Voltage: ");
    Serial.print(voltage[2], PRINT_DEC_POINTS);
    Serial.println("V\n");

    delay(1000);
  }
  SWire.endTransmission();
}

I can't read those tiny amber letters. Please copy and post the entire error message as text.

C:\Users\User\Downloads\INA3221-main\INA3221-main\examples\get_started\get_started.ino: In function 'void current_measure_init()':
get_started:23:33: error: no matching function for call to 'INA3221::begin(ina3221_addr_t)'
   ina_0.begin(INA3221_ADDR40_GND);
                                 ^
C:\Users\User\Downloads\INA3221-main\INA3221-main\examples\get_started\get_started.ino:23:33: note: candidate is:
In file included from C:\Users\Jefferson\Downloads\INA3221-main\INA3221-main\examples\get_started\get_started.ino:2:0:
C:\Users\User\Documents\Arduino\libraries\INA3221-0.0.1\src/INA3221.h:164:10: note: void INA3221::begin(SoftWire*)
     void begin(SoftWire *SWire);
          ^
C:\Users\User\Documents\Arduino\libraries\INA3221-0.0.1\src/INA3221.h:164:10: note:   no known conversion for argument 1 from 'ina3221_addr_t' to 'SoftWire*'
exit status 1
no matching function for call to 'INA3221::begin(ina3221_addr_t)'

Did you check the library documentation and examples to see whether the begin() method actually exists?

Yes, I checked the documentation. I think the Arduino library Wire and the stm32 are different.

For example: #include <Wire.h> This is from Arduino
#include <SoftWire.h> This is from STM32

Are you using the STM official core? It implements Wire, if you are using SoftWire, that is a different thing (perhaps you can explain?).

I have maybe about 50 sketches that run on STM and use the Wire library with zero portability problems.

I have the Maple Mini board here and I need to understand how to read the slave data with the INA sensor

You have to dig into the libraries you're using to see how they invoke the Wire library.

You didn't give any feedback about why you used the "SoftWire" library, or what it is. I did ask you to explain in reply #6.

As for the understanding of the logic, I even understood it, the only question is how am I going to call the slave so that the multiplexer loads the data and sends it to the microcontroller and ends with the ACK.

What you are talking about, sounds like low level functions of the I2C interface, which are normally hidden from the view of the application program.

You can condense all that to "call the slave", which is done transparently by the Wire library.

It's not necessary to delve into small details of the I2C interface, to simply access some bus device.

In particular, in a working system, you should never have to, or want to know about the ACK.

The "SoftWire" library was the only one that I can direct within the library the pins that I will use in the microcontroller

Why do you need to use alternate pins? For one thing, the STM has two hardware I2C ports...

Because I followed the data sheet with the pin map from the manufacturer.

I don't follow... if you follow the data sheet it tells you which pins you can use for I2C. Then you don't need software I2C.

Do you understand the difference between hardware and software I2C implementations?

h4t

I follow this pins PB10 (SCL), PB11 (SDA).

Yes, those are hardware I2C pins, you can interface them with the Wire library.

I tried by software but no response

What do you mean "by software"?

Because there are two interfaces, not just one, there are additional steps that you have to make in order to make the second port work. Please consult the Wire library documentation and examples from the STM core.

Why do you need more than one I2C port, anyway??? I2C is "plug and play" with the usual Wire library functions, on the port 1 pins.

Consult any of the 1,000,000 user sketches that do that.

I want to say that the alternative of doing it through hardware communication without a Wire.h library, didn't work. However, I tested it with the "SoftWire.h" library and managed to locate the addresses through a scan.

View the image down.

h2rt2

Aha, so you only need one bus after all...

I want to say that the alternative of doing it through hardware communication without a Wire.h library, didn't work.

But you don't know why.

I see you are bound and determined to avoid a simple, common and reliable interface that thousands of people have used, right out of the box with no problems. Good luck with your project.