当前位置:网站首页>RT thread studio learning (VII) using multiple serial ports
RT thread studio learning (VII) using multiple serial ports
2022-06-12 07:04:00 【iqiaoqiao】
RT-Thread Studio Study ( 7、 ... and ) Use multiple serial ports
brief introduction
This article will be based on STM32F407VET How to introduce the chip RT-Thread Studio Use... In a development environment UART1、UART2、UART3 and UART6 Multiple serial ports .
Can make UART1
In New RT-Thread Project time , You can directly select the console serial port as UART1, see RT-Thread Studio Learning to use an external clock system –> newly build RT-Thread project
Add serial port
modify board.h macro , Add macro definitions of related serial ports BSP_USING_UARTx And modify the pin information , As shown in the figure below 
Compile and download the program , Input at the console list_device Command to see that four serial ports have been registered .
test
stay application New under the directory uart_sample.c Source file , As shown below 
uart_sample.c The contents of the document are as follows :
/*
* Program listing : This is a A serial port Device usage routines
* Routine exported uart_sample Command to control terminal
* Command call format :uart_sample uart2
* Command interpretation : The second parameter of the command is the serial port device name to be used , If it is blank, the default serial port device will be used
* Program function : Output string through serial port "hello RT-Thread!"
*/
#include <rtthread.h>
#define SAMPLE_UART_NAME "uart2"
static rt_device_t serial;
static int uart_sample(int argc, char *argv[])
{
rt_err_t ret = RT_EOK;
char uart_name[RT_NAME_MAX];
char str[] = "hello RT-Thread!\r\n";
if (argc == 2)
{
rt_strncpy(uart_name, argv[1], RT_NAME_MAX);
}
else
{
rt_strncpy(uart_name, SAMPLE_UART_NAME, RT_NAME_MAX);
}
/* Find the serial port device in the system */
serial = rt_device_find(uart_name);
if (!serial)
{
rt_kprintf("find %s failed!\n", uart_name);
return RT_ERROR;
}
/* Open the serial device in interrupt receiving and polling sending mode */
ret = rt_device_open(serial, RT_DEVICE_FLAG_INT_RX);
if (ret != RT_EOK)
{
rt_kprintf("open device failed\r\n");
return -RT_ERROR;
}
/* Send string */
rt_size_t send_len = 0;
send_len = rt_device_write(serial, 0, str, (sizeof(str) - 1));
if (send_len != sizeof(str) - 1)
{
rt_kprintf("send data failed\r\n");
return -RT_ERROR;
}
/* Turn off the device */
ret = rt_device_close(serial);
if (ret != RT_EOK)
{
rt_kprintf("close device failed\r\n");
return -RT_ERROR;
}
rt_kprintf("serial device test successful\r\n");
return RT_EOK;
}
/* Export to msh In the command list */
MSH_CMD_EXPORT(uart_sample, uart device sample);
Compile and download the program .
Enter in the console uart_sample command , Can be in UART2 received hello RT-Thread!.
Enter in the console uart_sample uart3 command , Can be in UART3 received hello RT-Thread!.
Reference material
边栏推荐
- sql server2019安装到这步无法进行下一步了,如何解决?
- 【图像去噪】基于偏微分方程(PDE)实现图像去噪附matlab代码
- Noi openjudge computes the n-th power of 2
- Scons编译IMGUI
- June 9th training day - bit operation
- Freshmen are worried about whether to get a low salary of more than 10000 yuan from Huawei or a high salary of more than 20000 yuan from the Internet
- 应届生苦恼:是去华为拿1万多低薪,还是去互联网拿2万多高薪
- leetcode:890. 查找和替换模式【两个dict记录双射(set)】
- 数据库语法相关问题,求解一个正确语法
- Bid farewell to the charged xshell, and the free function of tabby is more powerful
猜你喜欢

VSCode常用插件

Junior high school education, less than 3k, to 30k+ monthly salary, how wonderful life is without restrictions

leetcode:剑指 Offer 67. 把字符串转换成整数【模拟 + 分割 +讨论】

Scons compiling imgui

leetcode:剑指 Offer 63. 股票的最大利润【记录前缀最小和 or 无脑线段树】

How to build your own website (using the pagoda panel)

SQL Server 2019 installation error. How to solve it

The second revolution of reporting tools

2 variables and basic types

sql server2019安装到这步无法进行下一步了,如何解决?
随机推荐
Leetcode: Sword finger offer 67 Convert string to integer [simulation + segmentation + discussion]
When SQL server2019 is installed, the next step cannot be performed. How to solve this problem?
I met 15 people recently and found that I couldn't answer the basic question of this test
platform driver
Meituan won the first place in fewclue in the small sample learning list! Prompt learning+ self training practice
美团获得小样本学习榜单FewCLUE第一!Prompt Learning+自训练实战
Set judge the existence of intersection
1. Foundation of MySQL database (1- installation and basic operation)
Zhang Chi's class: Notice on the time of CAQ Six Sigma test in 2022
Idea common shortcut keys
[image denoising] image denoising based on partial differential equation (PDE) with matlab code
Matlab 6-DOF manipulator forward and inverse motion
5、 El expression & JSTL tag library
Recommend 17 "wheels" to improve development efficiency
D cannot use a non CTFE pointer
VSCode常用插件
Kali and programming: how to quickly build the OWASP website security test range?
Zhang Chi: is process a panacea?
The fifth day of June training - double pointer
六月集训 第五天——双指针