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 Previous  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: 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: 19268

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: 1917
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: 19268

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: 19268

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
bkamen



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

View user's profile Send private message

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

Mahdi wrote:

I'm using 16f877a.



I'm curious.

Are you doing this for for class or for work or for personal fun?

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



Joined: 14 Mar 2005
Posts: 159

View user's profile Send private message

PostPosted: Fri Aug 24, 2012 11:05 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.

Best Wishes


Thanks! I'm in a design now where I'm pulled up to 3V using hardware i2c, and everything seems to be working. I'm on an 18f, and in i2c mode Vih is 0.7 Vdd, so it shouldn't and does, but I'll assume it won't do so reliably! The plan is to isolate this part of the 12c bus anyway, so I'll just have the microcontroller bus pulled to 5v anyway, but it's nice to know!
Mahdi



Joined: 21 Aug 2012
Posts: 47

View user's profile Send private message

PostPosted: Fri Aug 24, 2012 1:54 pm     Reply with quote

bkamen wrote:
Mahdi wrote:

I'm using 16f877a.



I'm curious.

Are you doing this for for class or for work or for personal fun?

-Ben


for a project
Mahdi



Joined: 21 Aug 2012
Posts: 47

View user's profile Send private message

PostPosted: Fri Aug 24, 2012 1:57 pm     Reply with quote

sseidman wrote:
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.

Best Wishes


Thanks! I'm in a design now where I'm pulled up to 3V using hardware i2c, and everything seems to be working. I'm on an 18f, and in i2c mode Vih is 0.7 Vdd, so it shouldn't and does, but I'll assume it won't do so reliably! The plan is to isolate this part of the 12c bus anyway, so I'll just have the microcontroller bus pulled to 5v anyway, but it's nice to know!

my 16f877 i2c with 3 volt work but unstable
bkamen



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

View user's profile Send private message

PostPosted: Fri Aug 24, 2012 2:02 pm     Reply with quote

Mahdi wrote:
for a project


And that would be a project for school? Work? Personal Fun?
_________________
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 Previous  1, 2, 3, 4  Next
Page 2 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