i2c with pcf8591 - Raspberry Pi Forums


hello there,
interfacing i2c pcf8591 , want read it.
have example code in

code: select all

void i2c_init()                            { fd=open("/dev/i2c/0",o_rdwr);                  // file open i2c communication in read-write mode if (fd<0) { printf("\n not able open driver \n"); } else { printf("\n i2c working \n"); } }  //*****************************************************************************************************// //***********************i2c read using external adc*********************************************// //*****************************************************************************************************//  int i2c_read(adc_channell) { if (adc_channell==0)                           // chanel 0 used data acqustion { buf[0]=0x90;                                   // sending control word adc write mode in ch=0 } buf[1]=0x40;                                   // i2c adress arm on adc connected                                  buf[2]=0x91;                                   // control word adc set in read mode io=ioctl(fd,0x703,0x48);                       // address arm i2c communication if(io<0) { printf("error ioctl\n"); } else { wbyte=write(fd,buf,3);                        // write 3 control word arm  usleep(1*1000); if(wbyte!=3) { printf("error write:%d\n",wbyte); } rbyte=read(fd,buff,10);                      // read 10 bytes adc  usleep(10*1000); for(i=0;i<=5;i++) {                                            // average , conversion in voltage valuee=(buff[i]*5)/255;  m1=m1+valuee; printf("\n%x",buff[i]); printf("\n voltage = %fv",value); } m1=m1/5; printf("%fv",m1); } return(m1); } 
can tell me ioctl(fd,0x703,0x48) these address.
don't understand it.

ioctl number 0x703 used set i2c slave address.

tells i2c device talk in next command(s). asking talk device 0x48 (decimal 72).


raspberrypi



Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support