c++ - Basic I2C read/write failure on Beaglebone -


i writing program access who_am_i registers on accelerometer , gyroscope via i2c on beaglebone black. here basic code.`

int main(void) { char rxbuffer[40]; char txbuffer[32]; int gyroaddress = 0x20; int acceleroaddress = 0x1e; int tenbitaddress = 0; int opresult = 0;   int i2cfd = open("/dev/i2c-1",o_rdwr); opresult = ioctl(i2cfd, i2c_tenbit, tenbitaddress); opresult = ioctl(i2cfd,i2c_slave, acceleroaddress);  memset(rxbuffer, 0, sizeof(rxbuffer)); memset(txbuffer, 0, sizeof(txbuffer));  txbuffer[0] = 0x0d; opresult = write(i2cfd, txbuffer, 1); if (opresult !=1) printf("no ack bit!\n"); opresult = read(i2cfd, rxbuffer, 1);  printf("part id: %d\n", (int)rxbuffer[0]);   //for gyro opresult = ioctl(i2cfd, i2c_slave, gyroaddress); txbuffer[0] = 0x0c; opresult = write(i2cfd, txbuffer, 1); if (opresult != 1) printf("no ack bit!\n"); opresult = read(i2cfd, rxbuffer, 1); printf("part id: %d\n", (int)rxbuffer[0]); } 

` part id both 0 when probe sensor using i2cget commands gives me expected "0xc7" value. idea doing wrong?


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -