【RT_thread英飞凌开发板】2.uart通信

1.硬件连接

uart5

rx:11.0
tx:11.1

2.rt-thread settings

在硬件中选择uart5,保存退出
在这里插入图片描述修改uart_config.h

#if defined(BSP_USING_UART5)
#ifndef UART5_CONFIG
#define UART5_CONFIG                            \
    {                                           \
        .name = "uart5",                        \
        .tx_pin = P11_1,                         \
        .rx_pin = P11_0,                         \
        .usart_x = SCB5,                        \
        .intrSrc = scb_5_interrupt_IRQn,        \
        .userIsr = uart_isr_callback(uart5),    \
        .UART_SCB_IRQ_cfg = &UART5_SCB_IRQ_cfg, \
    }
    void uart5_isr_callback(void);
#endif /* UART5_CONFIG */
#endif /* BSP_USING_UART5 */

3.相关接口

rt_device_find()
rt_device_open(rt_device_t dev, rt_uint16_t oflag)

oflag 定义在rtdef.h中
#define RT_DEVICE_FLAG_INT_RX 0x100 //中断模式
#define RT_DEVICE_FLAG_DMA_RX 0x200 //RxDMA
#define RT_DEVICE_FLAG_INT_TX 0x400 /**< INT mode on Tx */
#define RT_DEVICE_FLAG_DMA_TX

rt_device_read() 读取数据
rt_device_write() 写入数据
rt_device_control() 控制设备
rt_device_set_rx_indicate() 设置接收回调函数
rt_device_set_tx_indicate() 设置发送完回调函数
rt_device_close()

4.发送数据

void uart5_init(void){
    serial = rt_device_find(UART_NAME);
    rt_device_open(serial,RT_DEVICE_FLAG_INT_RX);
    rt_device_write(serial,0,str,(sizeof(str)-1));//会乱码
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值