Hardware Serial sending data using USART.
Posted: Tue Sep 14, 2021 1:35 pm
I am attempting to to send a message or from one STM32F103C8T6 board to another STM32F103C8T6 board. I have chosen PA10 and PA9 as my Rx and Tx for both the boards. And I have also assigned driver enable pin for both the pins (For Master PB15, which is always HIGH and for Slave PC14, which is always LOW). I am using HardwareSerial to read and write my data.
But I could able to send the data exactly to the slave from master. The ouput is printing just "??????". I dont know exactly where I am doing mistake. I am also attaching the screenshot and the codes that I am using to test the hardware serial.
My main task is to read and write the sensor values from the both the boards and and send them acorrding to algorithm given to the boards.
Hoping for responses from you.
Here below I am posting the code for my Master:
Here below I am posting the code for my Slave:
I am programming in stm32f103c8t6 in Arduino IDE with the current STM32 core files for STM32 based boards (official STM core, HAL based)
https://github.com/stm32duino/Arduino_Core_STM32. I am working on Windows 10. My Arduino IDE version 1.8.5.
But I could able to send the data exactly to the slave from master. The ouput is printing just "??????". I dont know exactly where I am doing mistake. I am also attaching the screenshot and the codes that I am using to test the hardware serial.
My main task is to read and write the sensor values from the both the boards and and send them acorrding to algorithm given to the boards.
Hoping for responses from you.
Here below I am posting the code for my Master:
Code: Select all
#define enable PB15
HardwareSerial myserial(PA10, PA9);
char firstname[7] = "Mustaq";
void setup()
{
pinMode(enable, OUTPUT);
digitalWrite(enable, HIGH);
Serial.begin(115200);
myserial.begin(19200);
}
void loop()
{
myserial.write(firstname);
Serial.println(firstname);
delay(1000);
}
Code: Select all
#define enable PC14
HardwareSerial myserial(PA10, PA9);
char myname[7];
byte nextchar = 0;
byte currentchar = 0;
void setup()
{
pinMode(enable, OUTPUT);
digitalWrite(enable, LOW);
Serial.begin(115200);
myserial.begin(19200);
}
void loop()
{
Serial.println("before while");
while(myserial.available());
{
Serial.println("inside while");
currentchar = myserial.read();
myname[nextchar] = currentchar;
nextchar++;
Serial.println("one loop of while is done");
}
Serial.println(myname);
delay(1000);
}
https://github.com/stm32duino/Arduino_Core_STM32. I am working on Windows 10. My Arduino IDE version 1.8.5.