HAT EEPROM Read/write, configuration for RPi B+, RPi 2

This article is more of a mental note than anything, and perhaps something others will find useful. I spent a couple hours with my strongest google-fu, some hardware, and better things to do than getting a memory chip programmed.

Introduction

The new Raspberry Pi B+ and it’s younger brother, the Raspberry Pi 2, have a breakout of the second i2c interface available on the Broadcom 2835 and 2836 chips. The interface is available on pins 28 and 29. While technically you could access it on previous versions, there weren’t jumper pins, and it was, well, harder. Still, even here the installation seemed unnecessarily complicated, if for no other reason than the information was spread across eighteen forum posts with a nearly broken forum board search feature.

Device Trees

The new RPi kernel uses what are referred to as Device Trees that load modules selectively at boot. This is in contrast to the previous versions, which used a blacklist to selectively disable devices. We won’t get into the pros and cons of this approach versus the other, but needless to say, when folks in userland upgraded their kernels, all of these things — SPI, I2C, etc, — stopped working. Big f**king oops for usability, guys.

Enable the I2C buses

Go to the file /boot/config.txt. At the end, find the lines (or add them yourself, that say:

dtparam=i2c_arm=on
dtparam=i2c_vc=on
dtparam=spi=on

Make sure they are uncommented. In order, these will enable i2c-1, i2c-0, and SPI. You have to be careful with i2c-0, as it can interfere with your GPU, specifically your camera. You have been warned.

Now, after the above, give it a good reboot. Now, when you give it an ls /dev,  you should get entries that look like:

i2c-0
i2c-1
spidev0.0
spidev0.1

You are now most of the way there! Now, one note before we move on: If you have used i2c devices before, you know that the convenient utility i2cdetect will typically list out all devices on the bus for you very nicely. Note that this is NOT the case for memory devices on i2c-0. If you take the device on i2c-1 that happily reads address 50 and put it on i2c-0, it will not respond. The script below, however, will tell you whether or not you have an EEPROM on your bus.

Reading/writing your EEPROM

Ok, well if your device doesn’t announce itself like other i2c devices, how do we read and write it? Good question. First, download the EEPROM utilities from the git repo: https://github.com/raspberrypi/hats/tree/master/eepromutils

Next — remember that in order to write to your EEPROM, you will need to make sure that the write-protect pin is either floating (defaults to pulled-down), or has been jumpered to ground. See circuit here: https://github.com/raspberrypi/hats/blob/master/eeprom-circuit.png

Finally, build yourself some binary data images by editing settings text file and using eepmake.c, and drop it onto your EEPROM using eepflash.sh, which you can also use to check your work. The docs on this stuff are good, so I won’t waste time repeating that info here.

Happy HATting !

C

P.S. If and when we figure out how you’re supposed to access the stuff in userland, we’ll let you know!!

 

One thought on “HAT EEPROM Read/write, configuration for RPi B+, RPi 2”

  1. I feel the pain on searching across 18 different forum posts! Thanks for the clarity on another improvement in RPi.

Leave a Reply

Your email address will not be published. Required fields are marked *