|
修改如下的方法,通过串口终端发送的消息始终到不了接收中断,请问下是需要什么额外的配置,感谢!
#define REC_LENGTH 1
extern uint8_t rDataBuffer[REC_LENGTH];
static void MX_USART1_UART_Init(void)
{
huart1.Instance = USART1;
huart1.Init.BaudRate = 115200;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
/* enable usart1 irq interrupt init*/
//HAL_NVIC_SetPriority(USART1_IRQn, 4, 0);
//HAL_NVIC_EnableIRQ(USART1_IRQn);
#if 1
//enable uart interrupt
if (HAL_OK == HAL_UART_Receive_IT(&huart1,(uint8_t *)rDataBuffer,REC_LENGTH)){
printf("uart interrupt receive success.\n");
}
#endif//
printf("/******************************************************************/\n");
printf("/********More Information Please Visit Our Website*************/\n");
printf("/************************www.51uwb.cn**************************/\n");
printf("/*********************FM Version F4-V1.0************************/\n");
printf("/******************************************************************/\n");
}
然后在HAL_UART_RxCpltCallback的中断方法里面使用rDataBuffer ,但是这个中断就没有进来,很奇怪,请教下是什么原因,非常感谢!
uint8_t rDataBuffer[1]; // RX Data buffer
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
uint8_t rDataCount = 0; // count Data bytes
uint8_t rDataFlag = 0; // waitting complete RX date having been send
/* Prevent unused argument(s) compilation warning */
UNUSED(huart);
/* NOTE: This function should not be modified, when the callback is needed,
the HAL_UART_RxCpltCallback could be implemented in the user file
*/
//while(HAL_UART_Receive_IT(huart, rDataBuffer, 1) != HAL_OK); // Wait completly receive 1 byte data, and put data in rDataBuffer
printf("%c", rDataBuffer[0]);
HAL_UART_Receive_IT(huart, rDataBuffer, 1);
}
|
|