Author Topic: I2C questions  (Read 2330 times)

0 Members and 1 Guest are viewing this topic.

Offline galannthegreatTopic starter

  • Supreme Robot
  • *****
  • Posts: 615
  • Helpful? 4
  • Blue-Lensed Blue LEDs?! What?! Impossible!!
I2C questions
« on: October 05, 2009, 11:10:01 PM »
I have been reading that I2C is a communication system that can address different types of devices only, not the same (due to the address being the same),. Is this true? Can I communicate between multiple MEGA328's (as my new project will need me to)? Or should I consider SPI instead?

Thanks, Kurt.
Kurt

Offline Joker94

  • Supreme Robot
  • *****
  • Posts: 1,119
  • Helpful? 26
Re: I2C questions
« Reply #1 on: October 06, 2009, 12:33:24 AM »
From what i understand you can, all you have to do is have the main Atmega328 as the master of the I2C system and all the others as the slaves.

As far as i was aware I2C is how the old SoR community project was going to communicate between all the modules. So again from what read i say yer you can communicate through I2C between your Mega328 MCU's.

Offline SmAsH

  • Supreme Robot
  • *****
  • Posts: 3,959
  • Helpful? 75
  • SoR's Locale Electronics Nut.
Re: I2C questions
« Reply #2 on: October 06, 2009, 03:02:19 AM »
Well sure they can, normally for this kind of situation the I2C addresses can be configured differently...
Read up a bit and im sure you can find something about configuring I2C addresses.
Howdy

Offline chelmi

  • Supreme Robot
  • *****
  • Posts: 496
  • Helpful? 15
    • Current projects

Offline galannthegreatTopic starter

  • Supreme Robot
  • *****
  • Posts: 615
  • Helpful? 4
  • Blue-Lensed Blue LEDs?! What?! Impossible!!
Re: I2C questions
« Reply #4 on: October 06, 2009, 02:26:20 PM »
Hmm... I've been looking at the material you posted, thanks btw, and now I'm thinking that I may want to explore more possibilites. Is there other means of intercommunication between like devices that would work here? (I am looking to intercommunicate between 3-9(or more) devices, most likely being MEGA328s or MEGA168s.)
Kurt

Offline chelmi

  • Supreme Robot
  • *****
  • Posts: 496
  • Helpful? 15
    • Current projects
Re: I2C questions
« Reply #5 on: October 06, 2009, 02:52:43 PM »
Hmm... I've been looking at the material you posted, thanks btw, and now I'm thinking that I may want to explore more possibilites. Is there other means of intercommunication between like devices that would work here? (I am looking to intercommunicate between 3-9(or more) devices, most likely being MEGA328s or MEGA168s.)

There are many possibilities, I2C is probably one of the simplest. Other than that there is SPI that could be used as well, and probably more.
Is there something in I2C that you don't like?

Chelmi.

Offline galannthegreatTopic starter

  • Supreme Robot
  • *****
  • Posts: 615
  • Helpful? 4
  • Blue-Lensed Blue LEDs?! What?! Impossible!!
Re: I2C questions
« Reply #6 on: October 06, 2009, 03:11:15 PM »
Well,  just that I don't even know how I'm going to go about changing the addresses (the 3 bits that are apparently configurable) of each controller of the same type (ie. I need control over a device because it will have a different purpose), as I want to use the same type of device through out so that I can have my code to be able to be transfered and updated easily through out the entire system.
Kurt

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: I2C questions
« Reply #7 on: October 06, 2009, 04:42:18 PM »
What I2C devices are you planning to use? Part number?
Most of these do have a few external pins that are used to set a unique address even for the same part number device.

Offline galannthegreatTopic starter

  • Supreme Robot
  • *****
  • Posts: 615
  • Helpful? 4
  • Blue-Lensed Blue LEDs?! What?! Impossible!!
Re: I2C questions
« Reply #8 on: October 06, 2009, 04:45:09 PM »
Multiple ATMEGA328s or 168s, pretty much every device in the system will be the same.
Kurt

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,165
  • Helpful? 111
    • Webbot stuff
Re: I2C questions
« Reply #9 on: October 06, 2009, 06:59:11 PM »
If you are connecting mcus together then you can set the address of each slave device in software to any address you like. So its dead easy.

The restriction you elude to is when you buy a commercial sensor which may only have one fixed address or a choice of a few addresses. Otherwise each sensor would need loads of switches to allow you to set the address.

SPI on the other hand doesn't use a unique address for each slave but instead would require one digital I/O pin on the master cpu to 'select' which slave device you are talking to. Also - since the mcu is probably also the SPI bus for its ISP programmer interface then you need to add some resistors to isolate the ISP programming header from the rest of the devices.

I advise using I2C. If 'YOU' are writing the software on each mcu then you can set the address to 'ANY' of the possible 127 different addresses.

Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline galannthegreatTopic starter

  • Supreme Robot
  • *****
  • Posts: 615
  • Helpful? 4
  • Blue-Lensed Blue LEDs?! What?! Impossible!!
Re: I2C questions
« Reply #10 on: October 06, 2009, 08:18:19 PM »
Thanks, I was hoping that there would be a way that this would work, and by looking at I2C it makes more sense than the other options to me.

Could you give an example or a link in which will show me how I could define my own addresses?

Thanks for your help, Kurt.
Kurt

Offline chelmi

  • Supreme Robot
  • *****
  • Posts: 496
  • Helpful? 15
    • Current projects
Re: I2C questions
« Reply #11 on: October 06, 2009, 08:29:35 PM »
Take a look at the applications notes on the Atmel's web site.
http://atmel.com/dyn/products/app_notes.asp?family_id=607

AVR310 and AVR311 are what you're looking for.

Chelmi.

Offline galannthegreatTopic starter

  • Supreme Robot
  • *****
  • Posts: 615
  • Helpful? 4
  • Blue-Lensed Blue LEDs?! What?! Impossible!!
Re: I2C questions
« Reply #12 on: October 06, 2009, 09:00:05 PM »
Sweet, thanks chelmi, I also found one on slaves a few below the ones you told me to look at, and it shows some very easy ways of defining my own addresses. :)
Kurt