通过wiringPi等library, 在user space 通过/dev/i2c来读写i2c设备的方案不在本文讨论了。

编译SENSORS_PCF8591 模块

在Default raspberryPi的内核中,pcf591模块是没有编译的。

查看drivers\hwmon\Makefile

obj-$(CONFIG_HWMON)        += hwmon.o
... obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o
...

修改arch\arm\configs\bcm2709_defconfig, 增加一行 CONFIG_SENSORS_PCF8591=m

CONFIG_HWMON=m
...
CONFIG_SENSORS_PCF8591=m

执行

make mrproper
make modules

将pcf8591.ko copy到raspberryPi板子

如果单独编译hwmon下的模块,

make modules SUBDIRS=drivers/hwmon/

install module

pi@raspberrypi:/lib/modules/4.14.48-v7+/kernel/drivers/hwmon $ sudo insmod pcf8591.ko

查看module是否install

pi@raspberrypi:/lib/modules/4.14.48-v7+/kernel/drivers/hwmon $ lsmod
Module Size Used by
pcf8591 16384 0

insmode 参数

The PCF8591 has 4 analog inputs programmable as single-ended or

differential inputs :

- mode 0 : four single ended inputs

Pins AIN0 to AIN3 are single ended inputs for channels 0 to 3

  • mode 1 : three differential inputs

    Pins AIN3 is the common negative differential input

    Pins AIN0 to AIN2 are positive differential inputs for channels 0 to 2

  • mode 2 : single ended and differential mixed

    Pins AIN0 and AIN1 are single ended inputs for channels 0 and 1

    Pins AIN2 is the positive differential input for channel 3

    Pins AIN3 is the negative differential input for channel 3

  • mode 3 : two differential inputs

    Pins AIN0 is the positive differential input for channel 0

    Pins AIN1 is the negative differential input for channel 0

    Pins AIN2 is the positive differential input for channel 1

    Pins AIN3 is the negative differential input for channel 1

/* Insmod parameters */
I2C_CLIENT_INSMOD_1(pcf8591); static int input_mode;
module_param(input_mode, int, 0);
MODULE_PARM_DESC(input_mode,
"Analog input mode:\n"
" 0 = four single ended inputs\n"
" 1 = three differential inputs\n"
" 2 = single ended and differential mixed\n"
" 3 = two differential inputs\n");

创建i2c device

查看i2c总线上的设备。 在使用中的0x68为RTC. 0x48为PCF8591

pi@raspberrypi:~ $ i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: 20 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- 48 -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
70: -- -- -- -- -- -- 76 --

创建设备

pi@raspberrypi:/sys/class/i2c-adapter/i2c-1 $ echo pcf8591 0x48 | sudo tee new_device
pcf8591 0x48
pi@raspberrypi:/sys/class/i2c-adapter/i2c-1 $ ls
1-0048 delete_device i2c-dev new_device power uevent
1-0068 device name of_node subsystem

再次查看总线,可以看到0x48设置为UU, 表示在使用中

pi@raspberrypi:/sys/class/i2c-adapter/i2c-1 $ i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: 20 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
70: -- -- -- -- -- -- 76 --

查看

pi@raspberrypi:/sys/class/i2c-adapter/i2c-1/1-0048 $ ls
driver in0_input in2_input modalias out0_enable power uevent
hwmon in1_input in3_input name out0_output subsystem

/sys Interface

The PCF8591 is plainly impossible to detect! Thus the driver won’t

even try. You have to explicitly instantiate the device at the

relevant address (in the interval [0x48..0x4f]) either through

platform data, or using the sysfs interface. See

Documentation/i2c/instantiating-devices for details.

Directories are being created for each instantiated PCF8591:

/sys/bus/i2c/devices/<0>-<1>/ where <0> is the bus the chip is

connected to (e. g. i2c-0) and <1> the chip address ([48..4f])

Inside these directories, there are such files: in0_input, in1_input,

in2_input, in3_input, out0_enable, out0_output, name

Name contains chip name.

The in0_input, in1_input, in2_input and in3_input files are RO.

Reading gives the value of the corresponding channel. Depending on the

current analog inputs configuration, files in2_input and in3_input may

not exist. Values range from 0 to 255 for single ended inputs and -128

to +127 for differential inputs (8-bit ADC).

The out0_enable file is RW. Reading gives “1” for analog output

enabled and “0” for analog output disabled. Writing accepts “0” and

“1” accordingly.

The out0_output file is RW. Writing a number between 0 and 255 (8-bit

DAC), send the value to the digital-to-analog converter. Note that a

voltage will only appears on AOUT pin if aout0_enable equals 1.

Reading returns the last value written.

Reference

https://www.kernel.org/doc/Documentation/hwmon/pcf8591

树梅派 -- 通过/sys读写ADC芯片 pcf8591的更多相关文章

  1. 树梅派配置ad-hoc网络

    树梅派配置ad-hoc网络 更新与安装 1.更改源/etc/apt/source.list: http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian ...

  2. 树梅派(Raspberry Pi 3b)安装kali linux 2.0

    最近终于入手了一枚树梅派3B,忘记是什么时候到手了,买回来,也没有激动无比,也没有心情澎湃,也就扔到床头,并没有像以前超想拥有的感觉,像是失去了对这些东西都兴趣,没有以前那么强烈了,对于这些对信仰有些 ...

  3. ARM裸板开发:07_IIC 通过IIC总线接口读写时钟芯片时间参数实现的总结

    问题一:程序直接在iRAM内部可正常执行,而程序搬移(Nand ->SDRAM)之后,就不能正常运行了 #define NAND_SECTOR_SIZE 2048 /* 读函数 */ void ...

  4. 树梅派3B kali2.0 启用SSH进行远程登录

    工具/原料 kali 2.0 ssh SSH连接工具(XShell)or PUTTY vi /etc/ssh/sshd_config 将#PasswordAuthentication no的注释去掉, ...

  5. 对ADC(DAC)的线性度(INL和DNL)的一点理解 [转]

    大家在使用ADC的时候,往往最关注位数,而对ADC的线性度往往会忽略. 其实这个线性度也是ADC非常重要的指标,ADC(或DAC,其实ADC也是由DAC组成的)线性度指标有两个: INL:翻译过来叫“ ...

  6. DSP基础学习-ADC同步采样

    DSP基础学习-ADC同步采样 彭会锋 2015-04-28 20:31:06 在DSP28027 LauchPad学习过程中,关于ADC同步采样和顺序采样的区别稍加研究了一下,发现里面还真有些门道, ...

  7. (转载)高速ADC的关键指标:量化误差、offset/gain error、DNL、INL、ENOB、分辨率、RMS、SFDR、THD、SINAD、dBFS、TWO-TONE IMD

    (一)一个基本概念 分贝(dB):按照对数定义的一个幅度单位.对于电压值,dB以20log(VA/VB)给出:对于功率值,以10log(PA/PB)给出.dBc是相对于一个载波信号的dB值:dBm是相 ...

  8. MySQL的B树索引与索引优化

    MySQL的MyISAM.InnoDB引擎默认均使用B+树索引(查询时都显示为"BTREE"),本文讨论两个问题: 为什么MySQL等主流数据库选择B+树的索引结构? 如何基于索引 ...

  9. FPGA高速ADC接口实战——250MSPS采样率ADC9481

    一.前言 最近忙于硕士毕业设计和论文,没有太多时间编写博客,现总结下之前在某个项目中用到的一个高速ADC接口设计部分.ADC这一器件经常用于无线通信.传感.测试测量等领域.目前数字系统对高速数据采集的 ...

随机推荐

  1. Caffe实战四(Caffe可视化方法)

    面对一堆文件,一行行的数据,确实很难理解深度学习相关的概念,好比训练的数据.构建的网络是怎样的?今天按照书中第16天的内容实践了一翻,终于看到了所谓的深度神经网络的模样.(参考:<深度学习 21 ...

  2. 逆序数 HDOJ 4911 Inversion

    题目传送门 题意:可以交换两个相邻的数字顺序k次,问最后逆序对最少有多少 分析:根据逆序数的定理如果逆序数大于0,那么必定存在1<=i<n使得i和i+1交换后逆序数减1假设原逆序数为cnt ...

  3. DP+高精度 URAL 1036 Lucky Tickets

    题目传送门 /* 题意:转换就是求n位数字,总和为s/2的方案数 DP+高精度:状态转移方程:dp[cur^1][k+j] = dp[cur^1][k+j] + dp[cur][k]; 高精度直接拿J ...

  4. PowerShell~文件操作和对象遍历

    ps提供了丰富的文件操作,如建立,删除,改名,移动,复制,文件夹建立,显示文件列表,同时对数组对象的遍历也很方便,如果在使用PS脚本时,希望现时传入参数,可以把参数声明为param,当然需要把它写在文 ...

  5. SpringBoot 2.x (8):模板引擎

    SpringBoot中有很多的starter:本质是多个JAR包集合 比如我们常用的: <dependency> <groupId>org.springframework.bo ...

  6. 数据库SQL server 删除一张表中的重复记录

    --建立一张表 create table cat( catId int, catName varchar(40) ) --将下边的插入语句,多执行几次. insert into catvalues(1 ...

  7. ASP.NET Web API FilterAttribute假想

    偶然的测试发现API FilterAttribute没用引用只会初始化一次 比如: 如果是 Global Action Filter, 则全局只会初始化一次 针对于不同的Controller级别的Ac ...

  8. Javaweb学习笔记6—EL表达式与JSTL及自定义标签

    今天来讲javaweb的第六阶段学习. EL表达式与JSTL及自定义标签是对上篇文章介绍的JSP的扩展,不能说是很重要的东西,但是也要了解. 老规矩,首先先用一张思维导图来展现今天的博客内容. ps: ...

  9. sql通过 openrowset查询csv文件

    两步即可完成 第一步. 创建cmmData.xml文件,并存入到能与sql服务器共享的文件夹中(如:\\10.252.21.6\sharedfolder) <?xml version=" ...

  10. SEO 第三章

    SEO第三章 本次课目标: 1.  掌握关键词的选取方法 2.  掌握关键词的竞争强度分析 3.  掌握关键词的拓展方法 一.关键词的选取 选择关键词的时候可以根据公司网站的定位,围绕公司的主营产品或 ...