2017-06-26 07:03 AM
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
Solved! Go to Solution.
2017-06-26 08:19 AM
>>
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.
2017-06-26 07:43 AM
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.
Hope this solution would be helpful.
Bests,
Misagh
2017-06-26 08:19 AM
>>
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.
2017-06-26 10:12 AM
instead of using address 0x22, try
(uint16_t)(0x22<<1)
2017-06-26 10:22 AM
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.
2017-06-26 10:25 AM
Interesting. Okay I will check this tomorrow.
2017-06-26 01:27 PM
Yes. you and Clive are right. As you can see in following picture, there is a software part for making the address R/W:
So you may need to shift your address one bit left.
Sorry for my last wrong post.
Bests,
Misagh
2017-06-27 09:41 AM
Problem solved. Thanks to all.