初始化代码如下:
void uart_init(void)
{
int8_t ret1 = 0;
hi_io_set_func(HI_IO_NAME_GPIO_0, HI_IO_FUNC_GPIO_0_UART1_TXD);
hi_io_set_func(HI_IO_NAME_GPIO_1, HI_IO_FUNC_GPIO_1_UART1_RXD);
hi_uart_attribute uart1_config = {
.baud_rate = 115200, //波特率9600
.data_bits = 8, //8位数据位
.stop_bits = 1, //1位停止位
.parity = 0, //不校验
};
ret1 = hi_uart_init(HI_UART_IDX_1, &uart1_config, NULL);
if (ret1 != HI_ERR_SUCCESS)
{
printf("uart1 Initialize Failed!");
printf("unknow Error,code:%d\n", ret1);
}
/*串口2,用于与其他外设通信*/
int8_t ret2 = 0;
hi_io_set_func(HI_IO_NAME_GPIO_11, HI_IO_FUNC_GPIO_11_UART2_TXD);
hi_io_set_func(HI_IO_NAME_GPIO_12, HI_IO_FUNC_GPIO_12_UART2_RXD);
hi_uart_attribute uart2_config = {
.baud_rate = 115200, //波特率9600
.data_bits = 8, //8位数据位
.stop_bits = 1, //1位停止位
.parity = 0, //不校验
};
ret2 = hi_uart_init(HI_UART_IDX_2, &uart2_config, NULL);
if (ret2 != HI_ERR_SUCCESS)
{
printf("uart2 Initialize Failed!");
printf("unknow Error,code:%d\n", ret2);
}
}
初始化代码如下:
void uart_init(void)
{
int8_t ret1 = 0;
hi_io_set_func(HI_IO_NAME_GPIO_0, HI_IO_FUNC_GPIO_0_UART1_TXD);
hi_io_set_func(HI_IO_NAME_GPIO_1, HI_IO_FUNC_GPIO_1_UART1_RXD);
hi_uart_attribute uart1_config = {
.baud_rate = 115200, //波特率9600
.data_bits = 8, //8位数据位
.stop_bits = 1, //1位停止位
.parity = 0, //不校验
};
ret1 = hi_uart_init(HI_UART_IDX_1, &uart1_config, NULL);
if (ret1 != HI_ERR_SUCCESS)
{
printf("uart1 Initialize Failed!");
printf("unknow Error,code:%d\n", ret1);
}
/*串口2,用于与其他外设通信*/
int8_t ret2 = 0;
hi_io_set_func(HI_IO_NAME_GPIO_11, HI_IO_FUNC_GPIO_11_UART2_TXD);
hi_io_set_func(HI_IO_NAME_GPIO_12, HI_IO_FUNC_GPIO_12_UART2_RXD);
hi_uart_attribute uart2_config = {
.baud_rate = 115200, //波特率9600
.data_bits = 8, //8位数据位
.stop_bits = 1, //1位停止位
.parity = 0, //不校验
};
ret2 = hi_uart_init(HI_UART_IDX_2, &uart2_config, NULL);
if (ret2 != HI_ERR_SUCCESS)
{
printf("uart2 Initialize Failed!");
printf("unknow Error,code:%d\n", ret2);
}
}