I am trying to send hex values to the Uart terminal, but I am getting wrong values or nothing at terminal. I am getting the characters ok. I am using DMA and interrupt (IRQ_Handler), and STMCUBE MX to generate DMA init and uart codes. Please help.
I am using below code;
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
{
if (huart->Instance == USART3)
{
oldPos = newPos; // Update the last position before copying new data
// If the data is large and it is about to exceed the buffer size, we have to route it to the start of the buffer
// This is to maintain the circular buffer
// The old data in the main buffer will be overlapped
if (oldPos+Size > MainBuf_SIZE) // If the current position + new data size is greater than the main buffer
{
uint16_t datatocopy = MainBuf_SIZE-oldPos; // find out how much space is left in the main buffer
memcpy ((uint8_t *)MainBuf+oldPos, RxBuf, datatocopy); // copy data in that remaining space
oldPos = 0; // point to the start of the buffer
memcpy ((uint8_t *)MainBuf, (uint8_t *)RxBuf+datatocopy, (Size-datatocopy)); // copy the remaining data
newPos = (Size-datatocopy); // update the position
}
// if the current position + new data size is less than the main buffer copy the data into the buffer and update the position
else
{
memcpy ((uint8_t *)MainBuf+oldPos, RxBuf, Size);
newPos = Size+oldPos;
}
// start the DMA again
HAL_UARTEx_ReceiveToIdle_DMA(&huart3, (uint8_t *) RxBuf, RxBuf_SIZE);
__HAL_DMA_DISABLE_IT(&hdma_usart3_rx, DMA_IT_HT);
}
}
