Part 0 : Assumptions & Disclaimers
- Freshly baked (flashed ;p) microsd card containing the latest raspbian distro (jessie as of this writing)
- RPI 3
- kernel version > 3.18 (
uname -a
should tell what is the running kernel's version)
- below instructions taken from from adafruit
solely for guiding new folks (and my own reference), no malice intended in any way
Part 1 : Setup
sudo apt-get install python-smbus
sudo apt-get install i2c-tools
Enabling kernel support (i2c is off by default) using raspi-config
raspi-config -> advanced options -> A7 i2c -> arm i2c interface enable (yes)
- raspi-config -> advanced options -> A7 i2c -> load i2c kernel module by default (yes)
reboot
Enabling device tree overlay
sudo nano /boot/config.txt
- Append the following lines
dtparam=i2c1=on
dtparam=i2c_arm=on
Part 2 : Verification
- use i2cdetect to check if the device is detected
sudo i2cdetect -y 1
detected device are indicated with addresses that are not --
Part 3 : Connecting LTC2945
There is a rather long discussion on the raspberrypi forum here
on the topic of connecting to LTC2945.
Here is the extract that is probably most relevant to the question at hand
by joan » Sat Dec 19, 2015 10:47 am
munnik wrote:
...
I2C Interface
The LTC2945 includes an I2C/SMBus-compatible interface to provide access to the onboard registers. Figure 5 shows a general data transfer format using the I2C bus. The LTC2945 is a read-write slave device and supports the SMBus Read Byte, Write Byte, Read Word and Write Word protocols. The LTC2945 also supports extended Read and Write commands that allow reading or writing more than two bytes of data. When using the Read/Write Word or extended Read and Write commands, the bus master issues an initial register address and the internal register address pointer automatically increments by 1 after each byte of data is read or written. After the register address reaches 31h, it will roll over to 00h and continue incrementing." A Stop condition resets the register address pointer to 00h. The data formats for the above commands are shown in Figures 6 to 11.
So I would guess that my original code in this post should work as expected? Is this a bug in the Linear device, I'm not an I2C expert so I'm not sure.
From memory it's more of a bug in the Pi's I2C software driver.
The problem is the handling of repeated starts.
The driver is sending start address (0x6F) write (5) stop start address (0x6f) read ... stop, it needs to send start address (0x6F) write (5) start read ... stop.
From the Linear datasheet "A Stop condition resets the register address pointer to 00h.". It's that superfluous stop which causes the problem.
The I2C module does have a combined flag which you can try setting. That is meant to permit repeated starts. I have not had reliable results when I tried using it, quite possibly my mistake.
by munnik » Sat Dec 19, 2015 12:09 pm
Great! I switched back to SMBus after:
echo -n 1 > /sys/module/i2c_bcm2708/parameters/combined
and now everything works fine, even setting the MAX and MIN values which failed before. PROBLEM SOLVED, thank you very much for your help!
Part 4 :
- If the above works, thank @joan for her help :)
Notes
- if you spot any errors or omissions, leave me a comment and I will try to address it as soon as possible