I am trying to establish a communication protocol between stm32 and arduino with UART DMA. What I want to do is to print "Emergency Button Activated" on the arduino serial port when the button is pressed, and then get the value 1. I want to do the opposite when the button is not pressed. I am attaching the code I wrote below. No matter how hard I tried, I couldn't. If I turn off the message part, I can get 1 and 0 values on the serial port. But when I open the message, no data is sent or I can't see the characters as letters.
It doesn't see the txmsgon and txmsgoff texts I sent and writes them as numbers as ASCII characters. If I make the variable char on the arduino, it does not see the 1s and 0s at this time. I want to partner with both. There is an error in the read command but I couldn't figure out what it was. When i press the button then i can see 1 on live expressions stm32 cubeide. The button is working. I think there is something wrong with the reading code. Can you help please?
Reading Code;
uint8_t data;
void setup()
{
Serial.begin(9600);
//Serial.println("UART Started");
}
void loop()
{
if(Serial.available()>0) {
data=Serial.read();
Serial.println(data);
delay(250);
}
}