首先我在F030系列生成的代码中,没有看到回调函数的调用.HAL_StatusTypeDef HAL_UART_Receive_IT(UART_HandleTypeDef *huart, uint8_t *pData, uint16_t Size){ /* Check that a Rx process is not already ongoing */ if(huart->RxState == HAL_UART_STATE_READY) { if((pData == NULL ) || (Size == 0U)) { return HAL_ERROR; }
/* In case of 9bits/No Parity transfer, pData buffer provided as input paramter should be aligned on a u16 frontier, as data to be received from RDR will be handled through a u16 cast. */ if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE)) { if((((uint32_t)pData)&1U) != 0U) { return HAL_ERROR; } }
/* Process Locked */ __HAL_LOCK(huart);
huart->pRxBuffPtr = pData; huart->RxXferSize = Size; huart->RxXferCount = Size;
/* Computation of UART mask to apply to RDR register */ UART_MASK_COMPUTATION(huart);
huart->ErrorCode = HAL_UART_ERROR_NONE; huart->RxState = HAL_UART_STATE_BUSY_RX;
/* Process Unlocked */ __HAL_UNLOCK(huart);
/* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */ SET_BIT(huart->Instance->CR3, USART_CR3_EIE);
/* Enable the UART Parity Error and Data Register not empty Interrupts */ SET_BIT(huart->Instance->CR1, USART_CR1_PEIE | USART_CR1_RXNEIE);
return HAL_OK; } else { return HAL_BUSY; }}
然后我在while循环之前开启中断 HAL_UART_Receive_IT(&huart2,Rx_Buf,1); 确定Rx_Buf可以接到数据,但是我在回调函数里转存数据的时候,就无法转存过去void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart){ Zigbee_Buf[R_Count++]=Rx_Buf[0]; HAL_UART_Receive_IT(&huart2,Rx_Buf,1);}Zigbee_Buf这个数组里一直没数据...而且我只能接收到第一次发送的一个字节的数据,第二次发另外的数据就接收不到了,..不知道问题出在哪里了.有没有人懂这个的,..点拨一下
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
调用回调函数的是在这个函数里面
HAL_StatusTypeDef UART_Receive_IT(UART_HandleTypeDef *huart)
{
uint16_t* tmp;
uint16_t uhMask = huart->Mask;
uint16_t uhdata;
/* Check that a Rx process is ongoing */
if(huart->RxState == HAL_UART_STATE_BUSY_RX)
{
uhdata = (uint16_t) READ_REG(huart->Instance->RDR);
if ((huart->Init.WordLength == UART_WORDLENGTH_9B) && (huart->Init.Parity == UART_PARITY_NONE))
{
tmp = (uint16_t*) huart->pRxBuffPtr ;
*tmp = (uint16_t)(uhdata & uhMask);
huart->pRxBuffPtr +=2U;
}
else
{
*huart->pRxBuffPtr++ = (uint8_t)(uhdata & (uint8_t)uhMask);
}
if(--huart->RxXferCount == 0U)
{
/* Disable the UART Parity Error Interrupt and RXNE interrupt*/
CLEAR_BIT(huart->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
/* Disable the UART Error Interrupt: (Frame error, noise error, overrun error) */
CLEAR_BIT(huart->Instance->CR3, USART_CR3_EIE);
/* Rx process is completed, restore huart->RxState to Ready */
huart->RxState = HAL_UART_STATE_READY;
HAL_UART_RxCpltCallback(huart);
return HAL_OK;
}
return HAL_OK;
}
else
{
/* Clear RXNE interrupt flag */
__HAL_UART_SEND_REQ(huart, UART_RXDATA_FLUSH_REQUEST);
return HAL_BUSY;
}
}
那个是回调函数,HAL库的特 {MOD}机制吧,你这种库函数的不知道能不能兼容,其他没问题的话,也许就是不能兼容
一周热门 更多>