赞
踩
#include <stdio.h> #include <unistd.h> #include "ohos_init.h" #include <string.h> #include "cmsis_os2.h" #include "wifiiot_gpio.h" #include "wifiiot_gpio_ex.h" #include "wifiiot_adc.h" #include "wifiiot_errno.h" #include "wifiiot_uart.h" static const char *data = "Hello, BearPi!\r\n"; #define UART_BUFF_SIZE 1024 static void uart_task(void) { uint8_t uart_buffer[UART_BUFF_SIZE] = {0}; uint8_t *pData = uart_buffer; uint32_t ret; WifiIotUartAttribute attr = { .baudRate = 115200, .dataBits = 8, .stopBits = 1, .parity = 0, .pad = 0, }; ret = UartInit(WIFI_IOT_UART_IDX_1,&attr,NULL); if(ret != WIFI_IOT_SUCCESS) { printf("Failed to init uart! Err code = %d\n", ret); return; } printf("UART Test Start\n"); while(1) { UartWrite(WIFI_IOT_UART_IDX_1,(uint8_t *)data,strlen(data)); UartRead(WIFI_IOT_UART_IDX_1,pData,UART_BUFF_SIZE); printf("read data from uart1============>\r\n %s",pData); osDelay(100); } } static void my_led_example(void) { osThreadAttr_t attr; attr.attr_bits = 0; attr.name = "uart"; attr.cb_mem = NULL; attr.cb_size = 0; attr.priority = 24; attr.stack_size = 1024*8; if(osThreadNew((osThreadFunc_t)uart_task,NULL,&attr) == NULL) { printf("Falied to create adc_func!\n"); } } SYS_RUN(my_led_example);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。