Go Down

Topic: Two simultaneus I2C communication (Read 1 time) previous topic - next topic

cstockmans

Jan 12, 2011, 10:59 am Last Edit: Jan 12, 2011, 11:10 am by cstockmans Reason: 1
Hi!

I'm working on a project where i connect LEGO Mindstorms NXT robot with Arduino usin the I2C protocol. And i want also to connect some sensors to the Arduino board, so it will be something like this: Mindstorms <--> Arduino <--> Sensor.

I want Arduino to be the slave in the communicaction with the robot, and to be the master in the communication with the sensors. Is this possible? Can i do both simultaneously?

I know that for I2C communication i have to use the pins 4 and 5 of the analog input, and i'm using Arduino MEGA board.

Thanks a lot (and i apologise for my english, it's not perfect).

Grumpy_Mike

#1
Jan 12, 2011, 11:05 am Last Edit: Jan 12, 2011, 11:07 am by Grumpy_Mike Reason: 1
Quote
Is this possible?


The I2C specification does cater for multi master bussed. So in theory it is.

However there are two snags:-
1) I don't know of any multi master software.
2) The Lego uses a 3v3 I2C bus and the sensors might need a 5V bus so you will need some hardware bus level shifters.

Quote
Can i do both simultaneously?

You can do nothing simultaneously on a single processor, you do them sequentially very fast so it looks like simultaneously.

Quote
I know thath for I2C communication i have to use the pins 4 and 5 of the analog input,

It is not those pins on a mega it is pins 20 & 21

cstockmans

Thanks for your answer :)

Quote
You can do nothing simultaneously on a single processor, you do them sequentially very fast so it looks like simultaneously.


Yes, you're right. Is what i wanted to say: first Arduino is the slave and receives instructions from de Mindstorm, and then is the master for the sensors, sending the instructions to them. It's not simulatenous.

Quote
It is not those pins on a mega it is pins 20 & 21


Oooops! I was confused because i've just been reading about the Arduino Duemilanove board. Thanks!

Net Honcho

The arduino can be a slave and a master at the same time. Also the arduino supports multi masters on the same bus.
The big question: dose the mind storm support multi masters.
It is worth a try.

cstockmans

Mindstorm doesn't support multi masters. I think i'm going to do this using software I2C, using two analog pins of Arduino to communicate with the sensors, and the two I2C pins to communicate with the robot.

Net Honcho

One trick my be to poll your slave just after the mind storm polls you.
The thought process is that the mind storm polls it's slave (your arduino) in a regular cycle. If the bus is idle just after the poll, you may have time to poll your slave.

wayneft

Quote
2) The Lego uses a 3v3 I2C bus and the sensors might need a 5V bus so you will need some hardware bus level shifters.


Actually you can use this snag to your advantage.  Since you'll need a level shifter use an IC like a TXS0102 that has an output enable pin.  Once the mindstorm is done communicating with the Arduino, drive the output enable LOW and force the bus between the mindstorm and Arduino into a Hi-Z state.  If the mindstorm tries to poll the Arduino it won't get a response and will leave you free to communicate with the rest of the sensors.  Just make sure the sensors are all wired downstream of the level shifter.  Also if the sensors can handle Fast Mode (400kHz) bump up the I2C speed when communicating with them, that should minimize timing concerns.
I2C GPS Shield

Checkout my Open Source GPS Tracker on Kickstarter

cstockmans

Thanks to both :)

Quote
One trick my be to poll your slave just after the mind storm polls you.


That's an option that i was thinking about, but i'm not shure if it will works. I will try it :)

Quote
ally you can use this snag to your advantage.  Since you'll need a level shifter use an IC like a TXS0102 that has an output enable pin.  Once the mindstorm is done communicating with the Arduino, drive the output enable LOW and force the bus between the mindstorm and Arduino into a Hi-Z state.  If the mindstorm tries to poll the Arduino it won't get a response and will leave you free to communicate with the rest of the sensors.  Just make sure the sensors are all wired downstream of the level shifter.  Also if the sensors can handle Fast Mode (400kHz) bump up the I2C speed when communicating with them, that should minimize timing concerns.


It's another good option :) Thanks!

Go Up