# Unable to read ITG3200 (6DOF) with i2c

**URL:** https://community.particle.io/t/unable-to-read-itg3200-6dof-with-i2c/7323
**Category:** Firmware
**Created:** [October 5, 2014, 11:52am UTC](https://community.particle.io/t/unable-to-read-itg3200-6dof-with-i2c/7323 "2014-10-05T11:52:44Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![sanjukul](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@sanjukul](https://community.particle.io/u/sanjukul)
#### Post date: [October 5, 2014, 11:52am UTC](https://community.particle.io/t/unable-to-read-itg3200-6dof-with-i2c/7323/1 "2014-10-05T11:52:44Z")

</div>

Hello Guys,

This is my first post here. So far learning expierence with spark core is great. I dont use webide and compile using make and flash using dfu util.

I have a imu 6DOF and trying to interface it with spark core using i2c (6dof only supports i2c). I have been trying to establish connection with gyro[itg3200](also accelometer[ADXL345]) of imu but without success.

I have come across other posts having problems with i2c,

> **[i2c changes from july? need code analysis help](https://community.particle.io/t/i2c-changes-from-july-need-code-analysis-help/7231/5)**
>
> I’m also having trouble with Wire code (trying to read an Adafruit BMP180 and TSL2561 over i2c) that was working last month. I’ve traced it to the very first Wire.requestFrom (when initializing my i2c slave device) never making anything available...

After going through above post i replaced the spark\_wiring\_i2c.cpp/h with the latest one available at (satishgn)

> <https://github.com/particle-iot/device-os/tree/fe30d62cae4541f2a2354c113b3460d1356bda57/src>
>
> //github.com/particle-iot/device-os/tree/fe30d62cae4541f2a2354c113b3460d1356bda57/src

but the new change didnt help. I pulled out only spark\_wiring\_i2c.cpp/h files.

I am following sparkfun link for reference, [ITG-3200 Hookup Guide - SparkFun Learn](https://learn.sparkfun.com/tutorials/itg-3200-hookup-guide)

My code is somewhat like this,

```auto
          Wire.enableDMAMode(true); /// is it really needed
          Wire.begin();
          len = itgRead(GYRO_ADDR, 0x00); ///WHO_AM_I register

and itgRead() is as follows,

uint8_t itgRead(uint8_t address, uint8_t registerAddress)
{
  unsigned char data=0;
 
 Wire.beginTransmission(address);
  Wire.write(registerAddress);
  Wire.endTransmission();

  Wire.beginTransmission(address);
  Wire.requestFrom(address, 1);

   while (!Wire.available()) ;
  data = Wire.read();
  
  Wire.endTransmission();
  return data;
}

itgRead() and requestFrom() always give out 0. 

```

Let me mention that i am not connecting any resistor between spark core and imu. SDA/SCL of imu is connected directly to SDA/SCL of the core.  
No good results with r without dma enabled.

Please guide me.  
Thanks.

---

<div class="post-metadata">

### Author: ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)
#### Post date: [October 5, 2014, 11:55am UTC](https://community.particle.io/t/unable-to-read-itg3200-6dof-with-i2c/7323/2 "2014-10-05T11:55:19Z")

</div>

You will need Pull-up resistors for I2C to work.

Also, did you short the `CLKIN` jumper at the bottom?

---

<div class="post-metadata">

### Author: ![sanjukul](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@sanjukul](https://community.particle.io/u/sanjukul)
#### Post date: [October 5, 2014, 12:18pm UTC](https://community.particle.io/t/unable-to-read-itg3200-6dof-with-i2c/7323/3 "2014-10-05T12:18:51Z")

</div>

[https://www.sparkfun.com/datasheets/Sensors/IMU/6DOF-Digital-v10.pdf](https://www.sparkfun.com/datasheets/Sensors/IMU/6DOF-Digital-v10.pdf) mentions pullup resistor across SDA/SCL pins for gyro. Are you talking about any other pullup resistors ?

Also the schematics mentions CLKIN connected to ground.

DO you think i should be doing something more?

thanks

---

<div class="post-metadata">

### Author: ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)
#### Post date: [October 5, 2014, 1:08pm UTC](https://community.particle.io/t/unable-to-read-itg3200-6dof-with-i2c/7323/4 "2014-10-05T13:08:08Z")

</div>

I’m confused.

This is the product right? [https://www.sparkfun.com/products/11977](https://www.sparkfun.com/products/11977)

or [https://www.sparkfun.com/products/10121](https://www.sparkfun.com/products/10121)?

Try to remove this line: `Wire.enableDMAMode(true);`

---

<div class="post-metadata">

### Author: ![sanjukul](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@sanjukul](https://community.particle.io/u/sanjukul)
#### Post date: [October 5, 2014, 1:48pm UTC](https://community.particle.io/t/unable-to-read-itg3200-6dof-with-i2c/7323/5 "2014-10-05T13:48:22Z")

</div>

> **[SparkFun 6 Degrees of Freedom IMU Digital Combo Board - ITG3200/ADXL345 -...](https://www.sparkfun.com/products/10121)**
>
> This is a simple breakout for the ADXL345 accelerometer and the ITG-3200 MEMS gyro. With this board, you get a full 6 degrees of freedom. The sensors commu

  
It’s the second link… imu combo…

Removing enabledmaMode() dosnt help…

---

<div class="post-metadata">

### Author: ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)
#### Post date: [October 5, 2014, 3:48pm UTC](https://community.particle.io/t/unable-to-read-itg3200-6dof-with-i2c/7323/6 "2014-10-05T15:48:43Z")

</div>

I’m not sure if it’s that straightforward to use but you probably need a library for it:

> **[sparkfun/IMU\_Digital\_Combo\_Board](https://github.com/sparkfun/IMU_Digital_Combo_Board/tree/master/Libraries)**
>
> IMU\_Digital\_Combo\_Board - A simple breakout for the ADXL345 accelerometer and the ITG-3200 MEMS gyro. (https://www.sparkfun.com/products/10121)

---

<div class="post-metadata">

### Author: ![sanjukul](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@sanjukul](https://community.particle.io/u/sanjukul)
#### Post date: [October 5, 2014, 4:16pm UTC](https://community.particle.io/t/unable-to-read-itg3200-6dof-with-i2c/7323/7 "2014-10-05T16:16:43Z")

</div>

I will give it a try… thanks for the link

---

<div class="post-metadata">

### Author: ![sanjukul](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@sanjukul](https://community.particle.io/u/sanjukul)
#### Post date: [October 17, 2014, 9:57am UTC](https://community.particle.io/t/unable-to-read-itg3200-6dof-with-i2c/7323/8 "2014-10-17T09:57:41Z")

</div>

it seems my 6dof is not working … i will update once i get a new one (which i have ordered) and work on it.

---

<div class="post-metadata">

### Author: ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)
#### Post date: [October 17, 2014, 11:39am UTC](https://community.particle.io/t/unable-to-read-itg3200-6dof-with-i2c/7323/9 "2014-10-17T11:39:42Z")

</div>

The I2C feature is currently broken

---

<div class="post-metadata">

### Author: ![sanjukul](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@sanjukul](https://community.particle.io/u/sanjukul)
#### Post date: [October 20, 2014, 6:24pm UTC](https://community.particle.io/t/unable-to-read-itg3200-6dof-with-i2c/7323/10 "2014-10-20T18:24:05Z")

</div>

thanks for the update … so when will the new release be made…

i am eagerly waiting…

---

<div class="post-metadata">

### Author: ![zach](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/zach/32/20714_2.png) [@zach](https://community.particle.io/u/zach)
#### Post date: [October 21, 2014, 12:17am UTC](https://community.particle.io/t/unable-to-read-itg3200-6dof-with-i2c/7323/11 "2014-10-21T00:17:15Z")

</div>

we’re working on it! @zachary will be sharing an update soon

---

<div class="post-metadata">

### Author: ![sanjukul](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@sanjukul](https://community.particle.io/u/sanjukul)
#### Post date: [October 22, 2014, 6:08pm UTC](https://community.particle.io/t/unable-to-read-itg3200-6dof-with-i2c/7323/12 "2014-10-22T18:08:27Z")

</div>

thanks Zach…

---

<div class="post-metadata">

### Author: ![sanjukul](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@sanjukul](https://community.particle.io/u/sanjukul)
#### Post date: [October 28, 2014, 6:19pm UTC](https://community.particle.io/t/unable-to-read-itg3200-6dof-with-i2c/7323/13 "2014-10-28T18:19:32Z")

</div>

I am testing the recent changes (0.34) made to i2c. Good news is new changes work.

Bad news is it works 3 to 4 times out of 10. In the function endTransmission()

while(!I2C\_CheckEvent(I2C1, I2C\_EVENT\_MASTER\_TRANSMITTER\_MODE\_SELECTED))  
fails.  
Core is not able to catch response for tx mode. This is not an issue with master receiver mode.

As i said the above check succeeds 3 to 4 times out of 10 tries.

I cant claim the issue is with imu since it works flawlessly with the raspberry pi.

Suggestions are welcome and i shall keep you guys updated.

---

<div class="post-metadata">

### Author: ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)
#### Post date: [October 28, 2014, 11:55pm UTC](https://community.particle.io/t/unable-to-read-itg3200-6dof-with-i2c/7323/14 "2014-10-28T23:55:48Z")

</div>

Did you managed to get it working 10/10 times on the Spark core before the I2C issue?

If not, it’s hard to pinpoint saying that the code changes made it work unreliably. It can but i don’t think so since i haven’t seen anyone commenting about their I2C issues after the recent firmware push.

Also, i presume you did the library porting?

---

<div class="post-metadata">

### Author: ![sanjukul](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@sanjukul](https://community.particle.io/u/sanjukul)
#### Post date: [October 29, 2014, 5:55am UTC](https://community.particle.io/t/unable-to-read-itg3200-6dof-with-i2c/7323/15 "2014-10-29T05:55:12Z")

</div>

Previously it never worked for me. And I have taken the new changes in its entirety.

I will double check from my side if I am doing any mistakes or not.

---

<div class="post-metadata">

### Author: ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)
#### Post date: [October 29, 2014, 12:23pm UTC](https://community.particle.io/t/unable-to-read-itg3200-6dof-with-i2c/7323/16 "2014-10-29T12:23:25Z")

</div>

@sanjukul, @kennethlimcp, the Sparkfun Arduino code requires some thinking for the port. @sanjukul can you post your ported code for review?

---

<div class="post-metadata">

### Author: ![sanjukul](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@sanjukul](https://community.particle.io/u/sanjukul)
#### Post date: [October 30, 2014, 4:09pm UTC](https://community.particle.io/t/unable-to-read-itg3200-6dof-with-i2c/7323/17 "2014-10-30T16:09:05Z")

</div>

```auto
define REQ_DATA_LEN 32 // this is the size of BUFFER_LENGTH
define I2C_SETUP 1
define I2C_START 2
static uint8_t i2c_stMch = 0xFF;

extern void Schedule_10ms(void (*f)());

void I2C_Init()
{
	Schedule_10ms(I2C_rw);

	i2c_stMch = I2C_SETUP ;
}

//this function is called every 10ms
void I2C_rw()
{
	static uint8_t len = 255;

	switch(i2c_stMch)
	{
	  case I2C_SETUP:
		  /* Set the Init parameters for i2c */
		  Wire.enableDMAMode(true);

		  Wire.begin();

		  Serial.println("SETUp");

		  i2c_stMch = I2C_START;

		  break;
	  case I2C_START:

		  Serial.println( "start");
		  len = itgRead(ACCL_ADDR, 0x00);
		  Serial.println( len);

		  if( len == 0xFF)
		  {
			 Serial.println("Error Reading");
			 i2c_stMch = 0xFF; // come out and do nothing    
		  }

		  break;
	  default:
		  break;
	}
}

void itgWrite(uint8_t address, uint8_t registerAddress, uint8_t data)
{
	//Initiate a communication sequence with the desired i2c device
	Wire.beginTransmission(address);
	//Tell the I2C address which register we are writing to
	Wire.write(registerAddress);
	//Send the value to write to the specified register
	Wire.write(data);
	//End the communication sequence
	Wire.endTransmission();
}

uint8_t itgRead(uint8_t address, uint8_t registerAddress)
{
	//This variable will hold the contents read from the i2c device.
	unsigned char data=0;
	system_tick_t _millis;

	//Send the register address to be read.
	Wire.beginTransmission(address);
	//Send the Register Address
	Wire.write(registerAddress);
	//End the communication sequence.
	Wire.endTransmission();

	//Ask the I2C device for data
	//Wire.beginTransmission(address);
	Wire.requestFrom(address, 1);

	Serial.println( "itgRead");
	//Wait for a response from the I2C device

	_millis = millis();
	while (!Wire.available()) 
	{
		if(millis() - _millis > 2000)
		return 0xFF;
	}

	data = Wire.read();

	Serial.println( "Yes Available");
	Serial.println(data);
	//End the communication sequence.
	//Wire.endTransmission();

	//Return the data read during the operation
	return data;
}

```

* * *

_I’ve edited your post to properly format the code. Please check out [this post](http://community.spark.io/t/forum-tips-and-tricks/3999/2), so you know how to do this yourself in the future. Thanks in advance! ~Jordy_

---

<div class="post-metadata">

### Author: ![sanjukul](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@sanjukul](https://community.particle.io/u/sanjukul)
#### Post date: [October 30, 2014, 4:17pm UTC](https://community.particle.io/t/unable-to-read-itg3200-6dof-with-i2c/7323/18 "2014-10-30T16:17:26Z")

</div>

Thanks @Jordy.

@peekay123: I have posted the my code. I2C\_rw() is called every 10ms. As of now i am trying to get the device id which is usually present in WHO\_AM\_I register (0x00) ( GYRO and ACCEL).

i will display error message if read fails.

---

<div class="post-metadata">

### Author: ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)
#### Post date: [October 30, 2014, 5:50pm UTC](https://community.particle.io/t/unable-to-read-itg3200-6dof-with-i2c/7323/19 "2014-10-30T17:50:25Z")

</div>

@sanjukul, your code “looks” fine. Am I correct in assuming you can communicate with the ADXL345 without problems? Have you tried running an [I2C bus scanner](http://community.spark.io/t/i2c-humidity-sensor/5451/3?u=peekay123) to see if the ITG shows up? I am looking at how the Core firmware and Arduino handle a device address to be sure they match.

---

<div class="post-metadata">

### Author: ![sanjukul](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@sanjukul](https://community.particle.io/u/sanjukul)
#### Post date: [November 1, 2014, 4:06am UTC](https://community.particle.io/t/unable-to-read-itg3200-6dof-with-i2c/7323/20 "2014-11-01T04:06:39Z")

</div>

WIth I2C bus scanner only ADXL345 shows up. ITG3200 does not show up. I got it confirmed with my raspberry pi too.

The combo board that i have has only accelermeter working. Gyrometer is not detected may be its gone bad.

[Next page](https://community.particle.io/t/unable-to-read-itg3200-6dof-with-i2c/7323.md?page=2)
