11 years, 1 month ago.

unsigned char/char

// read a 16 bit register
int readIntRegister ( unsigned char adres)
{
unsigned char mlsb[2];
unsigned char msb, lsb;
i2c.write(addr, &adres, 1, 0);
i2c.read (addr, mlsb, 2, 0);
msb = mlsb[0];
lsb = mlsb[1];
return (((int)msb<<8) | ((int)lsb));
}

this gives "no instance of overloaded function "mbed::I2C::write" matches the argument list" in file "/main.cpp", Line: 30, Col: 34 for both i2c operations. if i delete the unsigned this works, why is that? thank you

2 Answers

6 years, 10 months ago.

Instead of using unsigned char mlsb, you can safely use char mlsb, because the compiler uses unsigned char for char type. I've tested it under mbed compiler. Read more at stackoverflow

11 years, 1 month ago.

I'm not a C++ expert, but I believe it's because your argument type, "unsigned char *", is different enough that it doesn't fit the compiler's expectations for the function's "signature." At least for the read() function, the compiler is looking for, "int read (int address, char *data, int length, bool repeated=false)" rather than "..., unsigned char *data, ...". Since there's no overloaded method that does specify "unsigned char *data", the compiler says it can't find a method that matches your specs.