I2C communication issue when called from UART Command line
Hi There,
we have an IO Expender connected to I2C2, We read the GPIO using function "Read_IOExpendr2_Status();"
also, we have a UART connection for CLI
the function "Read_IOExpendr2_Status();" is at "Application.c" file
the CLI is at "COM_PORT.c" File
when the costumer send any UART message, a function is activated "void executeSerialCommand1(char *uart1RxBuf)"
inside that function there is a call for Read_IOExpendr2_Status();
CODE: (COM_PORT)
void executeSerialCommand1(char *uart1RxBuf)
{
Read_IOExpendr2_Status();
}
CODE: (MAIN)
void Read_IOExpendr2_Status(void)
{
uint8_t pRegAddress[2] = {INPUT_PORT0,INPUT_PORT1};
pcal9555_readRegister(&hi2c2, (uint16_t)PCAL9555_I2C_ADD_2, pRegAddress,USB_Link_Status );
}
Declaration of: pcal9555_readRegister
HAL_StatusTypeDef pcal9555_readRegister(I2C_HandleTypeDef *hi2c, uint16_t address, uint8_t *pRegAddress, uint8_t *pData);
Definition of: pcal9555_readRegister
HAL_StatusTypeDef pcal9555_readRegister(I2C_HandleTypeDef *hi2c, uint16_t address, uint8_t *pRegAddress, uint8_t *pData){
//Set the register address in the pointer register
HAL_Status = pcal9555_writeRegister(hi2c, address, pRegAddress, 1);
HAL_Status= HAL_I2C_Master_Receive_IT(hi2c, address, pData, 1);
while (HAL_I2C_GetState(hi2c) != HAL_I2C_STATE_READY){
/* Error_Handler() function is called when Timeout error occurs.
When Acknowledge failure occurs (Slave don't acknowledge its address)
Master restarts communication */
if ((HAL_I2C_GetError(hi2c) != HAL_I2C_ERROR_AF)&&(HAL_I2C_GetError(hi2c) != HAL_I2C_ERROR_NONE))
{
Error_Handler();
}
}
return HAL_Status;
}
the result is that the MCU send the IO Expender's address and then SDA and SCL lines set to '1' constant
from debugging, i can see that there is an issue with "pData"
HAL_Status = HAL_I2C_Master_Transmit_IT(hi2c,address, pData, Size);
when the function "Read_IOExpendr2_Status();" is called Outside of "void executeSerialCommand1(char *uart1RxBuf)" the value of pData is 0x200008F8
when the function "Read_IOExpendr2_Status();" is called Inside of "void executeSerialCommand1(char *uart1RxBuf)" the value of pData is 0x20000668
the Program enters a loop
while (HAL_I2C_GetState(hi2c) != HAL_I2C_STATE_READY)
MCU: STM32F072CBU6
any suggestions?
thank you
