树莓派开发之旅 (八)【串口通讯】

目录

【串口简介】

【开机串口登录】

【使用串口开发】

        (一)环境配置

        (二)demo


【串口简介】

树莓派:USB串口线控制树莓派(无显示器)_韩大狗的博客-CSDN博客

【开机串口登录】

        1.打开SD卡根目录的"config.txt"文件,在最后添加下面命令

dtoverlay=pi3-miniuart-bt

        2.打开SD卡根目录的"cmdline.txt"文件,将原有内容替换为下面命令

# 原内容:console=serial0,115200 console=tty1 root=PARTUUID=8660dfdf-02 rootfstype=ext4 fsck.repair=yes rootwait quiet splash plymouth.ignore-serial-consoles

# 新内容
dwc_otg.lpm_enable=0 console=tty1 console=serial0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

        3.通过串口工具查看启动内容和登录

【使用串口开发】

        (一)环境配置

        1.打开SD卡根目录的"cmdline.txt"文件,删除【】和【】之间的内容

dwc_otg.lpm_enable=0 【console=ttyAMA0,115200】 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

        buster系统的是

dwc_otg.lpm_enable=0 console=tty1 console=serial0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

           即替换为

dwc_otg.lpm_enable=0 console=tty1  root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

        2.若有inittab文件

        /*修改 inittab文件 */
        >cd /etc/
        >sudo vim inittab

        注释掉最后一行内容:,在前面加上 # 号
        #T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

        3.重启

        (二)demo

#include<wiringPi.h>
#include<wiringSerial.h>
int main()
{
	int fd;
	if(wiringPiSetup()==-1)	{
		return -1;
	}
	fd = serialOpen("/dev/ttyAMA0",9600);
	while(1)
	{
			serialPuts(fd," ZZQ ");
			delayMicroseconds(1000000);
	}
	return 0;
}
gcc 4_serial.c -lwiringPi
./a.out 

 https://www.cnblogs.com/lulipro/p/5992172.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值