I have some problem with I2C interface between Raspberry and Atmega128A.
I hope receiving some great advices from our forum.
This is my code to talk to Atmega128A by I2C bus:
I use wiringPi library of Gordons.
The writing function:
Code: Select all
void I2C_array_write(int I2C_fd,unsigned char *data,int bytes_num)
{
int dem=0;
int e[bytes_num];
for (dem;dem<bytes_num;dem++)
{
if(I2C_fd<0)
{
printf("error opening i2c channel\n\r");
}
e[dem]=wiringPiI2CWrite(I2C_fd,*(data+dem));
if(e[dem]<0)
{
printf("error i2c writing to slave\n\r");
}
else
{
//printf("writing hex:0x%i size:%i\n\r",test,sizeof(test));
}
}
//delay(50);
}Code: Select all
void I2C_array_read(int I2C_fd,unsigned char *Rec_data,int bytes_num)
{
int dem=0;
for (dem;dem<bytes_num;dem++)
{
if(I2C_fd<0)
{
printf("error opening i2c channel\n\r");
}
*Rec_data++=wiringPiI2CRead(I2C_fd);//*Rec_data++ is element that Rec_data pointed before data was incremented
if(*Rec_data<0)
{
printf("error i2c reading to slave\n\r");
}
else
{
//printf("Rec_Data[%i] :%c\n\r",dem,*Rec_data);
}
//delay(5);
}
}Can you give me some solution to get the I2C talking with high stability?
Thanks