Quantcast
Channel: Processors forum - Recent Threads
Viewing all articles
Browse latest Browse all 17527

I2C reading in userland application made on OMAP L138

$
0
0

Hi, 

      I2c device is attached with OMAP L138 and made application to read i2c data. where OMAP L138 is master device and i2c device as slave device, i2c device is sending 2 bytes of data. I am able to read two i2c data bytes by using ioctl() and read function. In first attempt, i am able to read first two bytes but on second attempt, one byte is dropped and next two bytes are read. This result repeats on every consecutive reading of i2c device. How can i ensure that every consecutive reading should read every bytes without dropping any one byte reading?

Code i

void i2cread()

{

  int i2c_fd;
     ssize_t byte;
     char buffer[32];

   
    i2c_fd=open("/dev/i2c-1",O_RDWR);
    if(i2c_fd<0) {
        printf("File I2C Device Can't be Opened\n");
        return -1;
    }
    else {
        printf("File I2C Device is Opened\n");
    }
    if(ioctl(i2c_fd,I2C_SLAVE,0x48)<0) {
        printf("I2C Device Can't be Opened\n");
        ERROR_FXN_EXIT(i2c_fd);
    }
    else {
        printf("I2C Device is Opened\n");
    }        
    byte=read(i2c_fd,buffer,20);
    printf("%d. ",byte);
    if(byte<0){
         printf("\n");
    }
    else  {

    for(byte=0;byte<20;byte++)
         printf("%d ",buffer[byte]);
    printf("\n");
    }

}

On every time calling of i2cread function, i am reading one byte is missing. why is one byte missing?

suppose if give read function two times, then first time reading is OK, but during call of read function, then one byte is missing. what could be reason? can anyone throw light on it?

Regards,   

Learner.


Viewing all articles
Browse latest Browse all 17527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>