怎样才能完成 收或发 呢?
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)
{
static signed portBASE_TYPE xHigherPriorityTaskWoken;
if(UartHandle->Instance == USART1)
{
xQueueSendFromISR(UART1_RX_QueueHandle,&UART1_RX_DATA,0);
HAL_UART_Receive_IT(&huart1,&UART1_RX_DATA,1);
}
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
//串口1发送中断回掉函数
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *UartHandle)
{
static signed portBASE_TYPE xHigherPriorityTaskWoken;
if(UartHandle->Instance == USART1)
{
xSemaphoreGiveFromISR(UART1_TX_semHandle_Mutex, &xHigherPriorityTaskWoken);
}
portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
}
void Send_TX_Queue(void)
{
uint8_t i;
if(xSemaphoreTake(UART1_TX_semHandle_Mutex,portMAX_DELAY))
{
for(i = 1;i<=3; i++)
xQueueSend(UART1_TX_QueueHandle,&i,0);
xSemaphoreGive(UART1_TX_semHandle_Mutex);
}
}
#endif
void COM_task(void *argument)
{
TickType_t xLastWakeTime;
uint16_t counter;
// uint8_t UART1_RX_DATA_TEMP = 0;
// uint8_t UART1_TX_DATA_TEMP = 0;
uint8_t TX_buf[1000];
const TickType_t xFrequency = 500; // ms
xLastWakeTime = xTaskGetTickCount();
xSemaphoreGive(UART1_TX_semHandle_Mutex); //信号量使用前先释放
IO_OUT(); //将PA9配置为输出
for(;;)
{
/* ----------------------------串口发送处理-----------------------------*/
// if(xSemaphoreTake(UART1_TX_semHandle_Mutex,0)) //获取到发送信号量
// {
//
// }
vTaskDelayUntil( &xLastWakeTime, xFrequency );
Send_TX_Queue();
counter = 0;
while(xQueueReceive(UART1_TX_QueueHandle,TX_buf +counter,0))
{
counter++;
if(counter >= 1000)
break;
}
HAL_UART_Transmit_IT(&huart1,TX_buf,counter);
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>