I am trying to use python-smbus on a raspberry Pi to communicate with the MMA7660 accelerometer chip using I2C.
In the code below, I read the registers 0x00, 0x01, 0x02 and 0x03 of the chip, and I get the exact values ββfor all. Looking at the values ββand tilting the chip, I see that they all correspond to register 0x00, the register of values ββof X.
Output:
... 1 1 1 2 3 3 3 3 1 1 1 1 59 60 60 60 51 51 51 51 58 58 58 58 3 3 3 3 62 62 62 62 58 58 58 58 62 62 62 62 ...
code:
import smbus import time bus = smbus.SMBus(1)
Am I something wrong with smbus syntax? I looked at the documentation here .
I checked that the chip is working - I can communicate with it using Arduino and set the registers in the same order as above.
Update # 1 (June 28, 2013) :
According to Sylvain's comment, I connect the oscilloscope output for SDA / SCL lines for the following code:
bus.write_byte(addr, 0x01) print bus.read_byte(addr)

Update # 2:
I guess the known issue with I2C on Raspberry Pi is that there is no restart.
https://raspberrypi.stackexchange.com/questions/7138/mma8452-i2c-module
According to Linux SMBus specification:
SMBus Read Byte: i2c_smbus_read_byte_data() ============================================ This reads a single byte from a device, from a designated register. The register is specified through the Comm byte. S Addr Wr [A] Comm [A] S Addr Rd [A] [Data] NA P
But when I tried it, the osciiloscope clearly shows STOP (P) before restarting (S).
So, I think Iβm not lucky that I used the I2C hardware on the Pi to talk to the MMA7760.