Debian Codegraph @

README

raw
1 NAME
2
3 Device::I2C - Control and read hardware devices with i2c(SMBus)
4
5 VERSION
6
7 version 0.06
8
9 SYNOPSIS
10
11 use Device::I2C;
12 use Fcntl;
13 $dev = Device::I2C->new('/dev/i2c-1', O_RDWR);
14 $dev->checkDevice(0x4c);
15 print $dev->readByteData(0x20);
16
17 DESCRIPTION
18
19 This is a perl interface to I2C interface using libi2c-dev library.
20
21 Prerequisites:
22
23 For Debian and derivative distros(including raspbian) use the following
24 to install dependencies:
25
26 sudo apt-get install libi2c-dev i2c-tools build-essential
27
28 If you are using Angstrom Linux use the following:
29
30 opkg install i2c-tools
31 opkg install i2c-tools-dev
32
33 For ArchLINUX use the following steps:
34
35 pacman -S base-devel
36 pacman -S i2c-tools
37
38 Special Instructions for enabling the I2C driver on a Raspberry Pi:
39
40 You will need to comment out the driver from the blacklist. currently
41 the I2C driver isn't being loaded.
42
43 sudo vim /etc/modprobe.d/raspi-blacklist.conf
44
45 Replace this line
46
47 blacklist i2c-bcm2708
48
49 with this
50
51 #blacklist i2c-bcm2708
52
53 You now need to edit the modules conf file.
54
55 sudo vim /etc/modules
56
57 Add these two lines;
58
59 i2c-dev
60 i2c-bcm2708
61
62 Now run this command(replace 1 with 0 for older model Pi)
63
64 sudo i2cdetect -y 1
65
66 If that doesnt work on your system you may alternatively use this:
67
68 sudo i2cdetect -r 1
69
70 you should now see the addresses of the i2c devices connected to your
71 i2c bus
72
73 METHODS
74
75 fileError
76
77 returns IO::Handle->error() for the device handle since the last
78 clearerr
79
80 checkDevice
81
82 $self->checkDevice($register_address)
83
84 Check device
85
86 selectDevice
87
88 $self->selectDevice($register_address)
89
90 Select device
91
92 writeQuick
93
94 $self->writeQuick($value)
95
96 This sends a single bit to the device, at the place of the Rd/Wr bit.
97
98 readByte
99
100 $self->readByte()
101
102 This reads a single byte from a device, without specifying a device
103 register. Some devices are so simple that this interface is enough; for
104 others, it is a shorthand if you want to read the same register as in
105 the previous I2C command
106
107 writeByte
108
109 $self->writeByte()
110
111 This operation is the reverse of readByte: it sends a single byte to a
112 device.
113
114 readByteData
115
116 $self->readByteData($register_address)
117
118 This reads a single byte from a device, from a designated register. The
119 register is specified through the Comm byte.
120
121 writeByteData
122
123 $self->writeByteData($register_address,$value)
124
125 This writes a single byte to a device, to a designated register. The
126 register is specified through the Comm byte. This is the opposite of
127 the Read Byte operation.
128
129 readNBytes
130
131 $self->readNBytes($lowest_byte_address, $number_of_bytes);
132
133 Read together N bytes of Data in linear register order. i.e. to read
134 from 0x28,0x29,0x2a
135
136 $self->readNBytes(0x28,3);
137
138 readWordData
139
140 $self->readWordData($register_address)
141
142 This operation is very like Read Byte; again, data is read from a
143 device, from a designated register that is specified through the Comm
144 byte. But this time, the data is a complete word (16 bits).
145
146 writeWordData
147
148 $self->writeWordData($register_address,$value)
149
150 This is the opposite of the Read Word operation. 16 bits of data is
151 written to a device, to the designated register that is specified
152 through the Comm byte.
153
154 processCall
155
156 $self->processCall($register_address,$value)
157
158 This command selects a device register (through the Comm byte), sends
159 16 bits of data to it, and reads 16 bits of data in return.
160
161 writeBlockData
162
163 $self->writeBlockData($register_address, $values)
164
165 Writes a maximum of 32 bytes in a single block to the i2c device. The
166 supplied $values should be an array ref containing the bytes to be
167 written.
168
169 The register address should be one that is at the beginning of a
170 contiguous block of registers of equal length to the array of values
171 passed. Not adhering to this will almost certainly result in unexpected
172 behaviour in the device.
173
174 readBlockData
175
176 $self->readBlockData($register_address, $numBytes)
177
178 Read $numBytes form the given register address, data is returned as
179 array
180
181 The register address is often 0x00 or the value your device expects
182
183 common usage with micro controllers that receive and send large amounts
184 of data: they almost always needs a 'command' to be written to them
185 then they send a response: e.g: 1) send 'command' with writeBlockData,
186 or writeByteData, for example 'get last telegram' 2) read 'response'
187 with readBlockData of size $numBytes, controller is sending the last
188 telegram
189
190 DEMOLISH
191
192 Destructor
193
194 CONSTANTS
195
196 I2C_SLAVE
197
198 I2C_SLAVE_FORCE
199
200 CREATING YOUR OWN CHIPSET DRIVERS
201
202 Writing your own chipset driver for your own i2c devices is quiet
203 simple. You just need to know the i2c address of your device and the
204 registers that you need to read or write. Example in the
205 Device::I2C::ADV7611.
206
207 NOTES
208
209 Based on the Device::SMBus without Moo. On my device Moo based script
210 started 5 second.
211
212 The SMBus was defined by Intel in 1995. It carries clock, data, and
213 instructions and is based on Philips' I2C serial bus protocol. Its
214 clock frequency range is 10 kHz to 100 kHz. (PMBus extends this to 400
215 kHz.) Its voltage levels and timings are more strictly defined than
216 those of I2C, but devices belonging to the two systems are often
217 successfully mixed on the same bus. SMBus is used as an interconnect in
218 several platform management standards including: ASF, DASH, IPMI.
219
220 USAGE
221
222 * This module provides a simplified object oriented interface to the
223 libi2c-dev library for accessing electronic peripherals connected on
224 the I2C bus.
225
226 SEE ALSO
227
228 * Device::SMBus
229
230 * Device::I2C::ADV7611
231
232 * IO::File
233
234 * Fcntl
235
236 SUPPORT
237
238 Bugs / Feature Requests
239
240 Please report any bugs or feature requests through github at
241 https://github.com/sv99/perl-device-i2c/issues. You will be notified
242 automatically of any progress on your issue.
243
244 Source Code
245
246 This is open source software. The code repository is available for
247 public review and contribution under the terms of the license.
248
249 https://github.com/sv99/perl-device-i2c
250
251 git clone git://github.com/sv99/perl-device-i2c.git
252
253 AUTHOR
254
255 Slava Volkov <[email protected]>
256
257 CONTRIBUTOR
258
259 Slava Volkov <svolkov att cpan dott org>
260
261 COPYRIGHT AND LICENSE
262
263 This software is copyright (c) 2016 by Slava Volkov.
264
265 This is free software; you can redistribute it and/or modify it under
266 the same terms as the Perl 5 programming language system itself.
267