Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
harshthegreat89
PostPosted: Aug 18, 2011 - 12:15 PM
Rookie


Joined: Jun 27, 2009
Posts: 41
Location: Ahmedabad, India

How do we decide the I2C address when using ATTINY as a:
1) Slave
2) Master

??
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Aug 18, 2011 - 12:24 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62354
Location: (using avr-gcc in) Finchingfield, Essex, England

You just pick any address that does not conflict with any other I2C in the design and on the same I2C bus.

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
gregsmithcts
PostPosted: Aug 18, 2011 - 12:31 PM
Raving lunatic


Joined: Nov 04, 2010
Posts: 2098
Location: Bristol, UK

http://www.nxp.com/acrobat_download2/selectionguides/SELGUIDE.PDF
This *might* help. Especially if you are planning on selling thousands of your smart new device Wink

_________________
--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
svmprasad
PostPosted: Aug 19, 2011 - 10:45 AM
Wannabe


Joined: May 14, 2008
Posts: 80
Location: UK

If you use it for testing you can choose any number between the I2C address range. If you decide to release I2C product, you have to look on other's addresses.

SVM Prasad
 
 View user's profile Send private message  
Reply with quote Back to top
th33lf
PostPosted: Aug 19, 2011 - 11:25 AM
Hangaround


Joined: Sep 29, 2010
Posts: 113


harshthegreat89 wrote:

2) Master
??


And the master always initiates all transactions, so it does not need an address for itself.

PS: All previous posts have been talking about slave mode, in case I've confused you.
 
 View user's profile Send private message  
Reply with quote Back to top
harshthegreat89
PostPosted: Aug 25, 2011 - 08:29 AM
Rookie


Joined: Jun 27, 2009
Posts: 41
Location: Ahmedabad, India

I searched the whole datasheet of ATtiny2313, but could not find the specification for range of I2C addresses supported by it.

Also how do I select the I2C address ? I mean has it to be hardwired ? Is it to be set programatically through some registers ?
 
 View user's profile Send private message  
Reply with quote Back to top
gregsmithcts
PostPosted: Aug 25, 2011 - 09:26 AM
Raving lunatic


Joined: Nov 04, 2010
Posts: 2098
Location: Bristol, UK

As a Master, it has no address. As a slave, you choose. It's all in the datasheet. Look again.
Oh, and re-read the replies already given!

ps. Does the T2313 even have a TWI module?

http://en.wikipedia.org/wiki/I%C2%B2C

_________________
--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
harshthegreat89
PostPosted: Aug 25, 2011 - 09:59 AM
Rookie


Joined: Jun 27, 2009
Posts: 41
Location: Ahmedabad, India

I searched a lot on google but not able to find anything related to the range of addresses.

Can we select any address from 0 to 127 ??
 
 View user's profile Send private message  
Reply with quote Back to top
harshthegreat89
PostPosted: Aug 25, 2011 - 10:03 AM
Rookie


Joined: Jun 27, 2009
Posts: 41
Location: Ahmedabad, India

gregsmithcts wrote:
.... Does the T2313 even have a TWI module?
http://en.wikipedia.org/wiki/I%C2%B2C

Yes, it has a USI (Universal Serial Interface) which supports 'Two-wire Synchronous Data Transfer'.

gregsmithcts wrote:
.... It's all in the datasheet ....

In the datasheet nothing has been mentioned related to the address selection.
 
 View user's profile Send private message  
Reply with quote Back to top
gregsmithcts
PostPosted: Aug 25, 2011 - 10:33 AM
Raving lunatic


Joined: Nov 04, 2010
Posts: 2098
Location: Bristol, UK

I'm not sure where your confusion is comming from...
Is your question (1)'How do I set the slave address?' or is it (2) 'What slave address should I set?'

If it's (1), surely thats answered in the datasheet?
If it's (2), I've already posted links that describe the protocol, and a link to already allocated address held on file by Phillips/NXP.

If the device you are building is a one off, just for your own use, clawsons reply says it all.

_________________
--greg
Still learning, don't shout at me, educate me.
Starting the fire is easy; the hardest part is learning how to keep the flame!
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
John_A_Brown
PostPosted: Aug 25, 2011 - 10:50 AM
Raving lunatic


Joined: Sep 20, 2003
Posts: 4080
Location: Surrey, England

http://atmel.com/dyn/resources/prod_documents/doc2560.pdf
You do the slave address matching in your software.
This link gives more info.

http://www.google.co.uk/url?sa=t&source=web&cd=14&ved=0CDEQFjADOAo&url=http%3A%2F%2Felk.informatik.fh-augsburg.de%2Fda%2Fda-48%2Fsource%2FATtiny44%2Fpmbus_patched%2Fusi_i2c_slave.c&rct=j&q=atmel%20usi%20in%20twi%20mode&ei=txtWTsnJCsODhQeP_dC1DA&usg=AFQjCNEPXD0CdTXoCGlkMhlihVDQD3H_Ow&cad=rja

And this link gives C code.
 
 View user's profile Send private message  
Reply with quote Back to top
clawson
PostPosted: Aug 25, 2011 - 04:07 PM
10k+ Postman


Joined: Jul 18, 2005
Posts: 62354
Location: (using avr-gcc in) Finchingfield, Essex, England

Quote:

You just pick any address that does not conflict with any other I2C in the design and on the same I2C bus.

(wonder which bit of this you didn't understand?)

_________________
 
 View user's profile Send private message  
Reply with quote Back to top
harshthegreat89
PostPosted: Aug 26, 2011 - 05:28 AM
Rookie


Joined: Jun 27, 2009
Posts: 41
Location: Ahmedabad, India

clawson wrote:
Quote:

You just pick any address that does not conflict with any other I2C in the design and on the same I2C bus.

(wonder which bit of this you didn't understand?)


Thanks everyone for your replies, actually I was under the impression that we have to select the address as we do in other I2C devices, i.e. hardwiring the pins, programatically writing in registers, etc.

Now I figured out from an example code that this address comparision in done in software/program. This was very simple after I figured this out but I must say that this information is not mentioned clearly anywhere in the datasheet.
 
 View user's profile Send private message  
Reply with quote Back to top
david.prentice
PostPosted: Aug 26, 2011 - 08:38 AM
10k+ Postman


Joined: Feb 12, 2005
Posts: 16324
Location: Wormshill, England

Hardware I2C chips tend to have their Slave address with a fixed number. Some then allow you to select alternative addresses via the hardware pins. e.g.
Code:

// 24Cxxx eeproms
// 0b10100000    default
// 0b10100010    A0=1
// 0b10100100    A1=1
// 0b10100110    A0=1, A1=1
// 0b10101000    A2=1
// 0b10101010    A0=1, A2=1
...

You note that addresses used by memory chips tend to be (note bit #0 is always the R/W bit)
Code:
// 0b1010xxx0


So you can connect 8 of these chips onto the bus at once (if you select unique A0,A1,A2 hardware pins)


If you read the NXP documents, you will see that the device Slave addresses follow a general plan.

If you are using a microcontroller as a Master, you 'speak to' whichever Slaves you want.
If you are using a microcontroller as a Slave, you choose a suitable address yourself.

No microcontroller data sheet will choose either for you. Greg's reply should have got you started.

David.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
John_A_Brown
PostPosted: Aug 26, 2011 - 09:43 AM
Raving lunatic


Joined: Sep 20, 2003
Posts: 4080
Location: Surrey, England

harshthegreat89 wrote:
clawson wrote:
Quote:

You just pick any address that does not conflict with any other I2C in the design and on the same I2C bus.

(wonder which bit of this you didn't understand?)


Thanks everyone for your replies, actually I was under the impression that we have to select the address as we do in other I2C devices, i.e. hardwiring the pins, programatically writing in registers, etc.

Now I figured out from an example code that this address comparision in done in software/program. This was very simple after I figured this out but I must say that this information is not mentioned clearly anywhere in the datasheet.

If you were using an AVR with "proper" I2C hardware, there would indeed be a register that set the slave address(when using the AVR as a slave), but the USI hardware doesn't have this facility. Having read the datasheet for the 2313, I would have to agree with you that it could do with some clarification.
 
 View user's profile Send private message  
Reply with quote Back to top
david.prentice
PostPosted: Aug 26, 2011 - 11:14 AM
10k+ Postman


Joined: Feb 12, 2005
Posts: 16324
Location: Wormshill, England

Ah-ha, I get your point. The USI has no TWAR register. In fact the whole I2C 'functionality' is considerably inferior to a Mega's TWI.

OTOH, you can implement multiple Slaves with USI very easily.
The old mega16/32/64/128 can only ever be a single Slave (=TWAR)

The newer megas have TWMR (address mask register). So you can respond to multiple Slave addresses, providing you can produce a unique mask.

David.
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
John_A_Brown
PostPosted: Aug 26, 2011 - 01:04 PM
Raving lunatic


Joined: Sep 20, 2003
Posts: 4080
Location: Surrey, England

Quote:
OTOH, you can implement multiple Slaves with USI very easily.

So could be useful for an I2C "sniffer" project.
Bit late for me, as I splashed out on a
http://www.thedebugstore.com/acatalog/Total-Phase-I2C-Bus-Analysers.html
a couple of years ago.
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits