简单测试串口打印
主函数前定义
#define SAMPLE_UART_NAME "uart2" /* 串 口 设 备 名 称 */
static rt_device_t serial; /* 串 口 设 备 句 柄 */
char str[] = "hello RT-Thread!\r\n"; /* 要发送的数据 */
主函数内
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT; /* 配 置 默 认 参 数 */
/* 查 找 串 口 设 备 */
serial = rt_device_find(SAMPLE_UART_NAME);
/* 以 中 断 接 收 及 轮 询 发 送 模 式 打 开 串 口 设 备 */
rt_device_open(serial, RT_DEVICE_FLAG_INT_RX);
//通过config结构体来配置 串口参数
config.baud_rate = BAUD_RATE_115200;
config.data_bits = DATA_BITS_8;
config.stop_bits = STOP_BITS_2;
config.parity = PARITY_NONE;
/* 打 开 设 备 后 才 可 修 改 串 口 配 置 参 数 *

最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



