3199 views|1 replies

110

Posts

1

Resources
The OP
 

[BearPi-HM Nano] UART test [Copy link]

According to the introduction of the Bear Pi development board and the manual of the main chip Hi3861, this chip provides three groups of UART communication interfaces, namely UART0, UART1 and UART2, of which one group UART1 is led out in E53 mode, see the following schematic diagram:

To facilitate testing, use this set of UART1 to perform serial communication testing.

B6 in the example is a demonstration of the UART communication function. Enter the B6_basic_uart directory and open the main program uart_example.c:

static void UART_Task(void)

{

uint8_t uart_buff[UART_BUFF_SIZE] = {0};

uint8_t *uart_buff_ptr = uart_buff;

uint32_t ret;

WifiIotUartAttribute uart_attr = {

//baud_rate: 9600

.baudRate = 9600,

//data_bits: 8 bits

.dataBits = 8,

.stopBits = 1,

.parity = 0,

};

//Initialize uart driver

ret = UartInit(WIFI_IOT_UART_IDX_1, &uart_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)

{

printf("========================================\r\n");

printf("************UART_example****************\r\n");

printf("========================================\r\n");

// Send data through serial port 1

UartWrite(WIFI_IOT_UART_IDX_1, (unsigned char *)data, strlen(data));

// Receive data through serial port 1

UartRead(WIFI_IOT_UART_IDX_1, uart_buff_ptr, UART_BUFF_SIZE);

printf("Uart1 read data:%s", uart_buff_ptr);

usleep(1000000);

}

}

The program is also very simple. After successfully initializing the serial port UART1, it enters a loop: write the data "Hello, BearPi!" to the serial port, and then read the data received by the serial port UART1. If we use a DuPont line to short-circuit TxD and RxD, the serial port UART1 can achieve self-transmission and self-reception, as shown in the following figure:

Modify the build.gn file in the sample directory as follows:

#"B1_basic_led_blink:led_example",

#"B2_basic_button:button_example",

#"B3_basic_pwm_led:pwm_example",

#"B4_basic_adc:adc_example",

#"B5_basic_i2c_nfc:i2c_example",

"B6_basic_uart:uart_example",

That is, comment out other example programs and remove the comment of B6.

The compilation and burning process is the same as the previous tests.

Open the serial terminal, and the program running results are shown as follows:

Serial port UART1 reads the data “Hello, BearPi!” sent by itself, thus achieving self-transmission and self-reception.

If TxD and RxD are not short-circuited, the program will run as follows:

While the program is writing data through the serial port, it is waiting for the serial port to read data, but because RxD is not connected, the data will not be read and displayed.

For the test of the communication interface I2C, please refer to the NFC test. The NFC chip uses the I2C interface, so this test will not repeat the I2C test.

This post is from ARM Technology

Latest reply

Not bad! Looking forward to the follow-up review!   Details Published on 2021-6-28 17:45

赞赏

1

查看全部赞赏

 

1942

Posts

2

Resources
2
 

Not bad! Looking forward to the follow-up review!

This post is from ARM Technology
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list