I'm playing around with a bluepill Board. The Idea is to create a few boards with STM32F103 Prozessors. These Boards shell collect data and do some other stuff. Sometimes a Raspberry will collect some data. (Sometimes in fact is 10ms

Currently i'm using a Raspberry pi 4 as an I2C Master and the Bluepill as a Slave on I2C2. Also a SCD30 Sensor from sensirion as an example on the I2C(1) Bus on the BluePill.
when the Bluepill collects data from the Sensor and exactly in this moment the Raspberry also sends a read request, the connection breaks down and the bluepill pulls the clock of the I2C2 Bus low (the one to the raspberry).
Are there maybe some Ideas?
I'm using the board manager files from github:
https://github.com/stm32duino/BoardMana ... index.json
my Arduino code is attached
Code: Select all
#include <Wire.h>
#include "SparkFun_SCD30_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_SCD30
SCD30 airSensor;
#define SLAVE_ADDRESS 0x08
#define DATA_TO_SEND_LENGHT 30
char number[30];
char test[DATA_TO_SEND_LENGHT];
// SDA SCL
TwoWire Wire2(PB11, PB10);
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
//Serial.begin(115200);
//Serial.println("SCD30 Example");
// initialize wire
Wire.begin();
Wire2.begin(SLAVE_ADDRESS);
//Wire2.setClock(STM_I2C2_FREQ);
Wire2.onReceive(receiveData2);
Wire2.onRequest(sendData2);
for (int i=0; i<DATA_TO_SEND_LENGHT ; i++){
test[i]=95;
}
if (airSensor.begin() == false)
{
digitalWrite(LED_BUILTIN,!digitalRead(LED_BUILTIN));// Turn the LED from off to on, or on to off
delay (200);
digitalWrite(LED_BUILTIN,!digitalRead(LED_BUILTIN));// Turn the LED from off to on, or on to off
delay (200);
}
}
void loop()
{
if (airSensor.dataAvailable())
{
digitalWrite(LED_BUILTIN,!digitalRead(LED_BUILTIN));// Turn the LED from off to on, or on to off
f_CO2 = airSensor.getCO2();
f_temp = airSensor.getTemperature();
f_humidity = airSensor.getHumidity();
}
delay(500);
}
// callback for received data
void receiveData2(int byteCount) {
digitalWrite(LED_BUILTIN,!digitalRead(LED_BUILTIN));// Turn the LED from off to on, or on to off
int i = 0;
while (Wire.available()) {
number[i] = Wire.read();
i++;
}
} // end while
// callback for sending data
void sendData2() {
digitalWrite(LED_BUILTIN,!digitalRead(LED_BUILTIN));// Turn the LED from off to on, or on to off
Wire.write(test,sizeof(test));
}
Code: Select all
#RPi Pinouts
#I2C Pins
#GPIO2 -> SDA
#GPIO3 -> SCL
#Import the Library Requreid
import smbus
import time
# for RPI version 1, use "bus = smbus.SMBus(0)"
bus = smbus.SMBus(1)
time.sleep(.1)
# This is the address we setup in the Arduino Program
#Slave Address 1
address = 0x08
read_length = 30
data = [255,255,0,1,2,3,4,5,6,7]
data_list = list(data)
count = 0
def writeNumber(value):
bus.write_i2c_block_data(address,0,value)
return -1
def readNumber():
number = bus.read_i2c_block_data(address, 0,read_length)
return number
while True:
state=1
if int(state) == 1:
for j in range (0,6):
writeNumber(value)
j +=1
#print("READ all data")
for i in range (0,6):
x = readNumber()
#time.sleep(.000005)
i+=1
#x_string = ''.join(chr(i) for i in x)
#print(x_string)
#time.sleep(.001)
else:
print ("enter valid function")
count = count + 1
print (count)
time.sleep(.0005)
#End of the Script