RPi::EEPROM::AT24C32 - Read and write to the AT24C32 based EEPROM ICs
Read and write data to the AT24C32-based EEPROM Integrated Circuits.
Currently, only the actual AT24C32 that has 4096 8-bit address locations (0-4095).
0-4095
It'll work for the AT24C64 unit as well, but only half of the address space will be available. I'll update this after I get one of these units.
use RPi::EEPROM::AT24C32; my $eeprom = RPi::EEPROM::AT24C32->new( device => '/dev/i2c-1', # optional, default address => 0x57, # optional, default delay => 1 # optional, default ); # write to, and read from a block of EEPROM addresses in a loop my $value = 1; for my $memory_address (200..225){ $eeprom->write($memory_address, $value); print $eeprom->read($memory_address) . "\n"; $value++; }
Instantiates a new RPi::EEPROM::AT24C32 object, initializes the i2c bus, and returns the object.
Parameters:
All parameters are sent in as a hash.
device => '/dev/i2c-1'
Optional, String. The name of the i2c bus device to use. Defaults to /dev/i2c-1.
/dev/i2c-1
address => 0x57
Optional, Integer. The i2c address of the EEPROM device. Defaults to 0x57.
0x57
delay => 1
Optional, Integer. Due to issues on the Raspberry Pi's i2c ability to "clock stretch" the bus, with some devices a slight delay (milliseconds) must be used between write cycles. This parameter is the multiplier for said write cycle timer.
If you're frequently getting write or I/O errors when performing multiple write/reads in succession, bump this number up.
Defaults to 1.
1
Performs a single-byte read of the EEPROM storage from the specified memory location.
$addr
Mandatory, Integer. Valid values are 0-4095.
Return: The byte value located within the specified EEPROM memory register.
Writes a single 8-bit byte of data to the EEPROM memory address specified.
$byte
Mandatory, Integer. Valid values are 0-255.
0-255
Return: 0 on success, -1 on failure.
0
-1
These are methods that aren't normally required for the use of this software, but may be handy for troubleshooting or future purposes.
Sets/gets the file descriptor that our i2c initialization routine assigned to us.
$fd
Optional, Integer: This is set internally, and it would be very unwise to set it manually at any other time.
Return: The file descriptor (integer) that the ioctl() initialization routine assigned us.
ioctl()
Ensures that the EEPROM memory register address supplied as a parameter is within limits.
For write calls, ensures that the data byte supplied is within valid limits.
Steve Bertrand, <steveb at cpan.org>
<steveb at cpan.org>
Copyright 2019 Steve Bertrand.
GPL version 2+ (due to using modified GPL'd code).
1; # End of RPi::EEPROM::AT24C32
To install RPi::EEPROM::AT24C32, copy and paste the appropriate command in to your terminal.
cpanm
cpanm RPi::EEPROM::AT24C32
CPAN shell
perl -MCPAN -e shell install RPi::EEPROM::AT24C32
For more information on module installation, please visit the detailed CPAN module installation guide.