cancel
Showing results for 
Search instead for 
Did you mean: 

Tranceiving & Receiving Data with UART on STM32H735G-DK

Nick_Tesla
Associate II

Dear all,

I've been wrestling with a communication glitch that's been causing me some serious headaches. Here's the lowdown: I've got this control board hooked up to a pump, and I've been trying to send commands to it via USART1 on my own STM32H735G-DK. The problem? It seems my board's only sending half the message, which is a major problem because those messages serve as commands for the pump.

After some debugging, I've narrowed down the issue to my UART interrupt. I thought I'd solved the issue by disabling the interrupt, sending the data, and then re-enabling it once the message was fully sent. But alas, that meant losing crucial data coming back from the pump, which is just as vital as sending commands. So it's a classic catch-22 situation: sacrifice the first half of my Rx message to send data, or lose the second half of my Tx message to receive data. I've verified this by scrutinizing the signal with my Oscilloscope's Decoder.

My messages are short, typically 1-40 characters, but their size can be unpredictable.

Any ideas on how to tackle this problem? I'm more than happy to share my code if it'll shed some light. Below are the relevant snippets:

 

 

__disable_irq();

if (pumpNo == 1)
{
    HAL_UART_Transmit(&huart1, pumpCommand, newlineIndex+1, HAL_MAX_DELAY);
}
else
{
    printf("ERROR: PUMP NOT FOUND");
    UartRxData1[0] = '5';
    temp1[0] = '\n';
}

__enable_irq();
HAL_UART_Receive_IT(&huart1, temp1, 1);

 

 

And the interrupt callback:

 

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
    memcpy (UartRxData1+uartIndx1, temp1, 1);

    if (++uartIndx1 >= 64)
    {
        memset(UartRxData1, 0, sizeof UartRxData1);
        uartIndx1 = 0;
    }

    HAL_UART_Receive_IT(&huart1, temp1, 1);
}

// USART1 Interrupt
HAL_UART_Receive_IT(&huart1, temp1, 1);

 

Any advice or help would be greatly appreciated!

 

 
1 ACCEPTED SOLUTION

Accepted Solutions
Pavel A.
Evangelist III

>  HAL_UART_Receive_IT(&huart1, temp1, 1);

Using HAL_UART_Receive_IT to receive variable sized data by one character is flawed and naturally prone to comm errors. Please look for more robust RX procedure - even though the "HAL" library does not have anything easy and ready. Consider circular buffer DMA. There are many examples on github.

 

View solution in original post

2 REPLIES 2
LCE
Principal

At 38k4 baud this should not be a hardware problem.

I don't like the HAL UART RX stuff at all, I think it's super *** that the DMA version needs a preconfigured length, even with this IDLE check.

I use UART 3 on H735-DK for debugging only, but without any problems, at ~1 Mbit/s.

It's a wild mix of HAL and direct register settings, maybe it helps.

Pavel A.
Evangelist III

>  HAL_UART_Receive_IT(&huart1, temp1, 1);

Using HAL_UART_Receive_IT to receive variable sized data by one character is flawed and naturally prone to comm errors. Please look for more robust RX procedure - even though the "HAL" library does not have anything easy and ready. Consider circular buffer DMA. There are many examples on github.