Hi,
I am interacting my PI with a slave device [PC], with the same I am able to send data and receive data.
But the first byte that i receive in PI is missing the MSB bit every time it reads, i.e.; the first bit [MSB] is always considered as 0, below i have given some example that slave device is sending and what PI RX.
Slave[TX] PI[TX]
FF 7F
88 08
AA 2A
I did connect the logical analyzer and to check the data it sends correctly.
#include <stdio.h>
#include <stdlib.h>
#include <linux/i2c-dev.h>
#include <linux/i2c.h>
#include <fcntl.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <time.h>
int main()
{
int File;
char Device[] = "/dev/i2c-0";
char Touch = 0x32;
char Data[60];
int i,j=0;
if ((File = open("/dev/i2c-0", O_RDWR)) < 0) // I²C aktivieren
{
printf("I²C Module address can not be loaded!\n");
return -1;
}
if (ioctl(File, I2C_SLAVE, Touch) < 0) // Port und Adresse setzen
{
printf("Device adresse can not be found !\n");
exit(1);
}
while(j++ < 2)
{
/* SW version */
Data[0] = 0xff;
Data[1] = 0xff;
Data[2] = 0xff;
Data[3] = 0xff;
if(write(File, Data, 4) != 4)
{
printf("Error writing data!\n");
return -1;
}
if (read(File, Data, 4) != 4)
{
printf("Error reading data!\n");
return -1;
}
//else
{
for(i = 0;i < 4;i++)
printf(" %x ",Data);
printf("\n");
}
sleep(1);
}
close(File);
return 0;
}