AnsweredAssumed Answered

FXOS8700CQ i2c functionality failure on Beaglebone

Question asked by Priyank S on Jun 3, 2015
Latest reply on Jun 12, 2015 by Mike Stanley

Hi,

Forgive my lack of expert knowledge on this subject. I am working on interfacing the FRDM-STBC-AGM01 (FXOS8700CQ and FXAS21002). Due to this setup type with beaglebone I am unable to get any of the toolbars to work. I am trying to get started by reading the WHO_AM_I and writing to CTRL_REG1 on the board using i2c. The program only prints zero value for both cases. Can an expert suggest what I am doing wrong?

 

int main(void)
{
  char rxBuffer[32];  // receive buffer
  char txBuffer[32];  // transmit buffer
  int gyroAddress = 0x20; // gyro device address
  int xlAddress = 0x1E// accelerometer device address
  int tenBitAddress = 0// is the device's address 10-bit? Usually not.
  int opResult = 0// for error checking of operations

  // Create a file descriptor for the I2C bus
  int i2cHandle = open("/dev/i2c-1", O_RDWR);

  // Tell the I2C peripheral that the device address is (or isn't) a 10-bit
  opResult = ioctl(i2cHandle, I2C_TENBIT, tenBitAddress);

  // Tell the I2C peripheral what the address of the device is
  opResult = ioctl(i2cHandle, I2C_SLAVE, gyroAddress);

  // Clear our buffers
  memset(rxBuffer, 0, sizeof(rxBuffer));
  memset(txBuffer, 0, sizeof(txBuffer));

  //We're going to ask the gyro to read back its "WHO_AM_I"
  txBuffer[0] = 0x0C; // This is the address we want to read from.
  opResult = write(i2cHandle, txBuffer, 1);
  if (opResult != 1) printf("No ACK bit!\n");
  opResult = read(i2cHandle, rxBuffer, 1);
  printf("Part ID: %d\n", (int)rxBuffer[0]);
 
  // we need to change the slave address!
  opResult = ioctl(i2cHandle, I2C_SLAVE, xlAddress);
  txBuffer[0] = 0x0D// This is the address to read from.
  opResult = write(i2cHandle, txBuffer, 1);
  if (opResult != 1) printf("No ACK bit!\n");
  opResult = read(i2cHandle, rxBuffer, 1);
  printf("Part ID: %d\n", (int)rxBuffer[0]);
}

 

I can read values from the sensor using i2cget/dump commands. Program seems simple but still does not function. Any hints?

 

Thank you.

Outcomes