Skip to main content
ABenz.11
Associate II
November 7, 2021
Solved

Send multiple byte (3x4byte variabel and 4x2byte variable) of binary data over UART with DMA

I have 7 binary variable that I want to continously send to uart with the DMA.

I do not want to use ascii format, I want to send binary data.

If I use multiple DMA transmits in a row, just some are beeing send due to the fact, that when the second is triggered the first is still beeing transmited.

How can I create a 20byte long variable in which I can store the data and send it with one command?

It is easily possible to send a 20byte sentence so it should be possible to create a 20byte variable.

Or am I overthinking it? can I construct an array and send the array at once.

I want to use DMA because the amount of data is getting bigger in the future.

This topic has been closed for replies.
TDK
TDKBest answer
November 7, 2021

Make them co-located in memory and send the whole thing.

struct DataStruct {
 uint32_t x[3];
 uint16_t y[4];
};
 
DataStruct data;
data.x[0] = 1;
...
 
HAL_UART_Transmit_DMA(&huart1, (uint8_t *) &data, sizeof(data));

"If you feel a post has answered your question, please click ""Accept as Solution""."

2 replies

TDK
TDKBest answer
November 7, 2021

Make them co-located in memory and send the whole thing.

struct DataStruct {
 uint32_t x[3];
 uint16_t y[4];
};
 
DataStruct data;
data.x[0] = 1;
...
 
HAL_UART_Transmit_DMA(&huart1, (uint8_t *) &data, sizeof(data));

"If you feel a post has answered your question, please click ""Accept as Solution""."
ABenz.11
ABenz.11Author
Associate II
November 7, 2021

This works beautifully.

Very elegant as well.

Kudos and thank you from Berlin