Answer the question
In order to leave comments, you need to log in
How to work with two devices on the I2C bus on Rasppberry?
For 2 days I have been unsuccessfully trying to get 2a devices to work together on the same bus, I can’t find an example of how several IIC devices for Rasppberry Pi work anywhere. There are no problems with one device.
#include <inttypes.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/fs.h>
#include <i2c-dev.h>
int main ()
{
//Открываю порт
if(( _HandleBNO = open("/dev/i2c-1", O_RDWR)) < 0) ;
//Открываю устройство
if( ioctl( _HandleBNO, I2C_SLAVE, _address) != 0);
uint8_t buf [2]= { subaddress, data }; // Адрес регистра и данные
//Запись
if(write(_HandleBNO, &buf, 1) != 1) ;
//Чтение
if(read(_HandleBNO, buffer, len) != len) ;
return 0;
}
Answer the question
In order to leave comments, you need to log in
Are the devices the same or different? If they are different, then their addresses on the bus are different, you can see them using i2cdetect. If they are the same, then it is more difficult. I haven’t done it myself yet, but I dug up a guide: https://www.instructables.com/id/Raspberry-PI-Mult...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question