| Author |
Message |
|
|
Posted: Aug 18, 2011 - 12:15 PM |
|

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
?? |
|
|
| |
|
|
|
|
|
Posted: Aug 18, 2011 - 12:24 PM |
|


Joined: Jul 18, 2005
Posts: 62220
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. |
_________________
|
| |
|
|
|
|
|
Posted: Aug 18, 2011 - 12:31 PM |
|


Joined: Nov 04, 2010
Posts: 2098
Location: Bristol, UK
|
|
|
|
|
|
|
Posted: Aug 19, 2011 - 10:45 AM |
|

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 |
|
|
| |
|
|
|
|
|
Posted: Aug 19, 2011 - 11:25 AM |
|

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. |
|
|
| |
|
|
|
|
|
Posted: Aug 25, 2011 - 08:29 AM |
|

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 ? |
|
|
| |
|
|
|
|
|
Posted: Aug 25, 2011 - 09:26 AM |
|


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!
|
| |
|
|
|
|
|
Posted: Aug 25, 2011 - 09:59 AM |
|

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 ?? |
|
|
| |
|
|
|
|
|
Posted: Aug 25, 2011 - 10:03 AM |
|

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. |
|
|
| |
|
|
|
|
|
Posted: Aug 25, 2011 - 10:33 AM |
|


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!
|
| |
|
|
|
|
|
Posted: Aug 25, 2011 - 10:50 AM |
|


Joined: Sep 20, 2003
Posts: 4061
Location: Surrey, England
|
|
|
|
|
|
|
Posted: Aug 25, 2011 - 04:07 PM |
|


Joined: Jul 18, 2005
Posts: 62220
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?) |
_________________
|
| |
|
|
|
|
|
Posted: Aug 26, 2011 - 05:28 AM |
|

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. |
|
|
| |
|
|
|
|
|
Posted: Aug 26, 2011 - 08:38 AM |
|

Joined: Feb 12, 2005
Posts: 16259
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. |
|
|
| |
|
|
|
|
|
Posted: Aug 26, 2011 - 09:43 AM |
|


Joined: Sep 20, 2003
Posts: 4061
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. |
|
|
| |
|
|
|
|
|
Posted: Aug 26, 2011 - 11:14 AM |
|

Joined: Feb 12, 2005
Posts: 16259
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. |
|
|
| |
|
|
|
|
|
Posted: Aug 26, 2011 - 01:04 PM |
|


Joined: Sep 20, 2003
Posts: 4061
Location: Surrey, England
|
|
|
|
|
|
|