2023-07-24 09:00 AM
Hi
I am using HAl_I2C_Mem_Read library to read data from a register. But the HAl-I2C_Mem_Read does not add the LSb bit for read bit. For example if the device adress is 0x6C, the 8th bit shout be 1 for reading but it is 0 and I get an Ack failer. Even if I do like 0x6C|0x01 to make the 8th bit 1 for reading it still is 0 and I get ACK failer.
Hope that anyone can help with this.
This is the code.
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;
}
Here I call the function MAX30205_readTemp(uint8_t dev_address) and send the device address:
Solved! Go to Solution.
2023-07-24 09:09 AM - edited 2023-07-24 09:12 AM
Cause it's WRITING the memory/register address FIRST...
ret = HAL_I2C_Mem_Read(&hi2c1, dev_address, 0x121, 2, tempData, 2, HAL_MAX_DELAY);
The SLAVE address is not 0x16 or 0x6C, and the REGISTER address is 8-bit wide.. Would strongly suggest reading some data sheets.. It's not responding because you're addressing it entirely incorrectly.
https://www.analog.com/media/en/technical-documentation/data-sheets/MAX30205.pdf
2023-07-24 09:09 AM - edited 2023-07-24 09:12 AM
Cause it's WRITING the memory/register address FIRST...
ret = HAL_I2C_Mem_Read(&hi2c1, dev_address, 0x121, 2, tempData, 2, HAL_MAX_DELAY);
The SLAVE address is not 0x16 or 0x6C, and the REGISTER address is 8-bit wide.. Would strongly suggest reading some data sheets.. It's not responding because you're addressing it entirely incorrectly.
https://www.analog.com/media/en/technical-documentation/data-sheets/MAX30205.pdf
2023-07-25 02:57 AM
Hi
Thank you for your hint. Could you be more precise why I addressing it entirely incorrectly? The data sheet says that it should first write slave address, then memory address and then the read slave address. I thought the function ret = HAL_I2C_Mem_Read(&hi2c1, dev_address, 0x121, 2, tempData, 2, HAL_MAX_DELAY); do the writing and reading for me.
2023-07-25 09:00 AM - edited 2023-07-25 09:00 AM
Ok, cite your sources.. You're clearly looking a different documentation than I am.
Diagram how you have the parts wired up, it will impact the SLAVE ADDRESS. The default strapping presumably dev_address = 0x90; You are using a MAX30205 right? Not something else? If the address is wrong the slave won't ACK, it's how you determine a part is present and responding.
The Memory address is 8-bits wide (1-Byte), not 16-bit (2-Byte)
Surely the rational interpretation for the example diagram (2nd line) would be
uint8_t tempData[4]; // 4 consecutive bytes read
ret = HAL_I2C_Mem_Read(&hi2c1, dev_address, 0x1C, 1, tempData, sizeof(tempData), HAL_MAX_DELAY);
2023-07-26 02:40 AM
Hi Sir!
Sorry for being inconvenient, I am using MAX17320 not MAX30205. this is the link for the IC I use: https://www.analog.com/media/en/technical-documentation/data-sheets/MAX17320.pdf
So I try to read the register value DevName register (021h) with slave address 0x6C and I write the function
uint8_t tempData[4]; // 4 consecutive bytes read ret = HAL_I2C_Mem_Read(&hi2c1, dev_address, 0x1C, 1, tempData, sizeof(tempData), HAL_MAX_DELAY);
This is a screenshot from the datasheet for the register DevName(o21h)
Suppose the slave address (0x6C) is correct, is it correct that to read from a register we write the
uint8_t tempData[2];
HAL_I2C_Mem_Read(&hi2c, 0x6C, 0x21, 1, tempData, sizeof(tempData), HAL_MAX_DELAY); or do we need to write the HAL_I2C_Mem_Write(....) function before the HAL_I2C_Mem_Read(...) function because we want to first write the register address to the chip?
2023-07-26 05:47 AM
HAL_I2C_Mem_Read() is a compound function, see library source, it writes the internal address as the first step, and then in a second step it reads the content.
The MAX17320 uses 8-bit addressing, and I2C and SMB, with a different I2C Slave Address depending on the subset of registers being used 0x6C for 0x00..0xFF, and 0x16 for 0x180..0x1FF (0x80..0xFF)
Register 0x0121 looks like it would need to be SMB protocol, not I2C