2024-05-12 12:27 AM
Hi everyone, I am kinda new at Embedded programming and I wanna ask a question.
I am working on a library development of ADXL345 sensor and when I read the datasheet of this sensor here is the information that I got:
"An alternate I2C address of 0x53 (followed by the R/W bit) can be chosen by grounding the SDO/ALT ADDRESS pin (Pin 12). This translates to 0xA6 for a write and 0xA7 for a read."
This means I2C address of ADXL345 is = 0x53 HEX and "0101 0011" Binary.
after 1 bit left shift and write address is = 0xA6 HEX and "1010 0110" Binary.
after add 1 bit to the shift address is = 0xA7 HEX and "010 0110" Binary.
When I run this code block in STM32 :
I got the A6 write address instead of 0x53 I2C address. Do you know why ?
I got an opinion but I am not sure. When I read the brief of HAL_I2C_IsDeviceReady() function it says:
"@brief Checks if target device is ready for communication."
so its mean " I am trying to write something and checking for knowing can I write or not ?" so it returns the write address because it can only write something in write address right or not ?
Thanks.
Solved! Go to Solution.
2024-05-13 07:59 AM
Hello @testbenchmark and welcome to the community !
The HAL_I2C_IsDeviceReady() function is indeed used to check if a device is ready for communication on the I2C bus. This function typically requires the I2C address in the format where the least significant bit (LSB) indicates whether it's a read (1) or write (0) operation. Since the function is checking for device readiness to communicate, it expects the write address.
Here's a breakdown of why you're seeing the address 0xA6:
The code you've written scans through all possible addresses and uses the HAL_I2C_IsDeviceReady() function to check if a device is ready at that address. When it finds a device ready at address 0xA6, it means that the ADXL345 is responding to its write address.
Note that when using the HAL_I2C_IsDeviceReady() function, you must shift the 7-bit address of the device, as specified in the driver, one bit to the left before passing it as a parameter to the function.
2024-05-13 07:59 AM
Hello @testbenchmark and welcome to the community !
The HAL_I2C_IsDeviceReady() function is indeed used to check if a device is ready for communication on the I2C bus. This function typically requires the I2C address in the format where the least significant bit (LSB) indicates whether it's a read (1) or write (0) operation. Since the function is checking for device readiness to communicate, it expects the write address.
Here's a breakdown of why you're seeing the address 0xA6:
The code you've written scans through all possible addresses and uses the HAL_I2C_IsDeviceReady() function to check if a device is ready at that address. When it finds a device ready at address 0xA6, it means that the ADXL345 is responding to its write address.
Note that when using the HAL_I2C_IsDeviceReady() function, you must shift the 7-bit address of the device, as specified in the driver, one bit to the left before passing it as a parameter to the function.
2024-05-20 09:03 AM
Thank you so much for your help OSAKE.1 .