cancel
Showing results for 
Search instead for 
Did you mean: 

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

ABenz.11
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

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".

View solution in original post

2 REPLIES 2
TDK
Guru

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".

This works beautifully.

Very elegant as well.

Kudos and thank you from Berlin