cancel
Showing results for 
Search instead for 
Did you mean: 

scope question on variable wrt I2C ??

SWenn.1
Senior III

I have the following two wrapper functions:

void POT_Load_Value(uint16_t value)
{
	uint8_t w[2];
	w[0] = 0; //reg
	w[1] = value;
	I2C_Write(POT_ADDR, w, 2);
}
 
uint8_t I2C_Write(uint8_t device, uint8_t *pValues, uint8_t size)
{
	if (HAL_OK == HAL_I2C_Master_Transmit_IT(&hi2c1, device, pValues, size))
		return I2C_SUCCESS;
	else
		return I2C_ERR;
}

I am using a simple callback:

void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c)
{
	if (hi2c == &hi2c1)
		ISR.I2C_dacTxComplete;
}

I am not sure how the I2C works on this device which brings me to the question:

The calling function POT_Load_Value variable w. Do I have to worry about scope being lost here between the transmission of the first byte and then the second? Should I be using static here?

1 REPLY 1

Yes, scope collapses immediately.

Static if you serialize operation so it won't reenter.

Allocate dynamically ​for a more general approach.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..