Issue with I2C between 2 STM32F411 black pill

Post here first, or if you can't find a relevant section!
Post Reply
camelator
Posts: 12
Joined: Fri Aug 20, 2021 10:27 am

Issue with I2C between 2 STM32F411 black pill

Post 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);
}
by GonzoG » Tue Jun 21, 2022 3:47 pm
No. You need at least pullup resistors. Otherwise MCU will read something as pin will change its state randomly.
Go to full post
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 26
Location: Prudnik, Poland

Re: Issue with I2C between 2 STM32F411 black pill

Post by GonzoG »

1. Did you connect both boards to a common ground ??
2. did you use pull-up resistors on IIC lines ??
camelator
Posts: 12
Joined: Fri Aug 20, 2021 10:27 am

Re: Issue with I2C between 2 STM32F411 black pill

Post 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)
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 26
Location: Prudnik, Poland

Re: Issue with I2C between 2 STM32F411 black pill

Post by GonzoG »

No. You need at least pullup resistors. Otherwise MCU will read something as pin will change its state randomly.
camelator
Posts: 12
Joined: Fri Aug 20, 2021 10:27 am

Re: Issue with I2C between 2 STM32F411 black pill

Post by camelator »

Hi GonzoG,
many thanks for your reply,
I totally forgot that!
Now it works!
many thanks!
Billie34
Posts: 2
Joined: Tue Mar 07, 2023 8:17 am

Re: Issue with I2C between 2 STM32F411 black pill

Post 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.
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 26
Location: Prudnik, Poland

Re: Issue with I2C between 2 STM32F411 black pill

Post 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.
Billie34
Posts: 2
Joined: Tue Mar 07, 2023 8:17 am

Re: Issue with I2C between 2 STM32F411 black pill

Post 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
Post Reply

Return to “General discussion”