cancel
Showing results for 
Search instead for 
Did you mean: 

Only receive one byte of string in UART

AKhot.1
Senior
I am not able to receive the full string in the RDR resgister. eg. If I am transmitting "hello" I am receiving only "h".
 
How to get a full string? Can anyone please help?
 
uint8_t Temp;
 
 while( !( USART2->ISR & USART_ISR_RXNE ) ) {
 
  Temp = USART2->RDR;
  HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);
  
 };
1 ACCEPTED SOLUTION

Accepted Solutions

> I running the code in debug mode to analyze everything.

Don't observe UART registers using debugger while it's running.

JW

View solution in original post

3 REPLIES 3
AKhot.1
Senior

I even tried the interrupt and the DMA approach but I am not getting it is still not working. I running the code in debug mode to analyze everything. I am giving input from hercules software. But nothing is working. The RxBuffer is showing 0 only. Can anyone please help

HAL_UART_Receive_DMA(&huart2,RxBuffer,3);
__HAL_UART_ENABLE_IT(&huart2, UART_IT_IDLE);
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);

 

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){
 
HAL_UART_Receive_DMA(&huart2,RxBuffer,3);
 
}
 
void USART2_IRQHandler(void)
{
  /* USER CODE BEGIN USART2_IRQn 0 */
if(__HAL_UART_GET_FLAG(&huart2,UART_FLAG_IDLE))
{
HAL_UART_DMAStop(&huart2);
//Calculate the length of the received data
RxLength= 3 - __HAL_DMA_GET_COUNTER(&hdma_usart2_rx);
//Restart to start DMA transmission of 255 bytes of data at a time
HAL_UART_Receive_DMA(&huart2, (uint8_t*)RxBuffer, 3);
}
  /* USER CODE END USART2_IRQn 0 */
  HAL_UART_IRQHandler(&huart2);
  /* USER CODE BEGIN USART2_IRQn 1 */
 
  /* USER CODE END USART2_IRQn 1 */
}

 

> I running the code in debug mode to analyze everything.

Don't observe UART registers using debugger while it's running.

JW

AKhot.1
Senior

You are right, debug mode made problems to the register or even say HAL_Receive_IT/HAL_Receive_DMA functions.