I thought I would have a go at rolling my own interface for the gyro. Unfortunately I'm having trouble getting the I2C working. Here's a snippet from the code; #include <Wire.h> #define WHO_AM_I 0x0C #define I2C_ADDRESS ((uint8_t)0x20) byte Gyro::readReg(byte reg) { byte value; Wire1.beginTransmission(I2C_ADDRESS); Wire1.write(reg); Wire1.endTransmission(); Wire1.requestFrom(I2C_ADDRESS, (uint8_t)1); value = Wire1.read(); Wire1.endTransmission(); return value; } void Gyro::test() { byte val = readReg(WHO_AM_I); Serial.println(val); } When I invoke the test() function I would expect to see 0xD7 printed to the screen (or the decimal equivalent). I am getting '0'. Any ideas why this isn't working? I've essentially just copied the readReg function from the FXAS21002C.cpp library.
Did you switch of I2C-4 from A9 as mentioned in the manual? http://www.udoo.org/docs-neo/Arduino_M4_Processor/Controlling_9-axis_motion_sensors.html Edit: I2C-4 instead of 2
Thanks for the reply. I haven't done this step. But I was able to run the example gyro code without doing it. Seems strange that the example code will run but not my code? Nonetheless I will give it a try.
I've been into the Device Tree editor, right clicked on the I2C-4 pins in the right panel and removed them. Then I saved the config and rebooted. No joy. My code is still outputting '0'.
I had to change a line in the readReg function to get it working; Before: Wire1.endTransmission(); After: Wire1.endTransmission(false); With this change it is working