当前位置:网站首页>RK3399开发板I2C4挂载EEPROM实例
RK3399开发板I2C4挂载EEPROM实例
2022-07-25 07:59:00 【飞凌嵌入式】
飞凌嵌入式OK3399-C开发板预留出了I2C4引脚接口,位于P32插针引脚上,分别是I2C4_SCL和I2C4_SDA。小编将通过本篇文章为大家列举和说明如何使用I2C4挂载at24c08(EEPROM)芯片。

修改结果
1、修改kernel/arch/arm64/boot/dts/rockchip/OK3399.dts,添加修改如下:

2、摘除at24c08模块上的上拉电阻,飞线使用1.8V给模块供电,接入I2C4_SCL和I2C4_SDA。
修改思路
我们要添加一个I2C设备的思路为:在设备树中添加描述->在设备树描述中添加对应设备驱动->设备驱动添加到内核。
按照思路,首先要在设备树I2C4节点下添加at24c08的设备信息。在kernel/arch/arm64/boot/dts/rockchip/OK3399-C.dts文件,找到I2C4节点如下:

目前是disabled的状态,并且没有任何设备信息。添加设备信息如下:

如上图,通过设备树告诉内核,I2C4开始使用,并且挂载了一个EEPROM设备,名字叫[email protected],其使用的驱动是compatible=“”;
那么我们现在缺少这个驱动,一般的I2C设备所使用的驱动文件对应的I2C厂家会提供,如果厂家说不需要驱动等,其实不是指的真的“不需要”驱动,而是他们的设备是可以使用通用驱动的。
本文中的设备就是这样,与厂家沟通后表示没有驱动文件。那么直接在内核目录下查找eeprom、at24这样的字眼,找找看有没有对应的通用驱动文件。

可见有kernel/drivers/misc/eeprom/at24.c文件。
查看其内容是如何匹配使用这个驱动的,正常来说驱动文件中应该预留了.compatible= *** 作为设备树调用该驱动的接口,只要在设备树描述里的compatible与 驱动文件中的.compatible中描述的一致,就会匹配成功了。
但是这个at24.c中并没有.compatible,只有一个at24_ids如下其中有”24c08”:

对比同目录的at25.c文件就有.compatible没有ids。

ids中描述的也是和.compatible一样,是设备树用来识别匹配使用的,其中的三种识别匹配条件感兴趣的可以深追一下。因与本文无关,不再赘述。所以找到了对应的驱动文件,返回设备树添加描述。

现在这样是告诉了内核我要使用I2C4,我的I2C4下有个EEPROM设备,使用的是“24c08”驱动,但是还没有将”24c08”这个文件给到内核,那么接下来的目的就是把驱动编进内核。
在kernel目录下运行makemenuconfig,搜索at24,如下:

按下数字1,自动跳转到对应选项,按下y选中,保存退出。

因为makemenuconfig修改的是.config文件,而编译脚本中每次都会重新生成.config文件,所以为了让修改生效,修改编译脚本,使其不重新生成.config文件,如下:

将生成.config文件的命令注释掉,编译内核,这样就将”24c08”给到内核,也通过设备树告诉内核,I2C4下有个EEPROM设备要用“24c08”。
到此,我们的常规添加设备思路就已经完成了:在设备树中添加描述->设备树描述对应设备驱动->设备驱动添加到内核。
接下来就是编译内核,烧写boot镜像到开发板,使用i2ctool的命令进行查看,这里也不赘述i2ctool命令的具体使用方法。使用命令:i2cdetect-l 、i2cdetect-y 4。

对应的地址已经被驱动注册,但是没有生成devices下的I2C4设备,说明模块可能没有正常工作,查看模块相关信息。



模块自带I2C4上拉电阻,因为OK3399-C底板上也带有上拉电阻如下图,并且是1.8V上拉,为了电平匹配,不修改底板的状态下,使用1.8V为基准,将模块带有的上拉电阻摘除,使用1.8V配置。

再次修改设备树,添加上时钟描述和设备地址描述。

编译后,烧写内核,烧写完毕启动开发板。

识别到I2C4下的设备,然后进行读写测试即可,如下命令:
echo"hello my world" > /sys/bus/i2c/devices/1-0050/eeprom
cat/sys/bus/i2c/devices/4-0050/eeprom

至此一个新的I2C EEPROM设备添加成功,对I2C设备的读写操作也可以通过开发板中带有的i2ctool相关命令操作。
边栏推荐
- MathWorks has been in China for 15 years. What are the secrets of continuous innovation?
- pom容易忽略的问题
- Cache design in Web services (error allowed, error not allowed)
- Install homebrew, NVM and verdaccio to build a private NPM warehouse
- [QNX Hypervisor 2.2用户手册]9.3 cpu
- VS2019 C# MFC安装
- A queue of two stacks
- Using one stack to sort another stack
- Polling, interrupt, DMA and channel
- Google Earth engine - Landsat 1985-2020 ecological remote sensing index resi calculation
猜你喜欢
Technical Analysis | Doris connector combined with Flink CDC to achieve accurate access to MySQL database and table exactly once

J1 common DOS commands (P25)

IoT物联网嵌入式设备中30种常见传感器模块简介及原理讲解

纳米数据足球数据,足球赛事比分,体育数据api,卡塔尔世界杯

People who lose weight should cry: it's no good not eating food, because your brain will be inflamed

Google AI can't understand the comments of netizens, and the wrong meaning will be as high as 30%. Netizens: you don't understand my stem

【Unity入门计划】界面介绍(2)-Games视图&Hierarchy&Project&Inspector
![[unity entry program] basic concept trigger](/img/16/cd0f8ae579627fc095935195136729.png)
[unity entry program] basic concept trigger

Didi - dispatching
![[unity introduction program] basic concepts GameObject & components](/img/fc/7e0a6f057394a6fd4409a7bf518ba5.png)
[unity introduction program] basic concepts GameObject & components
随机推荐
【论文笔记】Next-ViT: Next Generation Vision Transformer for Efficient Deployment in Realistic Industrial
[unity introduction program] basic concepts - 2D collider collider 2D
[unity introduction program] basic concept - preform prefab
P1048 [noip2005 popularization group t3] drug collection
How does MTK change the boot logo?
【Unity入门计划】基本概念-触发器 Trigger
Using one stack to sort another stack
Install homebrew, NVM and verdaccio to build a private NPM warehouse
efcore在Saas系统下多租户零脚本分表分库读写分离解决方案
2-6. Automatic acquisition
Dijkstra序列(暑假每日一题 5)
When deep learning makes data sets, it specifies how many frames to extract an image from the long video to the specified file path
Big guy Qiu zhaomianjing
New version 8.6 SEO quick release system (can be built at source level)
Technical Analysis | Doris connector combined with Flink CDC to achieve accurate access to MySQL database and table exactly once
2-6.自动化采集
C# 43. 获取UDP可用端口
Recommend 7 open source projects of yyds this week
[wechat applet] global style, local style, global configuration
Problems easily ignored by POM