3. 在MDK中编写、编译、下载用户代码
编写查询模式发送和接收代码
编写 main 函数如下:
int main(void)
{
/* USER CODE BEGIN 1 */
char str[12] = "Hello World\n";
char recv_buf[12] = {0};
/* USER CODE END 1 */
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
HAL_UART_Transmit(&huart1, (uint8_t*)str, 12, 0xFFFF);
/* USER CODE END 2 */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
//接收12个字节的数据,不超时
if(HAL_OK == HAL_UART_Receive(&huart1, (uint8_t*)recv_buf, 12, 0xFFFF))
{
//将接收到的数据发送
HAL_UART_Transmit(&huart1, (uint8_t*)recv_buf, 12, 0xFFFF);
}
}
/* USER CODE END 3 */
}
|