Which function used for read I2C device address?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-26 7:29 AM
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.
- Labels:
-
I2C
-
STM32H7 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-26 8:42 AM
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)
{
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-26 10:59 AM
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-26 10:00 PM
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");
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-26 10:03 PM
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");
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-26 10:50 PM
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-26 10:59 PM
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.​
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-26 11:05 PM
Then I am using the 46h address then for write purpose i have to use 46<<1 am i right
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-26 11:09 PM
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.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2021-11-26 11:12 PM
I can't understand what you told can you please exaplained me ,i am confused in this address.
