2021-08-24 06:51 AM
I am using STM32F746G discovery board.
~~~
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
HAL_UART_Receive_IT (&huart6, Rx_buff, USART_RX_BUFFER_SIZE);
HAL_Delay(500);
HAL_UART_Transmit(&huart6, &Rx_buff, USART_RX_BUFFER_SIZE, 1000);
}
~~~
This is the way i am using USART6, TX and RX.
here my doubt is, i fixed my USART_RX_BUFFER_SIZE =10.
I send 10 bytes data via serial terminal(hercules), in this case my usart transmit also works with same 10 bytes data.
But i send 9 bytes data means, the uart transmit is not transmit the 9 bytes data.
my requirement is,
how much amount of bytes received via UART_Receive(); , that amount of bytes, send via UART_Transmit();
Thanks
Manikandan D
Solved! Go to Solution.
2021-08-24 07:27 AM
Hello,
I recommend you to have a look to the following articles:
https://community.st.com/s/article/STM32-UART-DMA-RX-TX
https://community.st.com/s/article/faq-stm32-hal-driver-api-and-callbacks
Imen
2021-08-24 07:27 AM
Hello,
I recommend you to have a look to the following articles:
https://community.st.com/s/article/STM32-UART-DMA-RX-TX
https://community.st.com/s/article/faq-stm32-hal-driver-api-and-callbacks
Imen
2021-08-24 07:45 AM
You'd need to count the bytes. Perhaps there is an index in the uart instance structure, or you need to accumulate your own buffer one byte at a time.
You should not delay or call blocking functions in the call-back.
If you ask the function to receive 10 bytes before entering the call-back, 9 will not be sufficient.
Watch the definition of Rx_buff
2021-08-24 10:59 AM
Use HAL_UARTEx_ReceiveToIdle or HAL_UARTEx_ReceiveToIdle_IT.
/**
* @brief Receive an amount of data in blocking mode till either the expected number of data
* is received or an IDLE event occurs.
* @note HAL_OK is returned if reception is completed (expected number of data has been received)
* or if reception is stopped after IDLE event (less than the expected number of data has been received)
* In this case, RxLen output parameter indicates number of data available in reception buffer.
* @note When UART parity is not enabled (PCE = 0), and Word Length is configured to 9 bits (M1-M0 = 01),
* the received data is handled as a set of uint16_t. In this case, Size must indicate the number
* of uint16_t available through pData.
* @note When FIFO mode is enabled, the RXFNE flag is set as long as the RXFIFO
* is not empty. Read operations from the RDR register are performed when
* RXFNE flag is set. From hardware perspective, RXFNE flag and
* RXNE are mapped on the same bit-field.
* @param huart UART handle.
* @param pData Pointer to data buffer (uint8_t or uint16_t data elements).
* @param Size Amount of data elements (uint8_t or uint16_t) to be received.
* @param RxLen Number of data elements finally received
* (could be lower than Size, in case reception ends on IDLE event)
* @param Timeout Timeout duration expressed in ms (covers the whole reception sequence).
* @retval HAL status
*/
HAL_StatusTypeDef HAL_UARTEx_ReceiveToIdle(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size, uint16_t *RxLen,
uint32_t Timeout)
{
2021-08-24 10:59 PM
thanks @Community member this is very helpful
2021-08-24 11:00 PM
thanks @TDK
2021-08-25 04:15 AM
Hello,
I am facing another issue in UART_Receive_DMA();
USART_RX_BUFFER_SIZE = 10
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
Rx_ok_flag=1;
HAL_UART_Receive_DMA (&huart6, Rx_buff, USART_RX_BUFFER_SIZE);
}
I send 10 bytes of String "HIHELLOLCS" via Serial terminal(Hercules).
After sending this string , i read my Rx_buff. But my Rx_buff does not have 10 bytes of data. It's have only Three bytes.
After sending the data i am getting like this, i don't know what's happening.
Rx_buff [0] = 'H' Rx_buff [1] ='\000' Rx_buff [2] ='\000' Rx_buff [3] ='\000' Rx_buff [4] ='I' Rx_buff [5] ='\000' Rx_buff [6] ='\000' Rx_buff [7] ='\000' Rx_buff [8] ='H' Rx_buff [9] ='\000'
Thanks
Manikandan D
2021-08-25 11:52 AM
Are your DMA memory size and peripheral size both 1 byte?
2021-08-25 12:07 PM
It might be helpful to provide a more complete perspective, these code snippets lack a lot in context.
For example you'd want this flag as a volatile variable, and you'd want to copy the data to a staging buffer because the DMA can overwrite the content of the active buffer at any time.
2021-08-25 09:12 PM
Hai,
how to know the DMA memory size.
This issue not only for DMA method. I tried with Interrupt method also. But i am getting same issue.
Thanks
Manikandan D