注:(1)bcm2835_i2c_begin(); 启动i2c操作,设置I2C相关引脚为复用功能
(2)bcm2835_i2c_setSlaveAddress(0x20); 设置I2C从机设备的地址,此处为0x20。即PCF8574的地址。
(3)bcm2835_i2c_write(buf,1);传输字节到i2c从设备,buf为要传输的数据,1表示传输一个字节
注:(1)fd = wiringPiI2CSetup(0x20);初始化I2C设备,0x20为PCF8574的I2C地址,返回值是标准的Linux文件句柄,如果错误则返回-1.由此可知,wiringPi底层也是通过sysfs方式操作I2C设备/dev/i2c-1
注:(1)import smbus 导入smbus模块
(2)bus = smbus.SMBus(1) 在树莓派版本2中,I2C设备位于/dev/I2C-1,所以此处的编号为1
注:(1)fd = open(“/dev/i2c-1”, O_RDWR); 打开设备,树莓派版本2的I2C设备位于/dev/i2c-1
(2)ioctl(fd, I2C_SLAVE, I2C_ADDR) ; 设置I2C从设备地址,此时PCF8574的从机地址为0x20。I
(3) write( fd , &value, 1 );向PCF8574写入一个字节,value便是写入的内容,写入的长度为1.
更多回帖