树莓派I2C修改传输速率及兼容repeated start iic设备

1,修改传输速率

默认状态下传输速率为100khz,使用如下命令查看:


sudo cat /sys/module/i2c_bcm2708/parameters/baudrate


你会看到显示100000,表示为100khz。


修改步骤如下:
1,sudo nano /boot/config.txt

2,在打开的文件中添加一行dtparam=i2c1_baudrate=50000假设我们将其设置为50khz).

  3,sudo reboot


打开后重新查看 你会发现速率已经改为50000了。


2,树莓派修改iic协议让其兼容repeated start i2c设备,让此类设备可以正常运行。

我在使用MMA7660FC这个三轴加速度传感器时就碰到这样的问题,开始软件写的没有问题,但是怎么弄 xyz轴数据都一样,困扰了很

久终于发现树莓派iic协议不支持这样的iic设备。


mma7660fc数据手册中这样说:

MMA7660FC is read using it’s internally stored register address as address pointer, the same way the stored register address
is used as address pointer for a write. The pointer generally auto-increments after each data byte is read using the same rules
as for a write. Thus, a read is initiated by first configuring the device’s register address by performing a write (Figure 12) followed
by a repeated start. The Master Write address is 1001 1001 (0x99). The master can now read ''n' consecutive bytes from it, with
the first data byte being read from the register addressed by the initialized register address.


接下来怎么改变让其兼容呢?

步骤如下:

1:sudo su -

2:echo -n 1 > /sys/module/i2c_bcm2708/parameters/combined

3:exit


这样你会发现文件combined中的 N 变成了 Y

接下来你就可以使用repeated start 类型的Iic设备了。



参考英文如下:

Using:
Raspberry Pi 2 Model B
Python 2.7
python-smbus
i2c-tools

I was having problems with a device that required combined (repeated start) mode operation to work. After flailing around for a couple of days (getting smarter about I2C, Python, R-Pi and Linux), I found the information on this site:
http://ciaduck.blogspot.com/
Lastly, the MPL3115A2 requires a proper repeated start command in it's I2C communication. Raspberry Pi doesn't do this out of the box, but there is a kernel module that can be enabled to make it perform repeated start correctly. Run the following commands to enable repeated start on the Pi:

sudo su -
echo -n 1 > /sys/module/i2c_bcm2708/parameters/combined
exit

More details about the repeated start problem can be found here:
viewtopic.php?f=44&t=15840&start=25

After setting the contents of the file from “N” to “Y”, my device started working, with the scope showing that the Stop command was no longer being issued in the middle of the read_word_data(addr, cmd) instruction.




你可能感兴趣的:(学习笔记)