Why is QT Creator Automatically Splitting my String While Reading the Data from a STM32 Microcontroller?

64 Views Asked by At

I have been trying to send some temperature values read by 2 sensors connected to STM32 Microcontroller. I have already programmed the mc to send just 2 lines of temperature values (vertically and each time new value updating; see below) to the textEdit widget of QT Creator

22.05 °C

23.12 °C

However QT keeps splitting the string in different sizes.. sometimes I receive it fully but sometimes just parts of it. (like .05°C or just °C). I even tried sending a normal string like Test or Hello.. the same issue happens. The debug console also displays split data (like 'est' or sometimes just 't' for Test). I can't figure out why is this happening.

My QT code for reading values :

void MainWindow::readData()
{
    QByteArray data = COMPORT->readAll();
    qDebug() << "Received Data Size:" << data.size();

    // Convert the received data to QString
    //QString receivedData = QString::fromUtf8(data);
    QString receivedData = QString(data);
    ui->textEdit->clear();
    qDebug() << "Received Data:" << receivedData;
    ui->textEdit->setText(receivedData);

}

My simplest version of STM32 code looks like this :

char buffer [7];
if (input == '1')
{
sprintf (buffer, "Test")
HAL_UART_Transmit(&huart2, (uint8_t*)buffer, strlen(buffer), 200);
}
0

There are 0 best solutions below