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 support@ccsinfo.com

how to connect to mpu6050 gyro sensor-i2c?
Goto page 1, 2, 3, 4  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 22, 2012 2:45 pm     Reply with quote

Quote:
Wide operating voltage range: 2.0V to 5.5V

That wide range is only for the "LF" version of the 877A.
The part number is PIC16LF877A.

But, you can use an 3v i2c slave with a 5v PIC, if you use software i2c
on PortB, which is a TTL-compatible i/o port.

In software i2c, the i2c bits are sent and received by "bit banging" with
the i/o port pins. On PortB, the Vih (high level input voltage) is 2.0 volts.
This is true even if the Vdd for the PIC is 5.0 volts.

So, you can use pull-ups on the i2c bus that pull-up to +3.0v, and it works
perfectly well with the TTL-compatible inputs on PortB. You can use
3.3K ohm resistors for the pull-ups on the SCL and SDA lines.

This technique does not work with hardware i2c, where the PIC is running
at +5v for Vdd. It requires software i2c. The CCS #use i2c() library
supports software i2c. Software i2c is the default case for that library.
So, it's no problem to do it.


Quote:
device address:0x68

That's the slave address in 7-bit Philips format. But CCS doesn't use that
format. CCS uses 8-bit format. To convert to CCS format, just shift
the Philips address left by 1 bit position. So, the correct addresses to
use with the i2c_write() function are:

CCS i2c slave write address = 0xd0
CCS i2c slave read address = 0xd1

This assumes that you have connected pin 9 on the MPU-6050 to ground.


Here is a link to the i2c bus scanner program. Modify the first few lines
of the program (#include, #fuses, #use delay, #use rs232) to fit your
PIC and your board:
http://www.ccsinfo.com/forum/viewtopic.php?t=47707&start=21
This program will tell you if the PIC can find the MPU-6050 on the i2c bus.
Ttelmah



Joined: 11 Mar 2010
Posts: 19350

View user's profile Send private message

PostPosted: Thu Aug 23, 2012 2:06 am     Reply with quote

As a further comment, the F877, will probably run at 3.3v, _but will not be reliable_. Get the LF variant.
This is down to 'read the data sheet, not just the header'. The sheet covers both chip versions, and _between them_, the two chip types have the 'wide operating voltage range' mentioned.....

Best Wishes
Mahdi



Joined: 21 Aug 2012
Posts: 47

View user's profile Send private message

PostPosted: Thu Aug 23, 2012 6:42 am     Reply with quote

thanks alot pcm programer

Ttelmah wrote:
As a further comment, the F877, will probably run at 3.3v, _but will not be reliable_. Get the LF variant.
This is down to 'read the data sheet, not just the header'. The sheet covers both chip versions, and _between them_, the two chip types have the 'wide operating voltage range' mentioned.....

Best Wishes




Ttelmah your answer is right.but the LF frequency is low.until to 10Mhz
and it receive alot of noise.There is no way that I use the 16f?
for example use the resistor in scl and sda line or use 3.0v Zener diode?
i dont understand this part
Quote:

But, you can use an 3v i2c slave with a 5v PIC, if you use software i2c
on PortB, which is a TTL-compatible i/o port.
Ttelmah



Joined: 11 Mar 2010
Posts: 19350

View user's profile Send private message

PostPosted: Thu Aug 23, 2012 7:30 am     Reply with quote

This is down to input threshold levels.
A 'TTL' port pin, is considered to be 'high', if it is above 2.4v. A Schmitt port pin, is only considered 'high', when it gets to 4v (with a PIC running at 5v).
The hardware I2C input, uses a Schmitt buffer.
So a 3.3v device connected to a 5v PIC, using the hardware I2C, won't work. However you can connect such a device to a software I2C port provided you choose pins that have TTL input buffers (data sheet).
Fortunately, CCS provides software I2C just as easily as hardware.

Since I2C is an 'open collector' bus (the chips only drive downwards), the outputs from the PIC will drive the lines fine.

Wiring then has to be:
Run the PIC off 5v
Choose PIC pins with TTL input buffers.
Select these in #use I2C
Connect the PIC I2C pins to the 3v device.
Have the I2C pullups, go to the 3v rail (remember that lower rail voltage means smaller resistors will be needed - typically 4K7 is quite OK for short busses at 5v, but at 3v, you need 2K7 to give the same bus drive).

Best Wishes
Mahdi



Joined: 21 Aug 2012
Posts: 47

View user's profile Send private message

PostPosted: Thu Aug 23, 2012 8:19 am     Reply with quote

This could can use? with 2.2 and 3.3 resistor the out put of micro has 3 volt
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 23, 2012 11:49 am     Reply with quote

Quote:
A 'TTL' port pin, is considered to be 'high', if it is above 2.4v.

The 16F877A data sheet says the Vih is 2.0v:
Code:

17.2 DC Characteristics

Input High Voltage:

Param  Sym    Characteristic    Min       Conditions
No.
D040   VIH    with TTL buffer:  2.0v      4.5V <= VDD <= 5.5V

I agree that TTL outputs (Voh) (in general, not on this PIC)
are specified at a minimum of 2.4v to provide some noise margin.
Ttelmah



Joined: 11 Mar 2010
Posts: 19350

View user's profile Send private message

PostPosted: Thu Aug 23, 2012 2:41 pm     Reply with quote

Mahdi wrote:
This could can use? with 2.2 and 3.3 resistor the out put of micro has 3 volt



No.

Remember the I2C bus is an _open collector_ bus. The drives on both the sensor, and the PIC, only pull 'down'. It relies on the resistor to pull up.
You only need a single resistor on each line going to the 3v supply, and the line connects directly between the devices. Remember that on the data line signals travel in both directions, what you show would attenuate a logic output that drives both high and low, that is then driving an input, but won't work in the other direction, and won't work with I2C, since it pulls the signals down, and they need to be pulled up.

On the 2.4/2v, yes. I hadn't checked what the 877 considers to be a 'high', and used the figure from the Texas TTL data book.

Best Wishes
sseidman



Joined: 14 Mar 2005
Posts: 159

View user's profile Send private message

PostPosted: Thu Aug 23, 2012 3:25 pm     Reply with quote

People often use mosfets to change levels in i2c -- http://ics.nxp.com/support/documents/interface/pdf/an97055.pdf --

This seems to be more of a problem when you have i2c devices with different Vcc than with a 5v master and 3v device. Even for hardware i2c, I just pull up sda and scl to 3 volts and everything just seems to work!

Scott
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Thu Aug 23, 2012 9:02 pm     Reply with quote

You can also do this:
Code:

                                 +3.3V
                                   \
                                   /
                                   \  4.7K (rough starting point)
                                   /
                                   |
5V GPIO ------- |<|-----I2C bus----o--------------------> Other I2C devices

Where the --|<|-- is a shottky diode.

When the GPIO goes low, it will sink the bus to 0.
When the GPIO goes high, when it hit 3.3, it will reverse bias and shut off.

Another option for the GPIO control is to set the port bit to 0 (low) and then toggle the Tri-State (TRIS) bit between 0 (output) and 1 (Hi-Z input)...

but you still should keep the diode arrangement above. -- just in case.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
dyeatman



Joined: 06 Sep 2003
Posts: 1924
Location: Norman, OK

View user's profile Send private message

PostPosted: Thu Aug 23, 2012 9:25 pm     Reply with quote

I have used 2n7000 mosfets in a number of my designs for I2C level
translation and they have worked flawlessly. I pay about 12 cents each in
quantity.
_________________
Google and Forum Search are some of your best tools!!!!
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Thu Aug 23, 2012 9:43 pm     Reply with quote

dyeatman wrote:
I have used 2n7000 mosfets in a number of my designs for I2C level
translation and they have worked flawlessly. I pay about 12 cents each in
quantity.


2n700(0|2)'s are fabulous. I use them all over the place.

But for this app, they aren't that required.. a diode works too.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Ttelmah



Joined: 11 Mar 2010
Posts: 19350

View user's profile Send private message

PostPosted: Fri Aug 24, 2012 2:03 am     Reply with quote

As has already been said by PCM programmer. The key thing is that if he uses a software I2C, no translation at all is needed. No diodes. No MOSFET's, etc. etc...
I2C, is already an open collector drive, with the bus only being driven low, or allowed to float.

All that is needed is:
Code:

            +3v
             |
             /
             \ (2K2 - 4K7, is too high for reliable 3v I2C)
             /
             |
PIC pin------o------ I2C device

On both the lines.
It really is this simple.

The pull up resistor allowed, for normal I2C, with 3v pullups, is 866R minimum, 3.2Kmax to meet fast mode timing requirements (unless the bus has very low capacitance <30pF)
Remember as I already mentioned that the resistor needed has to reduce with the supply voltage. 4K7, actually goes outside the recommended resistor range when using 3v pull ups.

Best Wishes
sseidman



Joined: 14 Mar 2005
Posts: 159

View user's profile Send private message

PostPosted: Fri Aug 24, 2012 6:15 am     Reply with quote

The MSSP is also open collector (actually open drain) in hardware i2c master mode-- fig 9.16 on the 16f87xa datasheet. I'm a bit confused about why people keep saying that it's open collector only in software mode. Is it because of the slave configuration?
Ttelmah



Joined: 11 Mar 2010
Posts: 19350

View user's profile Send private message

PostPosted: Fri Aug 24, 2012 7:15 am     Reply with quote

No, the reason that only software will work, is the input, not the output.
The hardware MSSP (I2C) module has a Vih, of 0.8* the PIC's Vdd. So with a 5v PIC, 4v. So if it is being being driven off an I2C device with the pull-ups going to 3v, it'll never see a 'high', and won't work....
This is the point about choosing pins with TTL input buffers, where Vih is low enough to happily work off the 3v device.

Best Wishes
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Fri Aug 24, 2012 9:47 am     Reply with quote

Ttelmah wrote:
No, the reason that only software will work, is the input, not the output.
The hardware MSSP (I2C) module has a Vih, of 0.8* the PIC's Vdd. So with a 5v PIC, 4v. So if it is being being driven off an I2C device with the pull-ups going to 3v, it'll never see a 'high', and won't work....
This is the point about choosing pins with TTL input buffers, where Vih is low enough to happily work off the 3v device.



That's a good point.. I work with the lower voltage devices so regularly now...

Ahhh, mixing I2C bus voltages... something I make it a point to avoid.
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2, 3, 4  Next
Page 1 of 4

 
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