I am using the HAL_I2C_Mem_Read
library to read a register value but the last bit (8th bit) in the slave address is always 0 no matter which slave address I put.
I use the Fuel Guage MAX17320 with a microcontroller STM32F105 to read and write to/from different register. The data sheet for MAX17320 https://www.analog.com/media/en/technical-documentation/data-sheets/MAX17320.pdf
I want to read the register nDeviceName (121h) with slave address 0x16 but get always ACK failer because the HAL_I2C_Mem_Read()
does not add 1 for the 8th bit which is needed for reading.
This is the code in STM32Cube IDE
HAL_StatusTypeDef MAX30205_readTemp(uint8_t dev_address)
{
HAL_StatusTypeDef ret;
uint64_t tempData[2];
// read from the register sDeviceName
ret = HAL_I2C_Mem_Read(&hi2c1, dev_address, 0x121, 2, tempData, 2, HAL_MAX_DELAY);
if(ret != HAL_OK)
{
return ret;
}
return HAL_OK;
}
this is how I call the function MAX30205_readTemp(uint8_t dev_address)
and send the slave address:
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
MAX30205_readTemp(0x16);
/* USER CODE END 3 */
}
Even if I do it like MAX30205_readTemp(0x16|0x01);
or MAX30205_readTemp(0x16<<1|0x01);
to make the last bit 1 for reading it will still be 0 and cause ACK failer.
I have also decoded the I2C bus with an oscilloscope and it shows clearly that the last 8th bit is 0 instead of 1 for reading.
this is the picture on the oscilloscope:
The picture below is to test for another slave address(0xD8)
I assume that something may be wrong in the configuration of I2C but do not know where and how to fix it. I use the STM32CubeIDE 1.10.1 version. It would be enormous help if someone knows how to fix it. Help Plz