Hi Andrey, Thank you for your answer. See the code snippets below. Both open the device /dev/xi2c16. reg_write.php is called with the parameters 0x835 0x2 to switch to channel 2. Why doesn't the command fpcf -i2cw16 0x835 0x02do the same? Both write to /dev/xi2c16 I prefer to set the values from c, directly. Thank you for the info about the possibility of an inconsistency on driver level. But I don't think that this is the problem here. Do you know why the two code snippets don't do the same? Andreas ---------------------------- fpcf.c ------------------------------- shft=-1; if (strcasecmp(argv[1], "-i2cw8") ==0) shft=0; if (strcasecmp(argv[1], "-i2cw16") ==0) shft=1; if (shft>=0) { // write i2c bus0 if (argc<3) {printf("Need I2C address (hex) to write: register address + 256* (slave address>>1)\r\n");return -1;} if (argc<4) {printf("Need data (hex) to write to i2c bus 0\r\n");return -1;} sa= strtol (argv[2],&cp,16); uld=strtol (argv[3],&cp,16); if (shft==1) { if ((devfd = open("/dev/xi2c16", O_RDWR))<0) {printf("error opening /dev/xi2c16\r\n"); return -1;} uld= ((uld >>8) & 0xff) | ((uld <<8) & 0xff00); } else { if ((devfd = open("/dev/xi2c8", O_RDWR))<0) {printf("error opening /dev/xi2c8\r\n"); return -1;} } if ((res=lseek(devfd,sa<<shft,0))<0) { printf("lseek failed, returned %d\n",res); close (devfd); return -1; } if ((res=write(devfd,&uld,1<<shft))<(1<<shft)) { printf("write failed, returned %d, expected - %d\n",res, (1<<shft)); close (devfd); return -1; } close (devfd); return 0; } ---------------------------- reg_write.php ------------------------- function send_i2c_4($a,$d) { $i2c = fopen('/dev/xi2c16', 'w'); fseek ($i2c, 2*$a) ; if ($w==1) $res=fwrite($i2c, chr ($d)); else { $res=fwrite($i2c, chr (floor($d/(256*256*256))).chr (($d - 256*256*256*floor($d/(256*256*256)))/(256*256)).chr (($d - 256*256*floor($d/(256*256)))/256).chr ($d - 256*floor($d/(256))) ); printf("v1=%d\n",floor($d/(256*256*256))); printf("v2=%d\n",($d - 256*256*256*floor($d/(256*256*256)))/(256*256)); printf("v3=%d\n",($d - 256*256*floor($d/(256*256)))/256); printf("v4=%d\n",$d - 256*floor($d/(256))); } fclose($i2c); return $res; } |
<<attachment: office.vcf>>
_______________________________________________ Support-list mailing list Support-list@support.elphel.com http://support.elphel.com/mailman/listinfo/support-list_support.elphel.com