Hello,
I want to establish two way serial comunication between bluepill and nano , could also bluepill to bluepill, to exchange values of defined variables.
I have working stuff with UNO and nano , using struct data.
would arduino struct data libriris work on stm32 bluepill?
On A side i have stm32 conected to tft display, it uses tx rx 1 and 2 pins , so i need to use tx rx 3 pins, but i am not familiar to set up this with cube MX, also dont have enough knowledge to use HAL libraries. On B side i have nano or can use also bluepill, conected sensors to collect data.
distance is abot 12 meters so i want use serial , maybe also rs 485 converter between.
so , i need to setup tx rx 3 pins on bluepill and want use struct data ( it is eaay to do with struct data, and as i can see, it is reliable transmitting,
better than..if serial aaliable and ent , stop caracters.)
here is my code
// sending UNO to STM32 Bluepill
#include "SerialTransfer.h"
int VTmin;
int VTmax;
int ZelVlaga;
int Vzracenje;
// data to send from UNO to STM32
struct SensorData {
float sensorValue1;
float sensorValue2;
float sensorValue3;
float sensorValue4;
int VodaAl;
};
struct TFTdata {
int ZelVlaga;
int VTmin;
int VTmax;
int Vzracenje;
};
SerialTransfer stream;
SensorData TXdata;
TFTdata RXdata;
// data to send from UNO to STM32 for testing
float sensorValue1=1.1;
float sensorValue2=2.1;
float sensorValue3=3.1;
float sensorValue4=4.1;
bool VodaAl=false;
void setup() {
Serial.begin(9600);
stream.begin(Serial);
}
void loop() {
// Update TXdata with sensor values
TXdata.sensorValue1 = sensorValue1;
TXdata.sensorValue2 = sensorValue2;
TXdata.sensorValue3 = sensorValue3;
TXdata.sensorValue4 = sensorValue4;
// Send data
sndtx();
// Receive data
recrx();
ZelVlaga = RXdata.ZelVlaga;
VTmin=RXdata.VTmin;
VTmax=RXdata.VTmax;
Vzracenje=RXdata.Vzracenje;
// Print received sensor data
Serial.println("Received Sensor Data:");
Serial.print("Zeljena vlaga: ");
Serial.println(RXdata.ZelVlaga);
Serial.print("Minimalna temperatura ");
Serial.println(RXdata.VTmin);
Serial.print("Maximalna temperatura ");
Serial.println(RXdata.VTmax);
Serial.print("Prezracevanje ");
Serial.println(RXdata.Vzracenje);
}
void recrx() {
if (stream.available()) {
stream.rxObj(RXdata);
}
}
void sndtx() {
stream.txObj(TXdata, sizeof(TXdata));
stream.sendDatum(TXdata);
Serial.flush();
}
and STM to UNO ( I use pins A9 and A10 on bluepill)
// sending STM32 to UNO
#include "SerialTransfer.h"
// variables for receiving from UNO
float sensorValue1;
float sensorValue2;
float sensorValue3;
float sensorValue4;
int VodaAl;
// variables to send from STM32 to UNO for testing
int ZelVlaga = 1;
int VTmin = 2;
int VTmax = 3;
int Vzracenje =4;
struct SensorData {
float sensorValue1;
float sensorValue2;
float sensorValue3;
float sensorValue4;
int VodaAl;
};
struct TFTdata {
int ZelVlaga;
int VTmin;
int VTmax;
int Vzracenje;
};
SerialTransfer stream;
SensorData RXdata; // Use RXdata to store received data
TFTdata TXdata;
void setup() {
Serial.begin(9600);
stream.begin(Serial);
}
void loop() {
// Receive data
recrx();
// Print received sensor data
Serial.println("Received Sensor Data:");
Serial.print("SensorValue1: ");
Serial.println(RXdata.sensorValue1);
Serial.print("SensorValue2: ");
Serial.println(RXdata.sensorValue2);
Serial.print("SensorValue3: ");
Serial.println(RXdata.sensorValue3);
Serial.print("SensorValue4: ");
Serial.println(RXdata.sensorValue4);
Serial.print("VodaAl: ");
Serial.println(RXdata.VodaAl);
TXdata.ZelVlaga = ZelVlaga;
TXdata.VTmin = VTmin;
TXdata.VTmax = VTmax;
TXdata.Vzracenje = Vzracenje;
// Send data
sndtx();
}
void recrx() {
if (stream.available()) {
stream.rxObj(RXdata);
}
}
void sndtx() {
stream.txObj(TXdata, sizeof(TXdata));
stream.sendDatum(TXdata);
Serial.flush();
}
thank you for your help
joe