Linux Kernel 4.19+内核使用GPIO模拟I2C的方法

1.修改内核配置文件,使内核支持GPIO模拟I2C

复制代码
//开启方式
make menuconfig
Device Drivers --->
	<*> I2C support  --->
		I2C Hardware Bus support  ---> 
			<*> GPIO-based bitbanging I2C

2.对应的dts里面增加GPIO模拟I2C的设备树

复制代码
注意头文件:#include <dt-bindings/gpio/gpio.h>
	i2c@0 {
		compatible = "i2c-gpio";
		sda-gpios = <&gpio_chip16 3 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
		scl-gpios = <&gpio_chip16 4 (GPIO_ACTIVE_HIGH|GPIO_OPEN_DRAIN)>;
		i2c-gpio,delay-us = <2>;	/* ~100 kHz */
		#address-cells = <0>;
		#size-cells = <0>;
	};

编译后烧写,会发现/dev下多了一个i2c总线,多出来的那个就是了。

相关推荐
释怀不想释怀3 分钟前
Linux(复习常见命令)
linux·运维·服务器
_F_y6 分钟前
负载均衡在线oj(文件版)
linux·运维·负载均衡
Chase_______10 分钟前
【Linux指南】:vi编辑器
linux·运维·编辑器
礼拜天没时间.17 分钟前
【生产级实战】Linux 集群时间同步详解(NTP + Cron,超详细)
linux·运维·服务器·时间同步·cron·ntp
艾莉丝努力练剑18 分钟前
【Linux进程控制(一)】进程创建是呼吸,进程终止是死亡,进程等待是重生:进程控制三部曲
android·java·linux·运维·服务器·人工智能·安全
NEAI_N18 分钟前
嵌入式 Linux 中 system() 返回值的正确判定
linux·运维·服务器
Jason_zhao_MR21 分钟前
米尔T113核心板的农机中控屏显方案解析
linux·嵌入式硬件·嵌入式·交互
CodeAllen嵌入式30 分钟前
Rust 正式成为 Linux 永久核心语言
linux·开发语言·rust
水天需01042 分钟前
HISTCONTROL 介绍
linux
南工孙冬梅1 小时前
Linux中安装配置nfs
linux·运维·php