We are trying to get UART-receiver to work in interrupt mode.
Here is the code that doesn't work. Any suggestions?
UART_HandleTypeDef UartHandle;
uint8_t MyRxBuf[ 10 ], MyTxBuf[3];
int main( void ) {
uint32_t t_print;
int16_t i;
HAL_Init();
SystemClock_Config();
/* Put the USART peripheral in the Asynchronous mode (UART Mode) */
/* UART2 configured as follows:
- Word Length = 8 Bits
- Stop Bit = One Stop bit
- Parity = none
- BaudRate = 38400 baud
- Hardware flow control disabled (RTS and CTS signals) */
UartHandle.Instance = USART2;
UartHandle.Init.BaudRate = 38400;
UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
UartHandle.Init.StopBits = UART_STOPBITS_1;
UartHandle.Init.Parity = UART_PARITY_NONE;
UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
UartHandle.Init.Mode = UART_MODE_TX_RX;
UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
UartHandle.pTxBuffPtr = &MyTxBuf[ 0 ];
UartHandle.TxXferSize = 3;
UartHandle.pRxBuffPtr = &MyRxBuf[ 0 ];
UartHandle.RxXferSize = 10;
UartHandle.RxXferCount = 3;
if(HAL_UART_Init(&UartHandle) != HAL_OK) {
Error_Handler();
}
HAL_UART_Receive_IT( &UartHandle, &MyRxBuf[ 0 ], 1 ); // Needed?
/* Infinite loop */
t_print = get_RTC();
while (1) {
if( get_RTC() > t_print ) {
t_print += 2000UL; // Print buffer every 2 seconds
printf("RxCnt %d ", UartHandle.RxXferCount );
for(i=0;i<10;i++) printf("%d ", MyRxBuf[i] );
printf("\n\r");
}
}
}
