FXOS8700CQ i2c functionality failure on Beaglebone

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FXOS8700CQ i2c functionality failure on Beaglebone

1,720 Views
priyanks
Contributor I

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.

0 Kudos
1 Reply

1,395 Views
michaelestanley
NXP Employee
NXP Employee

Priyank,

I've moved your question to the general Sensors community, as I think we're more likely to get you a good answer here.  The sensorfusion team has no experience with the BeagleBoard, so can't be much help.

Mike

0 Kudos
%3CLINGO-SUB%20id%3D%22lingo-sub-425351%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3EFXOS8700CQ%20i2c%20functionality%20failure%20on%20Beaglebone%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-425351%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EForgive%20my%20lack%20of%20expert%20knowledge%20on%20this%20subject.%20I%20am%20working%20on%20interfacing%20the%20FRDM-STBC-AGM01%20(FXOS8700CQ%20and%20FXAS21002).%20Due%20to%20this%20setup%20type%20with%20beaglebone%20I%20am%20unable%20to%20get%20any%20of%20the%20toolbars%20to%20work.%20I%20am%20trying%20to%20get%20started%20by%20reading%20the%20WHO_AM_I%20and%20writing%20to%20CTRL_REG1%20on%20the%20board%20using%20i2c.%20The%20program%20only%20prints%20zero%20value%20for%20both%20cases.%20Can%20an%20expert%20suggest%20what%20I%20am%20doing%20wrong%3F%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3E%3CCODE%20class%3D%22rainbow%22%20style%3D%22font-family%3A%20Consolas%2C%20'Liberation%20Mono'%2C%20Courier%2C%20monospace%3B%20color%3A%20inherit%3B%20background%3A%20transparent%3B%22%3E%3CSPAN%20class%3D%22keyword%22%20style%3D%22font-weight%3A%20bold%3B%22%3Eint%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22call%20function%22%3Emain%3C%2FSPAN%3E(%3CSPAN%20class%3D%22keyword%22%20style%3D%22font-weight%3A%20bold%3B%22%3Evoid%3C%2FSPAN%3E)%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%26nbsp%3B%20%3CSPAN%20class%3D%22keyword%22%20style%3D%22font-weight%3A%20bold%3B%22%3Echar%3C%2FSPAN%3E%20rxBuffer%5B%3CSPAN%20class%3D%22numeric%20constant%22%20style%3D%22color%3A%20%23009999%3B%22%3E32%3C%2FSPAN%3E%5D%3B%26nbsp%3B%20%3CSPAN%20class%3D%22comment%22%20style%3D%22color%3A%20%23999988%3B%22%3E%2F%2F%20receive%20buffer%3C%2FSPAN%3E%3CBR%20%2F%3E%26nbsp%3B%20%3CSPAN%20class%3D%22keyword%22%20style%3D%22font-weight%3A%20bold%3B%22%3Echar%3C%2FSPAN%3E%20txBuffer%5B%3CSPAN%20class%3D%22numeric%20constant%22%20style%3D%22color%3A%20%23009999%3B%22%3E32%3C%2FSPAN%3E%5D%3B%26nbsp%3B%20%3CSPAN%20class%3D%22comment%22%20style%3D%22color%3A%20%23999988%3B%22%3E%2F%2F%20transmit%20buffer%3C%2FSPAN%3E%3CBR%20%2F%3E%26nbsp%3B%20%3CSPAN%20class%3D%22keyword%22%20style%3D%22font-weight%3A%20bold%3B%22%3Eint%3C%2FSPAN%3E%20gyroAddress%20%3CSPAN%20class%3D%22keyword%20operator%22%20style%3D%22font-weight%3A%20bold%3B%22%3E%3D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22numeric%20constant%22%20style%3D%22color%3A%20%23009999%3B%22%3E0x20%3C%2FSPAN%3E%3B%20%3CSPAN%20class%3D%22comment%22%20style%3D%22color%3A%20%23999988%3B%22%3E%2F%2F%20gyro%20device%20address%3C%2FSPAN%3E%3CBR%20%2F%3E%26nbsp%3B%20%3CSPAN%20class%3D%22keyword%22%20style%3D%22font-weight%3A%20bold%3B%22%3Eint%3C%2FSPAN%3E%20xlAddress%20%3CSPAN%20class%3D%22keyword%20operator%22%20style%3D%22font-weight%3A%20bold%3B%22%3E%3D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22numeric%20constant%22%20style%3D%22color%3A%20%23009999%3B%22%3E0x1E%3C%2FSPAN%3E%3B%26nbsp%3B%20%3CSPAN%20class%3D%22comment%22%20style%3D%22color%3A%20%23999988%3B%22%3E%2F%2F%20accelerometer%20device%20address%3C%2FSPAN%3E%3CBR%20%2F%3E%26nbsp%3B%20%3CSPAN%20class%3D%22keyword%22%20style%3D%22font-weight%3A%20bold%3B%22%3Eint%3C%2FSPAN%3E%20tenBitAddress%20%3CSPAN%20class%3D%22keyword%20operator%22%20style%3D%22font-weight%3A%20bold%3B%22%3E%3D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22numeric%20constant%22%20style%3D%22color%3A%20%23009999%3B%22%3E0%3C%2FSPAN%3E%3B%26nbsp%3B%20%3CSPAN%20class%3D%22comment%22%20style%3D%22color%3A%20%23999988%3B%22%3E%2F%2F%20is%20the%20device's%20address%2010-bit%3F%20Usually%20not.%3C%2FSPAN%3E%3CBR%20%2F%3E%26nbsp%3B%20%3CSPAN%20class%3D%22keyword%22%20style%3D%22font-weight%3A%20bold%3B%22%3Eint%3C%2FSPAN%3E%20opResult%20%3CSPAN%20class%3D%22keyword%20operator%22%20style%3D%22font-weight%3A%20bold%3B%22%3E%3D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22numeric%20constant%22%20style%3D%22color%3A%20%23009999%3B%22%3E0%3C%2FSPAN%3E%3B%26nbsp%3B%20%3CSPAN%20class%3D%22comment%22%20style%3D%22color%3A%20%23999988%3B%22%3E%2F%2F%20for%20error%20checking%20of%20operations%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%26nbsp%3B%20%3CSPAN%20class%3D%22comment%22%20style%3D%22color%3A%20%23999988%3B%22%3E%2F%2F%20Create%20a%20file%20descriptor%20for%20the%20I2C%20bus%3C%2FSPAN%3E%3CBR%20%2F%3E%26nbsp%3B%20%3CSPAN%20class%3D%22keyword%22%20style%3D%22font-weight%3A%20bold%3B%22%3Eint%3C%2FSPAN%3E%20i2cHandle%20%3CSPAN%20class%3D%22keyword%20operator%22%20style%3D%22font-weight%3A%20bold%3B%22%3E%3D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22call%20function%22%3Eopen%3C%2FSPAN%3E(%3CSPAN%20class%3D%22string%22%20style%3D%22color%3A%20%23dd1144%3B%22%3E%22%2Fdev%2Fi2c-1%22%3C%2FSPAN%3E%2C%20O_RDWR)%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%26nbsp%3B%20%3CSPAN%20class%3D%22comment%22%20style%3D%22color%3A%20%23999988%3B%22%3E%2F%2F%20Tell%20the%20I2C%20peripheral%20that%20the%20device%20address%20is%20(or%20isn't)%20a%2010-bit%3C%2FSPAN%3E%3CBR%20%2F%3E%26nbsp%3B%20opResult%20%3CSPAN%20class%3D%22keyword%20operator%22%20style%3D%22font-weight%3A%20bold%3B%22%3E%3D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22call%20function%22%3Eioctl%3C%2FSPAN%3E(i2cHandle%2C%20I2C_TENBIT%2C%20tenBitAddress)%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%26nbsp%3B%20%3CSPAN%20class%3D%22comment%22%20style%3D%22color%3A%20%23999988%3B%22%3E%2F%2F%20Tell%20the%20I2C%20peripheral%20what%20the%20address%20of%20the%20device%20is%3C%2FSPAN%3E%3CBR%20%2F%3E%26nbsp%3B%20opResult%20%3CSPAN%20class%3D%22keyword%20operator%22%20style%3D%22font-weight%3A%20bold%3B%22%3E%3D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22call%20function%22%3Eioctl%3C%2FSPAN%3E(i2cHandle%2C%20I2C_SLAVE%2C%20gyroAddress)%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%26nbsp%3B%20%3CSPAN%20class%3D%22comment%22%20style%3D%22color%3A%20%23999988%3B%22%3E%2F%2F%20Clear%20our%20buffers%3C%2FSPAN%3E%3CBR%20%2F%3E%26nbsp%3B%20%3CSPAN%20class%3D%22call%20function%22%3Ememset%3C%2FSPAN%3E(rxBuffer%2C%20%3CSPAN%20class%3D%22numeric%20constant%22%20style%3D%22color%3A%20%23009999%3B%22%3E0%3C%2FSPAN%3E%2C%20%3CSPAN%20class%3D%22call%20function%22%3Esizeof%3C%2FSPAN%3E(rxBuffer))%3B%3CBR%20%2F%3E%26nbsp%3B%20%3CSPAN%20class%3D%22call%20function%22%3Ememset%3C%2FSPAN%3E(txBuffer%2C%20%3CSPAN%20class%3D%22numeric%20constant%22%20style%3D%22color%3A%20%23009999%3B%22%3E0%3C%2FSPAN%3E%2C%20%3CSPAN%20class%3D%22call%20function%22%3Esizeof%3C%2FSPAN%3E(txBuffer))%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%26nbsp%3B%20%2F%2F%3CSPAN%20class%3D%22comment%22%20style%3D%22color%3A%20%23999988%3B%22%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22comment%22%20style%3D%22color%3A%20%23999988%3B%22%3EWe're%20going%20to%20ask%20the%20gyro%20to%20read%20back%20its%20%22WHO_AM_I%22%3C%2FSPAN%3E%3CBR%20%2F%3E%26nbsp%3B%20txBuffer%5B%3CSPAN%20class%3D%22numeric%20constant%22%20style%3D%22color%3A%20%23009999%3B%22%3E0%3C%2FSPAN%3E%5D%20%3CSPAN%20class%3D%22keyword%20operator%22%20style%3D%22font-weight%3A%20bold%3B%22%3E%3D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22numeric%20constant%22%20style%3D%22color%3A%20%23009999%3B%22%3E0x0C%3C%2FSPAN%3E%3B%20%3CSPAN%20class%3D%22comment%22%20style%3D%22color%3A%20%23999988%3B%22%3E%2F%2F%20This%20is%20the%20address%20we%20want%20to%20read%20from.%3C%2FSPAN%3E%3CBR%20%2F%3E%26nbsp%3B%20opResult%20%3CSPAN%20class%3D%22keyword%20operator%22%20style%3D%22font-weight%3A%20bold%3B%22%3E%3D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22call%20function%22%3Ewrite%3C%2FSPAN%3E(i2cHandle%2C%20txBuffer%2C%20%3CSPAN%20class%3D%22numeric%20constant%22%20style%3D%22color%3A%20%23009999%3B%22%3E1%3C%2FSPAN%3E)%3B%3CBR%20%2F%3E%26nbsp%3B%20%3CSPAN%20class%3D%22keyword%22%20style%3D%22font-weight%3A%20bold%3B%22%3Eif%3C%2FSPAN%3E%20(opResult%20%3CSPAN%20class%3D%22keyword%20operator%22%20style%3D%22font-weight%3A%20bold%3B%22%3E!%3C%2FSPAN%3E%3CSPAN%20class%3D%22keyword%20operator%22%20style%3D%22font-weight%3A%20bold%3B%22%3E%3D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22numeric%20constant%22%20style%3D%22color%3A%20%23009999%3B%22%3E1%3C%2FSPAN%3E)%20%3CSPAN%20class%3D%22call%20function%22%3Eprintf%3C%2FSPAN%3E(%3CSPAN%20class%3D%22string%22%20style%3D%22color%3A%20%23dd1144%3B%22%3E%22No%20ACK%20bit!%5Cn%22%3C%2FSPAN%3E)%3B%3CBR%20%2F%3E%26nbsp%3B%20opResult%20%3CSPAN%20class%3D%22keyword%20operator%22%20style%3D%22font-weight%3A%20bold%3B%22%3E%3D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22call%20function%22%3Eread%3C%2FSPAN%3E(i2cHandle%2C%20rxBuffer%2C%20%3CSPAN%20class%3D%22numeric%20constant%22%20style%3D%22color%3A%20%23009999%3B%22%3E1%3C%2FSPAN%3E)%3B%3CBR%20%2F%3E%26nbsp%3B%20%3CSPAN%20class%3D%22call%20function%22%3Eprintf%3C%2FSPAN%3E(%3CSPAN%20class%3D%22string%22%20style%3D%22color%3A%20%23dd1144%3B%22%3E%22Part%20ID%3A%20%25d%5Cn%22%3C%2FSPAN%3E%2C%20(%3CSPAN%20class%3D%22keyword%22%20style%3D%22font-weight%3A%20bold%3B%22%3Eint%3C%2FSPAN%3E)rxBuffer%5B%3CSPAN%20class%3D%22numeric%20constant%22%20style%3D%22color%3A%20%23009999%3B%22%3E0%3C%2FSPAN%3E%5D)%3B%20%3CSPAN%20class%3D%22comment%22%20style%3D%22color%3A%20%23999988%3B%22%3E%3C%2FSPAN%3E%3CBR%20%2F%3E%26nbsp%3B%20%3CSPAN%20class%3D%22comment%22%20style%3D%22color%3A%20%23999988%3B%22%3E%3C%2FSPAN%3E%3CBR%20%2F%3E%26nbsp%3B%20%3CSPAN%20class%3D%22comment%22%20style%3D%22color%3A%20%23999988%3B%22%3E%2F%2F%20we%20need%20to%20change%20the%20slave%20address!%3C%2FSPAN%3E%3CBR%20%2F%3E%26nbsp%3B%20opResult%20%3CSPAN%20class%3D%22keyword%20operator%22%20style%3D%22font-weight%3A%20bold%3B%22%3E%3D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22call%20function%22%3Eioctl%3C%2FSPAN%3E(i2cHandle%2C%20I2C_SLAVE%2C%20xlAddress)%3B%3CBR%20%2F%3E%26nbsp%3B%20txBuffer%5B%3CSPAN%20class%3D%22numeric%20constant%22%20style%3D%22color%3A%20%23009999%3B%22%3E0%3C%2FSPAN%3E%5D%20%3CSPAN%20class%3D%22keyword%20operator%22%20style%3D%22font-weight%3A%20bold%3B%22%3E%3D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22numeric%20constant%22%20style%3D%22color%3A%20%23009999%3B%22%3E0x0D%3C%2FSPAN%3E%3B%26nbsp%3B%20%3CSPAN%20class%3D%22comment%22%20style%3D%22color%3A%20%23999988%3B%22%3E%2F%2F%20This%20is%20the%20address%20to%20read%20from.%3C%2FSPAN%3E%3CBR%20%2F%3E%26nbsp%3B%20opResult%20%3CSPAN%20class%3D%22keyword%20operator%22%20style%3D%22font-weight%3A%20bold%3B%22%3E%3D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22call%20function%22%3Ewrite%3C%2FSPAN%3E(i2cHandle%2C%20txBuffer%2C%20%3CSPAN%20class%3D%22numeric%20constant%22%20style%3D%22color%3A%20%23009999%3B%22%3E1%3C%2FSPAN%3E)%3B%3CBR%20%2F%3E%26nbsp%3B%20%3CSPAN%20class%3D%22keyword%22%20style%3D%22font-weight%3A%20bold%3B%22%3Eif%3C%2FSPAN%3E%20(opResult%20%3CSPAN%20class%3D%22keyword%20operator%22%20style%3D%22font-weight%3A%20bold%3B%22%3E!%3C%2FSPAN%3E%3CSPAN%20class%3D%22keyword%20operator%22%20style%3D%22font-weight%3A%20bold%3B%22%3E%3D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22numeric%20constant%22%20style%3D%22color%3A%20%23009999%3B%22%3E1%3C%2FSPAN%3E)%20%3CSPAN%20class%3D%22call%20function%22%3Eprintf%3C%2FSPAN%3E(%3CSPAN%20class%3D%22string%22%20style%3D%22color%3A%20%23dd1144%3B%22%3E%22No%20ACK%20bit!%5Cn%22%3C%2FSPAN%3E)%3B%3CBR%20%2F%3E%26nbsp%3B%20opResult%20%3CSPAN%20class%3D%22keyword%20operator%22%20style%3D%22font-weight%3A%20bold%3B%22%3E%3D%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22call%20function%22%3Eread%3C%2FSPAN%3E(i2cHandle%2C%20rxBuffer%2C%20%3CSPAN%20class%3D%22numeric%20constant%22%20style%3D%22color%3A%20%23009999%3B%22%3E1%3C%2FSPAN%3E)%3B%3CBR%20%2F%3E%26nbsp%3B%20%3CSPAN%20class%3D%22call%20function%22%3Eprintf%3C%2FSPAN%3E(%3CSPAN%20class%3D%22string%22%20style%3D%22color%3A%20%23dd1144%3B%22%3E%22Part%20ID%3A%20%25d%5Cn%22%3C%2FSPAN%3E%2C%20(%3CSPAN%20class%3D%22keyword%22%20style%3D%22font-weight%3A%20bold%3B%22%3Eint%3C%2FSPAN%3E)rxBuffer%5B%3CSPAN%20class%3D%22numeric%20constant%22%20style%3D%22color%3A%20%23009999%3B%22%3E0%3C%2FSPAN%3E%5D)%3B%3CBR%20%2F%3E%7D%3C%2FCODE%3E%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EI%20can%20read%20values%20from%20the%20sensor%20using%20i2cget%2Fdump%20commands.%20Program%20seems%20simple%20but%20still%20does%20not%20function.%20Any%20hints%3F%3C%2FP%3E%3CP%3E%3C%2FP%3E%3CP%3EThank%20you.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-425352%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%20translate%3D%22no%22%3ERe%3A%20FXOS8700CQ%20i2c%20functionality%20failure%20on%20Beaglebone%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-425352%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EPriyank%2C%3C%2FP%3E%3CP%3EI've%20moved%20your%20question%20to%20the%20general%20Sensors%20community%2C%20as%20I%20think%20we're%20more%20likely%20to%20get%20you%20a%20good%20answer%20here.%26nbsp%3B%20The%20sensorfusion%20team%20has%20no%20experience%20with%20the%20BeagleBoard%2C%20so%20can't%20be%20much%20help.%3C%2FP%3E%3CP%3EMike%3C%2FP%3E%3C%2FLINGO-BODY%3E