Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Thread

Looking for i2c (TWI) using USI example (AVR Butterfly ATmega169)

Looking for i2c (TWI) using USI example (AVR Butterfly ATmega169)

2006-12-15 by James Ronald

Tonight I tried to compile the i2c examples in AVRlib.  I found that the AVR 
Butterfly does not support i2c the same as the ATmega8, 128, 16, 163 and 
such.  Instead, the 169 uses the USI to do TWI.   I did find Atmel 
application note 310 which describes how to go about setting up USI to do 
TWI but I was hoping to find another example as well.  I have searched for 
the past few hours with little luck.  I'm surprised that I could not find 
examples of connecting an AVR Butterfly to a SRF08 an i2c compus or such. 
Anyway, if anyone has a TWI USI example I would be appreciative.

Much Thanks
Jim Ronald

Re: [AVR-Chat] Looking for i2c (TWI) using USI example (AVR Butterfly ATmega169)

2006-12-15 by Dave Hylands

Hi James,

On 12/14/06, James Ronald <jronald@chartermi.net> wrote:
> Tonight I tried to compile the i2c examples in AVRlib.  I found that the AVR
> Butterfly does not support i2c the same as the ATmega8, 128, 16, 163 and
> such.  Instead, the 169 uses the USI to do TWI.   I did find Atmel
> application note 310 which describes how to go about setting up USI to do
> TWI but I was hoping to find another example as well.  I have searched for
> the past few hours with little luck.  I'm surprised that I could not find
> examples of connecting an AVR Butterfly to a SRF08 an i2c compus or such.
> Anyway, if anyone has a TWI USI example I would be appreciative.

The openservo project: http://www.openservo.com/ was originally
designed for the AVR Tiny45/85 and it uses USI
http://www.openservo.com/viewcvs/viewcvs.cgi/OpenServo/ATtinyX5_Bootloader/

-- 
Dave Hylands
Vancouver, BC, Canada
http://www.DaveHylands.com/

Re: [AVR-Chat] Looking for i2c (TWI) using USI example (AVR Butterfly ATmega169)

2006-12-19 by James Ronald

> On 12/14/06, James Ronald <jronald@chartermi.net> wrote:
>> Tonight I tried to compile the i2c examples in AVRlib.  I found that the 
>> AVR
>> Butterfly does not support i2c the same as the ATmega8, 128, 16, 163 and
>> such.  Instead, the 169 uses the USI to do TWI.   I did find Atmel
>> application note 310 which describes how to go about setting up USI to do
>> TWI but I was hoping to find another example as well.  I have searched 
>> for
>> the past few hours with little luck.  I'm surprised that I could not find
>> examples of connecting an AVR Butterfly to a SRF08 an i2c compus or such.
>> Anyway, if anyone has a TWI USI example I would be appreciative.
>
> The openservo project: http://www.openservo.com/ was originally
> designed for the AVR Tiny45/85 and it uses USI
> http://www.openservo.com/viewcvs/viewcvs.cgi/OpenServo/ATtinyX5_Bootloader/
>
> -- 
> Dave Hylands

Thanks for the link Dave.  It looks like a good starting point.  I was 
hoping to just put USI into TWI mode and just map the USI to TWI register 
names and such.  It looks like it's going to be quite involved and is going 
to take some time to figure out.  Other than the openservo project it looks 
like projects needing TWI (i2c) just stayed away from the USI 
implementation.  I mean if professional developers are shying away from USI 
implementations of TWI should I as a hobbyist?  Am I just wasting my time?

Re: [AVR-Chat] Looking for i2c (TWI) using USI example (AVR Butterfly ATmega169)

2006-12-19 by Dave Hylands

Hi James,

> Thanks for the link Dave.  It looks like a good starting point.  I was
> hoping to just put USI into TWI mode and just map the USI to TWI register
> names and such.  It looks like it's going to be quite involved and is going
> to take some time to figure out.  Other than the openservo project it looks
> like projects needing TWI (i2c) just stayed away from the USI
> implementation.  I mean if professional developers are shying away from USI
> implementations of TWI should I as a hobbyist?  Am I just wasting my time?

Not necessarily.

I mean, lots of people do bit-banged i2c. Using USI allows the
hardware to deal with a bunch of the bit manipulations. So using USI
will consume less CPU than using bit-banged i2c. But bit-banged i2c is
probably easier to understand just by looking at the code and is
probably portable to many more platforms.

So it all depends on what your constraints are, what type of
performance you're trying to achieve and how much CPU you have.

-- 
Dave Hylands
Vancouver, BC, Canada
http://www.DaveHylands.com/

Re: [AVR-Chat] Looking for i2c (TWI) using USI example (AVR Butterfly ATmega169)

2006-12-19 by David Kelly

On Tue, Dec 19, 2006 at 01:38:29PM -0800, Dave Hylands wrote:
> 
> I mean, lots of people do bit-banged i2c. Using USI allows the
> hardware to deal with a bunch of the bit manipulations. So using USI
> will consume less CPU than using bit-banged i2c. But bit-banged i2c is
> probably easier to understand just by looking at the code and is
> probably portable to many more platforms.

Sometimes (on SPI that I know of) the target hardware has registers
which are not multiples of 8 bits. One can bitbang shift exactly the
proper amount of bits and alignment in CPU variables is totally under
your own control.

If using hardware SPI one typically must shift multiples of 8 bits.
Generally this isn't a problem for odd sized SPI targets but one has to
know where these extra bits end up on the target. Hopefully in the bit
bucket. Usually the last bits one sends are the important bits, but the
first bits one receives are the important bits.

Sometimes I use hardware, sometimes I bit bang, it all depends on the
situation.

-- 
David Kelly N4HHE, dkelly@HiWAAY.net
========================================================================
Whom computers would destroy, they must first drive mad.

Re: [AVR-Chat] Looking for i2c (TWI) using USI example (AVR Butterfly ATmega169)

2006-12-19 by John Samperi

At 10:07 AM 20/12/2006, you wrote:
>I would be happy to supply PIC code for I2C if you dont mind converting it?

What's wrong with AVR300 (Master) and AVR302 (slave) Atmel's
application notes? I have used the master bit banged TWI code
and it works very well. Tried to use the USI but I gave up,
it was much easier in my application to use the bit banged version
so that I wasn't tied up to any pins. Perhaps one day someone (or me??)
will convert both of the above app notes to work with the USI.

Regards

John Samperi

********************************************************
Ampertronics Pty. Ltd.
11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
Tel. (02) 9674-6495       Fax (02) 9674-8745
Email: john@ampertronics.com.au
Website  http://www.ampertronics.com.au
*Electronic Design * Custom Products * Contract Assembly
********************************************************

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.