Convert define to pointer argument in a function (I2C)

Hello, I am using this specific function to communicate with I2C, this function has the following format:

I2C_Master_Transmit (I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout)

As the third argument of this function is an address, it has no need of being a pointer to a variable stored in an address. I am trying to use a #define for the pData address but for obvious reasons it doesn't work because it is not a pointer. It does work for the second argument.

Is there some simple way to create a temporary pointer variable just to store the declaration of the address?

I want to to this:

I2C_Master_Transmit(&hi2c1, (BMP2_I2C_ADDR_SEC << 1), BMP2_REG_CHIP_ID, 1, 1000);

Insted of this: (because it seems redundant)

uint8_t chip_id = BMP2_REG_CHIP_ID;

I2C_Master_Transmit(&hi2c1, (BMP2_I2C_ADDR_SEC << 1), &chip_id, 1, 1000);

No, you have to use a pointer.
The argument wants a pointer and a pointer has to point to something.

Which Arduino board do you use ? Is this a Mbed function ?

The argument wants a pointer and a pointer has to point to something.

That's my question, can I create a temporary variable inside the argument to store the #define value?

Is this a Mbed function ?

yes

As I wrote before, the answer is "no".
Suppose there is something to create a temporary variable on the stack and the parameter is a pointer to that variable. But that is exactly what you are doing when you declare the 'chip_id' variable. There is no automatic or magic trick for it.

A #define is a text replacement, nothing more, nothing less. A variable can store data, a pointer is a variable that holds an address and a function has parameters. They are all totally different things. You have to glue them together with code.

In the 'C' and 'C++' language, you have to tell the compiler what to do. The compiler does not generate code based on your intentions.

It is not so bad after all, is it ? It is just normal code for the 'C' and 'C++' language.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.