UART DMA Communication between STM32 and Arduino

Viewed 44

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. Can you help please?

Arduino Code;

    uint8_t data;

    void setup() 
    {
    Serial.begin(9600);
    }

    void loop() 
    {  
    if(Serial.available()>0) {
    data=Serial.read();   
    Serial.println(data);    
    delay(250);   
    }
    }

STM32F0 Code;

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 BEGIN 3 */
  emergencyButton = HAL_GPIO_ReadPin(GPIOA, B1_Pin);
  if (emergencyButton == 1)
        {
          HAL_UART_Transmit_DMA(&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_DMA(&huart1,txmsgoff,sizeof(txmsgoff),100);
            HAL_Delay(500);
            HAL_UART_Transmit_DMA(&huart1, txBuffer0, sizeof(txBuffer0));
            HAL_Delay(250);
        }
0 Answers
Related