CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

ITG 3200 gyro

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
alex323qp



Joined: 17 Jun 2011
Posts: 12

View user's profile Send private message

ITG 3200 gyro
PostPosted: Wed Jun 22, 2011 11:49 pm     Reply with quote

Has anybody used the ITG 3200 gyro??

I'm trying to comunicate with it using pic 12f675 (Yes, it doesn't have i2c ports)... but I can't get any answer from it... The datasheet says it works on address 0x69, but after running a program to find how many devices are connected, I get 0 devices found :(.

Thanks for any help!
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jun 23, 2011 5:05 am     Reply with quote

Do you have the correct pullups on the I2C bus lines ?

Have you correctly got any other I2C device to communicate with your PIC and code ?
alex323qp



Joined: 17 Jun 2011
Posts: 12

View user's profile Send private message

PostPosted: Thu Jun 23, 2011 3:33 pm     Reply with quote

Hi, I reckon I've got the correct resistors, 10k from SDA to vcc and 10k from SCL to vcc... The device works up to 400k.

To be honest, this is my first attempt with I2c, so i'm kind of newbie. And not, I don't have any other device connected. As far as I understand, despite the fact that my pic doesn't have hardware for I2c, I should be able to use it as master... shouldn't I?

Here is my code:

Code:

#include <12F675.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOCPD                    //No EE protection

#use delay(int=4000000)
#define XBEE_IN   PIN_A0
#define XBEE_OUT   PIN_A1
#define LED   PIN_A2
#define SW1   PIN_A3
#use rs232(baud=9600,parity=N,xmit=XBEE_OUT,rcv=XBEE_IN,bits=8,stream=xbee)
#use i2c(master, sda=PIN_A4, scl=PIN_A5, FAST=100000, FORCE_SW)

int8 get_ack_status(int8 address)
{
   int8 status;
   
   i2c_start();
   status = i2c_write(address);  // Status = 0 if got an ACK
   i2c_stop();
   
   if(status == 0){
      return(TRUE);
   }else{
      return(FALSE);
   }
}

void main(){
   int8 i=0;
   for(i=1; i<255; i++){
      if(get_ack_status(i) == TRUE){
         printf("Device found at: %u ", i);
      }
   }
   puts("Done!");
}

The gyro works in 0x69 address, but I'm getting "Device found at: 210, 211, 212". I have not idea why.


Any idea?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 23, 2011 4:21 pm     Reply with quote

In CCS 8-bit format, the slave address is 0xD2 (210 decimal).
This is the same as 0x69 in 7-bit Philips address format.


Quote:
printf("Device found at: %u ", i);

Change the %u to %x to display the i2c addresses in their normal Hex format.
alex323qp



Joined: 17 Jun 2011
Posts: 12

View user's profile Send private message

PostPosted: Thu Jun 23, 2011 4:53 pm     Reply with quote

wow, thanks!!!

So apparently it's working quite good. However, now I need to send register addresses to read the data... But, where can I find a conversor from 7-bit to 8-bit... cos the datasheet has addresses in 7-bit. I guess it's the reason I'm getting -1 when I try to read the register 1E (or any other).

Thanks again!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 23, 2011 5:07 pm     Reply with quote

0x69 shifted left by 1 becomes 0xD2. Simply use 0xD2 as the slave
address in your i2c_write() statement.

Thus the write address is 0xD2 and the read address is 0xD3, in CCS
format.
alex323qp



Joined: 17 Jun 2011
Posts: 12

View user's profile Send private message

PostPosted: Thu Jun 23, 2011 6:28 pm     Reply with quote

Ok, apparently I've got not idea how to comunicate with my device...

This is my reading function:
Code:

BYTE read_gyro()
{
   BYTE ret;
   i2c_start();
   i2c_write(0xD2);  // 210 writing address
   i2c_write(0x3C);  // GYRO_XOUT_L (8-bit format XD)
   i2c_start();      // Restart
   i2c_write(0xD3);  // Reading address
   ret = i2c_read(0);
   i2c_stop();
   return ret;
}

I got 0 every time... I guess I must be doing something really silly!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 23, 2011 6:49 pm     Reply with quote

The left-shifting biz only applies to the Philips-style i2c slave address.
It doesn't apply to commands, data, or anything else. See this recent
thread for more info:
http://www.ccsinfo.com/forum/viewtopic.php?t=45628&start=3

Modify your routine to use the GYRO_XOUT_L address as given in the
ITG-3200 data sheet.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group