cancel
Showing results for 
Search instead for 
Did you mean: 

I have noticed that the HAL_I2C_Master_Transmit code is only sending write requests to even numbered addresses. A hardcoded address of 0x21 becomes 0x20 for instance.

AMcAf.1
Associate II

I am trying to use an STM32-p405 to communicate with another device via I2C. The device has a number of potential addresses so I am sending commands to all of them to see which respond back. It wasn't working, and then I discovered none of the odd numbered addresses were being called.

6 REPLIES 6

What do you mean by address?

In the I2C realm, there is a longstanding confusion between the 7-bit address, as defined by the I2C standard, and the 8-bit byte, which is transmitted, which, next to the address, includes the Read/Write bit as its LSB. And that, for Write, is zero.

JW

AMcAf.1
Associate II

The slave device has a data sheet with a list of addresses. One of those is 0x21. When I pass 0x21 into HAL_I2C_Master_Transmit what I pick up on the logic analyzer between my stm32 and the device is a request to transmit to 0x20 and no response. When I shift 0x21 left and pass 0x42 into HAL_I2C_Master_Transmit I pick up a request to transmit to 0x42 and no response.

> The slave device has a data sheet with a list of addresses.

Post link.

> what I pick up on the logic analyzer between my stm32 and the device

Show.

JW

Device's table of addresses:

0693W000008zKkNQAU.pngAttempt to send to address 0x42:

0693W000008zKkrQAE.pngAttempt to send to address 0x21:

0693W000008zKkXQAU.pngAttempt to send to address 0x20:

0693W000008zKk3QAE.png

> Device's table of addresses:

It says that these are 7-bit addresses and the doxygen header to HAL_I2C_Master_Transmit says that 7-bit addresses have to be left-shifted, so you have to use 0x21<<1 as parameter, which your LA incorrectly displays as 0x42 (many LA do so).

However, that table does not indicate that you have a *range* of addresses available from which you can pick one at will. Rather, it indicates that the device has one unique address, determined at its manufacturing time.

JW

AMcAf.1
Associate II

For the sake of thread resolution and anyone with similar issues: It turns out the address I needed to send to was 0x20 or 0100000 in 7bit binary. However this needed to be left shifted to 1000000 for the STM32 to send out. After that it worked. Thanks JW!