2020-10-09 04:03 AM
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");
}
}
}
2020-10-09 06:40 AM
Are you initializing pins?
Does your interrupt handler call HAL_UART_IRQHandler?
2020-10-14 12:56 AM
Hello,
Sorry for delay in answer.
We don't know how to do that. Could you give example of how to call HAL_UART_IRQHandler?
2020-10-14 06:29 AM
Generate code from CubeMX and it will (probably) do this for you. Or check out a UART interrupt example in the appropriate cube repository.