Wire.requestFrom and constant error

Hi guys.

Seems that

Wire.requestFrom(0x77, 2)

only accepts a value (0x77 here), and not a constant I defined before

const uint8_t   MY_SENSOR_ADDRESS   = 0x77;

Why is it so? It's not very convenient this way and it seems that already seen this kind of param used before. Thanks!

Seems that … only accepts a value (0x77 here), and not a constant I defined before

Not true.

Why is it so?

It isn’t.

it seems that already seen this kind of param used before.

I’m sure that you have.

Thanks!

You’re welcome.

If you posted your code, I’m sure we could see what you are doing wrong.

yep!

First,

const uint8_t	BPM180_ADDRESS_SENSOR						= 0x77;

and then,

uint16_t BPM180_get_EEPROM_2bytes(uint8_t code){	
	uint16_t value;
	Wire.beginTransmission(BPM180_ADDRESS_SENSOR);
	Wire.write(code);
	Wire.endTransmission();
	Wire.requestFrom(0x77, 2);	//replace 0x77 by BPM180_ADDRESS_SENSOR? not working
	if(Wire.available() >= 2)
	{
	value = (Wire.read() << 8) | Wire.read();
	  }
	return value;
}

Here is the bug report in Eclipse

‘requestFrom’ is ambiguous ’ Candidates are: unsigned char requestFrom(int, int) unsigned
char requestFrom(unsigned char, unsigned char) ’

?? :slight_smile:

    Wire.requestFrom(0x77, 2);  //replace 0x77 by BPM180_ADDRESS_SENSOR? not working

"Not working" and "won't even compile" are two completely different things.

requestFrom' is ambiguous ' Candidates are: unsigned char requestFrom(int, int) unsigned
 char requestFrom(unsigned char, unsigned char) '

Your first argument is neither int or unsigned char. If you make the type of BPM180_ADDRESS_SENSOR one of those two, then the code with BPM180_ADDRESS_SENSOR in the call to requestFrom() will at least compile.

Sorry for not being any accurate in my terms!

Here is the function definition

uint8_t TwoWire::requestFrom(int address, int quantity)
{
  return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)true);
}

Altough it can take address param as int only, requestFrom accepts uint8_t as address. Not clear to me.

Not clear to me.

What isn't? The snippet you showed shows that the two argument version of requestFrom() takes an int, as the first argument, while the three argument version takes a uint8_t. If you want to call the two argument version, you need to supply an int as the first argument. If you want to call the version that takes a uint8_t, you need to supply three arguments. It ain't rocket science.

ok. get it.

is uint8_t and Unsigned Char the same?

Thanks PaulS

is uint8_t and Unsigned Char the same?

No, but on the Arduino they are equivalent.