2020-09-03 12:44 AM
Hello dear experts,
I am trying to send a binary 32bits over the uart3 using either HAL_UART3_Transmit (polling, It or DMA).
1- sending roughly the 32bits with a length of 4 in the function parameters does not work.
2 -sorting the 32bits data in a 8bits array with >> and & and passing the array @ with a lenth of 4 does not work.
3- using a loop and sending the 4 bytes one by one with a length of 1 works whatever the mode but maybe the most efficient considering the time.
4- the following code sends correctly 3 bytes out of 4... the last one is corrupted. Dont understand why, on the scope, 81 appears as 08
uint32_t data = 0x815533AA;
uint8_t dataArray[4];
dataArray[0] = data & 0x000000FF;
dataArray[1] = (data & 0x0000FF00) >> 8;
dataArray[2] = (data & 0x00FF0000) >> 16;
dataArray[3] = (data & 0xFF000000) >> 24;
HAL_UART_Transmit_DMA(&huart3, (uint8_t*)dataArray, 4);
NB: the last byte is always 0x08 whatever the value; i am using DAM1 stream3 mode normal data with byte for peripheral and memory.
I think i am missing an important point in DMA transfers....
Thanks for your help.
Pap
2020-09-03 07:15 AM
Include your part number.
Don't send local variables out through DMA. Since DMA operates asynchronously, the variables go out of scope before it completes. Use a global array, or otherwise ensure the array remains valid until DMA is complete.
2020-09-03 08:05 AM
Thanks TDK, Got it! excellent suggestion ! I thought that DMA transfer were faster. Do you think I also need to check the function returned value and also the serial state ?
regards.
2020-09-03 08:26 AM
> I thought that DMA transfer were faster.
The UART speed is constant. Using DMA just means it goes on in the background while your CPU is off doing other things.
> Do you think I also need to check the function returned value and also the serial state ?
I would. Easy enough to do and it can help you find bugs faster than if you let the function fail silently.
2020-09-04 04:40 AM
Using the global variables as proposed, it worked correctly at speed around 961Kbits/s on uart3 but when I try to increase the baud rate up to 1.843Mbits/s the last byte is corrupted. I also noticed that the returned value of HAL_UART_Transmit_DMA() is correct but testing the uart status stays stuck in the while loop....
while (HAL_UART_GetState(&huart3) != HAL_UART_STATE_READY)
{
}
Any suggestion for both problems (speed and status)?
I thank you in advance.
Pap
2020-09-04 04:40 AM
Using the global variables as proposed, it worked correctly at speed around 961Kbits/s on uart3 but when I try to increase the baud rate up to 1.843Mbits/s the last byte is corrupted. I also noticed that the returned value of HAL_UART_Transmit_DMA() is correct but testing the uart status stays stuck in the while loop....
while (HAL_UART_GetState(&huart3) != HAL_UART_STATE_READY)
{
}
Any suggestion for both problems (speed and status)?
I thank you in advance.
Pap
2020-09-04 06:44 AM
I would find a HAL example using DMA UART and go from there.
The State should get changed back in the DMA complete interrupt.
2020-09-07 06:31 AM
dear TDk,
i can se ethat the uart3 state is HAL_UART_STATE_BUSY_TX and appaarently it never switches to HAL_UART_STATE_READY so I stay stuck in the isr callback and no data is sent. Not testing that value produces a corrupted last byte on the uart3. Is there any speed problem with uart3 to your knowledge.
regards,
pap