Device::BusPirate::Mode::I2C - use Device::BusPirate in I2C mode
Device::BusPirate::Mode::I2C
Device::BusPirate
use Device::BusPirate; my $pirate = Device::BusPirate->new; my $i2c = $pirate->enter_mode( "I2C" )->get; my $addr = 0x20; my $count = 0; while(1) { $i2c->send( $addr, chr $count )->get; my $in = ord $i2c->recv( $addr, 1 )->get; printf "Read %02x\n", $in; $count++; $count %= 255; }
This object is returned by a Device::BusPirate instance when switching it into I2C mode. It provides methods to configure the hardware, and interact with one or more I2C-attached chips.
I2C
The following methods documented with a trailing call to ->get return Future instances.
->get
Sends an I2C START bit transition
Sends an I2C STOP bit transition
Sends the given bytes over the I2C wire. This method does not send a preceding start or a following stop; you must do that yourself, or see the send and recv methods.
send
recv
Receives the given number of bytes over the I2C wire, sending an ACK bit after each one but the final, to which is sent a NACK.
A convenient wrapper around start_bit, write and stop_bit. This method sends a START bit, then an initial byte to address the slave in WRITE mode, then the remaining bytes, followed finally by a STOP bit. This is performed atomically by using the enter_mutex method.
start_bit
write
stop_bit
enter_mutex
$address should be an integer, in the range 0 to 0x7f.
$address
A convenient wrapper around start_bit, write, read and stop_bit. This method sends a START bit, then an initial byte to address the slave in READ mode, then reads the given number of bytes, followed finally by a STOP bit. This is performed atomically by using the enter_mutex method.
read
A convenient wrapper around start_bit, write, read and stop_bit. This method combines a send and recv operation, with a repeated START condition inbetween (not a STOP). It is useful when reading values from I2C slaves that implement numbered registers; sending the register number as a write, before requesting the read.
Paul Evans <leonerd@leonerd.org.uk>
To install Device::BusPirate, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Device::BusPirate
CPAN shell
perl -MCPAN -e shell install Device::BusPirate
For more information on module installation, please visit the detailed CPAN module installation guide.