1. 程式人生 > >AliOS-Things--ESP8266-linkkitapp-串列埠(二)

AliOS-Things--ESP8266-linkkitapp-串列埠(二)

/*
 * Copyright (C) 2015-2017 Alibaba Group Holding Limited
 * 
 * 
 *   this is a uart sample from hal uart for esp8266, and the same as other chips;
 *   for esp8266 , when the port set is 1 ,then the uart1 ande uart2 is the same baud_rate , but the uart1(gpio2) is for log ;
 * 
 *   這sample是一個從hal層適配esp8266的,也許同樣適配其他晶片
 *   對於esp8266,如果設定串列埠為1,則串列埠一和串列埠零都是這個波特率,如果需要不一樣,請自行修改driver ,注意串列埠一(gpio2)是作為日誌列印。
 * 
 *   Contributor:  https://github.com/xuhongv
 * 
 * 
 */
#include <aos/aos.h> #include <hal/soc/uart.h> #include "driver/uart.h" #define HAL_WAIT_FOREVER 0xFFFFFFFFU int application_start(int argc, char *argv[]) { printf("uart sample application started...\n"); uart_config_t uartConfig; uartConfig.baud_rate = 9600; uart_dev_t uart;
uart.port = 1; //for esp8266 , when the port set is 1 ,then the uart1 ande uart2 is the same baud_rate , but the uart1 is for log uart.config = uartConfig; hal_uart_init(&uart); uint8_t receive_bytes[15]; int32_t ret = -1; uint32_t i, recv_size = 0; while (1) { ret =
hal_uart_recv_II(&uart, &receive_bytes, 15, &recv_size, HAL_WAIT_FOREVER); if ((ret == 0)) { for (i = 0; i < recv_size; i++) printf("hal_uart_recv_II ch = %d ,recv_size= %d \n", receive_bytes[i], recv_size); // en:return by the way you came ch: 原路返回資料 hal_uart_send(&uart,receive_bytes,recv_size,1000); } } aos_loop_run(); return 0; }