cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103C8 as I2C SLAVE - I2C HAL_I2C_Slave_Seq_Transmit_IT sends address as the first data byte. HAL Bug ?

debugging
Lead

STM32F103 as Interrupt driven I2C slave . in the address callback

Master READ

if (dir == I2C_DIRECTION_RECEIVE) // 0

 {

      data[0] = 0x55;

       data[1] = 0xAA;

     HAL_I2C_Slave_Seq_Transmit_IT(hi2c, &data[0], 2, I2C_LAST_FRAME);

}

On the wire (see picture) the first byte returned to the master is always a duplicate of the address | direction bit. Tested this with several different addresses. Changing the option flag LAST_FRAME) does not matter. Also the error callback is called and the error is 0x0C (AF | OVR) For example: Address 0x30 write , setup = 0x61. 1st data byte = 0x61 (0x30 << 1 | 1), second is 0x55. For address 0x20, setup = 0x31 , first data byte = 0x31, second is 0x55. 0xAA never goes over the wire 

When receiving data from a master, (MASTER WRITE) HAL_I2C_Slave_Seq_Receive_IT(hi2c, data, 2, I2C_LAST_FRAME); does receive the two correct data bytes.

0690X00000Bwl61QAB.png

4 REPLIES 4
debugging
Lead

Have the same issue with one byte. Just for debugging, when forcing the first data byte value in the HAL driver it still sends the address as the first data byte.

 *pData = 0x55;

   /* Prepare transfer parameters */

   hi2c->pBuffPtr   = pData;

0690X00000BwlstQAB.png

PDemb.1
Associate

@debugging​ 

Did You find an answer? I have similar problem.

debugging
Lead

unfortunately not. Still in limbo how to get a slave implemented. Sent a PM to Imen Dahmen (as below) but no reply for 3 months. Gave up and moved to other things but this will be a decisive issue in a few weeks time getting back to this project. Maybe DMA mode works, have not tried it. I have a bunch of other SM MCU's and will try those as well. If finally can't get slave mode working I'll may have to move use other micro-controllers or brands or a major change the intended architecture/design of my solution. Try to search this forum with "I2C slave" and you'll find a huge amount post of people having all kind of issue issues and asking for sample code, but there are no answers. It could be the F103 HAL I2C slave library for interrupt code is broken without STM wanting to admit it and the same code on another MCU may work due to HAL differences. An alternative would be to write custom I2C codes instead of using the HAL library.. Also check this out:

https://community.st.com/s/question/0D50X0000BueC0USQU/connecting-raspberry-pi-to-stm32f105xx-via-i2c

Same issue, duplicate byte. So that makes three of us bumping into this brick wall.

  

"I have posted some issues about I2C and struggling with slave mode. i am building a STM32MP1 interfacing to an STM32F103C8 . Would you have time take a look at this link, There are no ST examples using the callbacks only, so it is hard to find a "reference" code. Maybe I am doing something wrong but there is nothing much I see I can change in calling the HA driver. I am debugging this with an RPI3 to the STMF103C8 as a slave. Writing from the PI to STMF103C8 is fine but not the other way around."

laserfaser
Associate II

Hey, I have the same problem. Google for your specific reference manual (the 1500 pages long pdf with all registers in it and so on.) In slave-i2c you'll see this line in the Slave Transmitter section:

Following the address reception and after clearing ADDR, the slave sends bytes from the
DR register to the SDA line via the internal shift register.

So it is sending out what it still has in the DR, which is the Slave-Address and R/W-Bit. I tried to get it to send something like 0b10101010 by writing to DR immediately when the corresponding interrupt is triggered, but still the same. I will let you know when I find out wtf this is.

 

 

 

 

Reference for STM32F1

https://www.google.com/url?sa=t&source=web&rct=j&opi=89978449&url=https://www.st.com/resource/en/reference_manual/rm0008-stm32f101xx-stm32f102xx-stm32f103xx-stm32f105xx-and-stm32f107xx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf&ved=2ahUKEwiDu-ip2aSHAxX8hv0HHcU5BRgQFnoECBIQAQ&usg=AOvVaw0gKEw...