简体   繁体   English

在Raspberry Pi,python smbus上使用I2C连续传输

[英]Transmit consecutively using I2C on Raspberry Pi, python smbus

I want to transmit AVR or Arduino etc by I2C from Raspberry pi. 我想从Raspberry pi通过I2C传输AVR或Arduino等。 I am writing in Python. 我正在用Python编写。

I already successeded communication using write_data() function in smbus module. 我已经在smbus模块中使用write_data()函数成功完成了通信。 But I want to transmit multiple bytes data consecutively. 但是我想连续传输多个字节的数据。

Please tell me how to transmit multiple bytes data in i2c communication. 请告诉我如何在i2c通信中传输多个字节数据。 I find write_block_data() function, but I don't understand the second parameter CMD . 我找到了write_block_data()函数,但是我不理解第二个参数CMD What is the CMD?? 什么是CMD? Should I specify the value of CMD ? 我应该指定CMD的值吗?

thank you. 谢谢。

Communicating between an RPi and an Arduino on I2C is a big mess if you are using Wire.h library. 如果您使用的是Wire.h库,则在I2C上的RPi和Arduino之间进行通信非常麻烦。 The short answer is that RPi is using a repetitive start signal while Arduino is not using it. 简短的答案是,RPi使用重复的启动信号,而Arduino不使用它。

Repetitive start signal on I2C interface tells the slave to start answering for the call. I2C接口上的重复启动信号告诉从机开始应答呼叫。 In case of the Arduino asking and answering is in two separated calls. 如果是Arduino,则在两个单独的呼叫中进行询问和应答。 Therefore you cannot send block 因此,您无法发送阻止

I made two blog posts to interface the two architecture through I2C. 我写了两个博客文章,以通过I2C连接这两种体系结构。 First one is for using a remote controller PWM: http://distantorion.com/2014/10/24/rc-signals-pwm-to-i2c-with-arduino/ The second one is for driving a 128x64 LCD display on I2C: http://distantorion.com/2014/11/01/i2c-display-with-arduino/ 第一个用于使用远程控制器PWM: http : //distantorion.com/2014/10/24/rc-signals-pwm-to-i2c-with-arduino/第二个用于驱动I2C上的128x64 LCD显示器: http : //distantorion.com/2014/11/01/i2c-display-with-arduino/

In the second one I'm using block data in python: 在第二个中,我在python中使用块数据:

bus.write_i2c_block_data(0x05,0x10,buff)

0x05 is the device address, 0x10 is the "command", buff containd the characters to display. 0x05是设备地址,0x10是“命令”,buff包含要显示的字符。

Regarding the commands. 关于命令。 In I2C a slave works in a way of commands or registers. 在I2C中,从站以命令或寄存器的方式工作。 Both method looks like the same. 两种方法看起来都一样。 If you are using a repetitive start signal the communication seems to be reading and writing registers. 如果使用重复的启动信号,则通信似乎正在读写寄存器。 When you have no repetitive start signal, the communication looks like a command - answer system. 当您没有重复的开始信号时,通讯就像命令-应答系统。 In my example I'm sending 0x10 what is "put the characters from to the display". 在我的示例中,我要发送0x10,即“将字符从显示到显示器”。 And 0x01 is a clear screen command, while 0x02 turns on the backlight. 0x01是一个清晰的屏幕命令,而0x02则打开背光。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM