Electronic – arduino – STM32 HAL UART transmission

arduinodmastm32cubemxstm32f10xuart

I'm trying to send data by STM32f103 to an Arduino board using UART. Data isn't received properly. The code is generated using STM32CUBEMX and here is the part I added:

STM32 code (Transmit):

uint8_t Test[] = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 \n"; //Data to send 

HAL_UART_Transmit(&huart1,Test,sizeof(Test),10);// Sending in normal mode
HAL_Delay(1000);
HAL_UART_Transmit_DMA(&huart1,Test,sizeof(Test));// Sending in DMA mode
HAL_Delay(1000);

    /* USART1 init function */
static void MX_USART1_UART_Init(void)
{

  huart1.Instance = USART1;
  huart1.Init.BaudRate = 115200;
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
  huart1.Init.StopBits = UART_STOPBITS_1;
  huart1.Init.Parity = UART_PARITY_NONE;
  huart1.Init.Mode = UART_MODE_TX_RX;
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  if (HAL_UART_Init(&huart1) != HAL_OK)
  {
    Error_Handler();
  }

}

the received data is:

  {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 1}
enter code here

in both DMA and normal modes the received data is pretty similar. The UART baud rate is 115200.

Why is my data being truncated? Is it an array bounds problem? Or am I hitting the limit of my buffer?

Edit:

Arduino Code (Receive):

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 9); // RX, TX ports

void setup() {
  // set the data baud rate 
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. 
  }
  mySerial.begin(115200);
}

void loop() { 
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
}

Data transmission works good between two Arduino boards.

Best Answer

The higher a baud rate goes, the faster data is sent/received, but there are limits to how fast data can be transferred. You usually won’t see speeds exceeding 115200 - that’s fast for most microcontrollers. Get too high, and you’ll begin to see errors on the receiving end, as clocks and sampling periods just can’t keep up.

Test lower baud rate.