cancel
Showing results for 
Search instead for 
Did you mean: 

Which function used for read I2C device address?

MDeva.1
Associate II

Hello,

I am working on NUCLEO-H745ZIQ board. I am interfacing PCAL6524 to board .I have to read the Device address of that IC. Which HAL function that I have to used? I am get confused.

11 REPLIES 11
TDK
Guru

HAL_I2C_Mem_Read should get you there.

/**
  * @brief  Read an amount of data in blocking mode from a specific memory address
  * @param  hi2c Pointer to a I2C_HandleTypeDef structure that contains
  *                the configuration information for the specified I2C.
  * @param  DevAddress Target device address: The device 7 bits address value
  *         in datasheet must be shifted to the left before calling the interface
  * @param  MemAddress Internal memory address
  * @param  MemAddSize Size of internal memory address
  * @param  pData Pointer to data buffer
  * @param  Size Amount of data to be sent
  * @param  Timeout Timeout duration
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_I2C_Mem_Read(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout)
{

If you feel a post has answered your question, please click "Accept as Solution".
TDK
Guru

Maybe you mean the slave address. That is something that is set by hardware and should be known, rather than something the STM32 needs to read.

You can, however, poll all 128 possible slave addresses from 0x00 to 0x7F with HAL_I2C_IsDeviceReady() to see which one it responds to, but this is not typically done.

0693W00000GZ6WqQAL.png 

The first step to getting I2C to work is to use HAL_I2C_IsDeviceReady() with the appropriate slave address and ensure it returns HAL_OK.

If you feel a post has answered your question, please click "Accept as Solution".

I craete this function for to check device is ready or not can you tell me this is right or wrong?

void PCAL6254SETUP(void)

{

uint8_t Device_Address;

Device_Address = (PCAL6524_ADDRESS_3 << 1);

if(HAL_I2C_IsDeviceReady(&hi2c3, Device_Address, 2, 10000)!=HAL_OK)

{

printf("Device Not Ready\n\r");

}

}

I craete this function for to check device is ready or not can you tell me this is right or wrong?

void PCAL6254SETUP(void)

{

uint8_t Device_Address;

Device_Address = (PCAL6524_ADDRESS_3 << 1);

if(HAL_I2C_IsDeviceReady(&hi2c3, Device_Address, 2, 10000)!=HAL_OK)

{

printf("Device Not Ready\n\r");

}

}

Hello,

why we need shift device address? whats its purpose?

tx_buff = (dev->addr << 1);

if (HAL_I2C_Mem_Write(dev->i2c, tx_buff, addr, 1, &value, 1, 10000) == HAL_OK)

return false;

I2C slave addresses are 7-bit, but on the wire those are the upper 7-bits within the byte, the least significant bit of the byte indicates whether it is a read or write interaction.​

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

Then I am using the 46h address then for write purpose i have to use 46<<1 am i right

The 0x48 value looks to have already been shifted. If you are shifting use address 0x24 instead.

D​ifferent chip vendors and software drivers manage this differently, so you should establish the bit mapping described in the datasheet vs the software side expectations. It requires some attention to the details.

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

I can't understand what you told can you please exaplained me ,i am confused in this address.