cancel
Showing results for 
Search instead for 
Did you mean: 

I2C DevAddress incorrect

benny
Associate II
Posted on June 26, 2017 at 16:03

Hey,

I have a problem with the I2C1 on the STM32F746G-Discovery.

I'm using the example-code for communication with DMA, but I changed the address mode from 10bit to 7bit.

Now it's getting strange. The ST-Board is the master and a TCA6424A port expander is the slave. According to the datasheet the device address is 010 0010b (=22h; my ADDR pin is connected to GND).

But if I use the function HAL_I2C_Master_Transmit_DMA() and watch the output with an oszilloscope, the device address changed from 22h to 11h (010 0010b -> 001 0001b). I don't know why, but the library adds an extra zero in front of the device address. I can workaround it, if I use 44h as an address (100 0100b). With 44h the output is 22h.

Did I miss something or is there a bug in the code? How can I disable the additional zero in front of the device address?

Kind regards

Nyix

1 ACCEPTED SOLUTION

Accepted Solutions
Posted on June 26, 2017 at 17:19

>>

Did I miss something or is there a bug in the code? How can I disable the additional zero in front of the device address?

Some implementations shift the address and some don't. ST's doesn't so you must left align the address in the high order 7 bits. The low order bit is determined based on it being a read (receive) or write (transmit) transaction

It is a matter of understanding the data sheet for the I2C part to get the address (and reviewing other code examples), and understanding the specific implementation.

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

View solution in original post

7 REPLIES 7
misagh
Associate III
Posted on June 26, 2017 at 16:43

As you can see in figure 4 in TCA6424A datasheet, you need to use 8-bit address. one bit is for data direction bit (R/W). I think this is the only problem you have.

0690X00000607X1QAI.png

Hope this solution would be helpful.

Bests,

Misagh

Posted on June 26, 2017 at 17:19

>>

Did I miss something or is there a bug in the code? How can I disable the additional zero in front of the device address?

Some implementations shift the address and some don't. ST's doesn't so you must left align the address in the high order 7 bits. The low order bit is determined based on it being a read (receive) or write (transmit) transaction

It is a matter of understanding the data sheet for the I2C part to get the address (and reviewing other code examples), and understanding the specific implementation.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
john doe
Lead
Posted on June 26, 2017 at 19:12

instead of using address 0x22, try

(uint16_t)(0x22<<1)

Posted on June 26, 2017 at 17:22

The R/W bit isn't part of the address. It's done by soft- or hardware (I don't know). You can check this if you call the receive-function and observe the output on the oscilloscope (I have I2C decoding capabilities on mine). The address must be always 7bit or 10bit. In this case it's 7 bit.

Posted on June 26, 2017 at 17:25

Interesting. Okay I will check this tomorrow.

Posted on June 26, 2017 at 20:27

Yes. you and Clive are right. As you can see in following picture, there is a software part for making the address R/W:

0690X00000607JkQAI.png

So you may need to shift your address one bit left.

Sorry for my last wrong post.

Bests,

Misagh

benny
Associate II
Posted on June 27, 2017 at 18:41

Problem solved. Thanks to all.