Issue with I2C between 2 STM32F411 black pill
Posted: Mon Jun 20, 2022 11:29 pm
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);
}
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);
}