Page 1 of 1

Issue with I2C between 2 STM32F411 black pill

Posted: Mon Jun 20, 2022 11:29 pm
by camelator
Hi,
unfortunately, I am not able to communicate between 2 STM32F411 blue pill boards with I2C.
From, the master, I removed all the extra code, and I just keep the code for communication.
I've unplugged all wires between the two boards. Master is not connected on the SDA (PB4) and SCL (PA8) lines.

But the code bellow run anormaly fine.

It should't work as:

int32_t n=masterI2C.requestFrom(0x25,6) ;

suprisely, value for n is 6 instead of 0 as the wires are not connected.

Any help?



#include <Arduino.h>
#include <Wire.h>

#define MASTER_SDA PB4
#define MASTER_SCL PA8

TwoWire masterI2C(MASTER_SDA, MASTER_SCL);


void setup()
{


Serial.begin(115200);
Serial.println("[ENGINE] Initializing");

masterI2C.begin();


}


void loop()
{


masterI2C.beginTransmission(0x24) ;
masterI2C.write(0x01) ;
masterI2C.endTransmission(false) ;
int32_t n=masterI2C.requestFrom(0x24,6) ;
if (n==6) {
uint8_t v[6] ;
uint8_t *pv=v;
while ( (n>0) ) {

int32_t v=masterI2C.read() ;
*pv++=(uint8_t)v ; n--;
}
uint32_t yaw=0 ;
uint32_t pitch=0 ;
uint32_t roll=0 ;

yaw=v[0]+(v[1]<<8) ;
pitch=v[2]+(v[3]<<8) ;
roll=v[4]+(v[5]<<8) ;
Serial.print("yo") ;

}


//gps.loop();
delay(10);
}

Re: Issue with I2C between 2 STM32F411 black pill

Posted: Tue Jun 21, 2022 8:59 am
by GonzoG
1. Did you connect both boards to a common ground ??
2. did you use pull-up resistors on IIC lines ??

Re: Issue with I2C between 2 STM32F411 black pill

Posted: Tue Jun 21, 2022 1:48 pm
by camelator
1. Did you connect both boards to a common ground ??
2. did you use pull-up resistors on IIC lines ??

No, for this first test, I am just working with the master board, I let the pins free, without wires, without connection.
So, if my understanding is correct, in these conditions, the following line:

int32_t n=masterI2C.requestFrom(0x24,6) ;

should return 0 as there is no connection... But the function returns 6 (the number of bytes requested)

Re: Issue with I2C between 2 STM32F411 black pill

Posted: Tue Jun 21, 2022 3:47 pm
by GonzoG
No. You need at least pullup resistors. Otherwise MCU will read something as pin will change its state randomly.

Re: Issue with I2C between 2 STM32F411 black pill

Posted: Wed Jun 22, 2022 8:57 am
by camelator
Hi GonzoG,
many thanks for your reply,
I totally forgot that!
Now it works!
many thanks!

Re: Issue with I2C between 2 STM32F411 black pill

Posted: Tue Mar 07, 2023 8:27 am
by Billie34
One of my main interests in this endeavor is the keypad plugin, which I'm eager to test out on my network. I currently use a Blackpill development board with a WeActStudio STM32F411 MCU. I2C pins are often mapped to PB10 and PB11, but PB11 on Blackpill boards is not routed to headers, which is my issue.

Re: Issue with I2C between 2 STM32F411 black pill

Posted: Wed Mar 08, 2023 8:57 pm
by GonzoG
@Billie34
There's no such thing as "I2C pins are often mapped to PB10 and PB11".
Each MCU may have different pins used for "same" interface. Read MCU datasheet or board pinout to find which pins are used for which interface.

Also, there is no WeActStudio STM32F411 MCU. STM32 MCUs are made by STM.

Re: Issue with I2C between 2 STM32F411 black pill

Posted: Fri Apr 07, 2023 1:59 am
by Billie34
GonzoG wrote: Wed Mar 08, 2023 8:57 pm @Billie34
There's no such thing as "I2C pins are often mapped to PB10 and PB11".
Each MCU may have different pins used for "same" interface. Read MCU datasheet or board pinout to find which pins are used for which interface.

Also, there is no WeActStudio STM32F411 MCU. STM32 MCUs are made by STM.
I understood, thanks a lot