UART DMA Communication between STM32 and Arduino

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);   
  }
}

Where is a DMA?

STM32 Code;
Variables

uint8_t rxBuffer[10];
uint8_t txBuffer[1]= {1};
uint8_t txBuffer0[1]= {0};
uint8_t txmsgon[]="Emergency Button Activated\r\n";
uint8_t txmsgoff[]="Emergency Button Deactivated\r\n";

Receive

   HAL_UART_Receive_DMA(&huart1,rxBuffer,sizeof(rxBuffer));

Transmit

 while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
	  emergencyButton = HAL_GPIO_ReadPin(GPIOA, B1_Pin);
	  if (emergencyButton == 1)
	  		{
		  	    HAL_UART_Transmit(&huart1, txmsgon, sizeof(txmsgon),100);
		  	  	HAL_Delay(500);
	  			HAL_UART_Transmit_DMA(&huart1, txBuffer, sizeof(txBuffer));
	  			HAL_Delay(250);

	  		}

	   if (emergencyButton == 0)
	  		{
			    HAL_UART_Transmit(&huart1,txmsgoff,sizeof(txmsgoff),100);
				HAL_Delay(500);
	  			HAL_UART_Transmit_DMA(&huart1, txBuffer0, sizeof(txBuffer0));
	  			HAL_Delay(250);
	  		}
   }

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.