cancel
Showing results for 
Search instead for 
Did you mean: 

I2C found the wrong address (Actually 1 shifter version)

SKAŞ.1
Associate II

Hello Folks,

I was doing my I2C example, and I realize that the STM board found an address with one left-shifted.

I set my Arduino address as 70 -> 0x46 for hexadecimal

void setup()
{
  Wire.begin(0x46); // Wire communication begin
}

I connect my STM32F429I_DISC1 and finally make it work with the IsDeviceReady function.

It returns as 0-1-130-131 (I don't know why but not relevant.) and then it finds 140 and 141

When I check my binaries,

70 -> 0100 1100

140 -> 1000 1100

141 -> 1000 1101

when I left shift 70 with 1 bit, I got 140, I have no idea why I am getting 141 (last bit not important maybe?)

So I'm just curious about why it's happening?

I supply my project in here, I didn't add any additional library or so,

I just use CubeMX and CubeIDE (Not even Keil uVision 5)

But since, I am capable of doing I2C communication happen (even with shifted addresses), I want to look forward to complex examples.

Now, what should I send to my slave Arduino, 70 or 140?

Also when I make a scan at Arduino, it gives some I2C addresses, I am not sure which one belongs to my STM32.

0693W00000D0pIDQAZ.jpg 

There is only STM32 and Arduino connection with SDA and SCL, they have additional 4.7k pull-up resistor connected to 5V output of STM32, and ground of STM and Arduino connected.

Thanks for your attention,

Kind Regards.

1 ACCEPTED SOLUTION

Accepted Solutions
Mike_ST
ST Employee

Hello,

>> So I'm just curious about why it's happening?

I2C Addresses are 7 bits + 1 bit for R/W => 8bits address

Write => bit 0 =0

Read => bit 0 =1

>> Now, what should I send to my slave Arduino, 70 or 140?

HAL layer will expect a 7 bits address shifted 1 bit left, so, 140 in your case.

Depending of what operation you are doing, read or write, the HAL functions will take care of the bit 0.

View solution in original post

3 REPLIES 3
Pavel A.
Evangelist III

> When I check my binaries,

> 70 -> 0100 1100

Nope. 0100 0110.

> I got 140, I have no idea why I am getting 141 (last bit not important maybe?)

This is actually an important reminder to refresh the basics of I2C protocol :)

The LSB of the address set means read request. If this bit is 0 it means a write request.

If the device supports both reads and writes it will respond to both addresses.

> Now, what should I send to my slave Arduino, 70 or 140?

140. Or 141.

-- pa

Mike_ST
ST Employee

Hello,

>> So I'm just curious about why it's happening?

I2C Addresses are 7 bits + 1 bit for R/W => 8bits address

Write => bit 0 =0

Read => bit 0 =1

>> Now, what should I send to my slave Arduino, 70 or 140?

HAL layer will expect a 7 bits address shifted 1 bit left, so, 140 in your case.

Depending of what operation you are doing, read or write, the HAL functions will take care of the bit 0.

SKAŞ.1
Associate II

Thanks for your response people,

Yes I got it. As you guys mention, it's essential part of I2C protocol. Respectively that is my first time I really use these things. Also thanks for your support. I totally understand the I2C examples. I saw your message too late, but at least I saw it. I complete my examples on this one now, I am going to use UART and then SPI. I am gonna open a new topic if I need. THANKS AGAIN!