cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Multimaster

Peter Morrow
Associate II
Posted on January 12, 2018 at 11:12

Hi,

We have a 'distributed' system in place where we have a single I2C master (STM32F7) and a number of I2C slaves (STM32F0).  I understand that I2C multimaster is supported, where you have a number of masters speaking to a number of slaves.  What I'd like to understand is it is possible to run an I2C bus on any microcontroller (F0 or F7) in master AND slave mode.  Ideally we'd have another bus but we don't have that luxury unfortunately.  The scenario is we'd like to send messages over I2C from F7 (master) to F0 (slave), but we'd like like to also initiate messages from the F0 back to the F7.

Could someone shed some light on whether this is possible without disabling and re-enabling the I2C peripheral on the fly?  Effectively we want I2C masters to be able to listen for async messages received from other MCUs.

Thanks,

Peter.

10 REPLIES 10
Andrew Neil
Chief II
Posted on January 12, 2018 at 13:41

Because of the forum shambles, I can't see the whole of the question:

0690X00000609LSQAY.png

Hopefully, this will make it appear in my 'inbox' view ...

Danish1
Lead II
Posted on January 12, 2018 at 13:59

The reference manual for stm32f7 claims this is possible.

33.4.3 

Mode selection

The interface can operate in one of the four following modes:

  • Slave transmitter

  • Slave receiver

  • Master transmitter

  • Master receiver

    By default, it operates in slave mode. The interface automatically switches from slave to master when it generates a START condition, and from master to slave if an arbitration loss or a STOP generation occurs, allowing multimaster capability.

My reading is that you set up the slave address and master timing, then leave the interface in slave mode.

Then if a given stm32 wants to become master, it just needs to set START in I2C_CR2. You'll need to cope with loss-of-arbitration interrupts.

I haven't tried it myself but it looks possible to me.

Danish

Posted on January 12, 2018 at 13:52

As you say, MultiMaster should be supported, so this should work.

However, watching a colleague's recent battles, it seems that it is very rarely used - so you will be on your own.

we'd like like to also initiate messages from the F0 back to the F7.

Why?

I think you are making a whole lot of trouble for yourself by doing that - it will be far simpler if you just stick to the standard single-master approach.

But, if you must, you could look at this: 

http://www.chibios.com/forum/viewtopic.php?t=1597

 
Posted on January 12, 2018 at 14:05

Hi Andrew,

Thanks for your reply.  I'd love to stick to the normal master-slave approach but this is where we are   We may end up just using a gpio to signal back from the F0 to the F7.  The reason for doing this is we'd like to initiate long running tasks on the slaves (via I2C), then have the slave asynchronously signal completion back to the master (instead of the master polling the slave for completion).  There will be many types of events, so using a gpio may get complication - thus having using something like I2C would help since we need to convey some context back from the F0 to the F7.

I'll have a look at the link you've suggested.

Peter.

Posted on January 12, 2018 at 14:07

Thanks Danish, this looks promising.

I had tried this already (using the HAL APIs) but had not luck so far, though admittedly I only spend a day on it.  I think I need to try a bit harder, I'll let you know how it goes.

Cheers,

Peter.

Posted on January 12, 2018 at 14:11

As I said, no argument that it should be possible - just whether it's worth the effort.

It seems to be a very, very rarely (if ever) used case - so it's likely that you will be on your own, in uncharted water, having to find & fix all the bugs & gotchas! yourself...

Do you have good tools for analysing I2C bus traffic?

Posted on January 12, 2018 at 14:24

We have plenty of tools for analysing the bus, so no issue there - I do agree with you it's going to likely be a pain (I was loathed to even post this).  I suspect we are going to stick with a simple GPIO based notification for now.

Posted on January 12, 2018 at 14:30

Peter Morrow wrote:

I suspect we are going to stick with a simple GPIO based notification for now.

I suspect that may turn out to be the wise move ...

Posted on January 12, 2018 at 14:40

it's likely that you will be on your own, in uncharted water, having to find & fix all the bugs & gotchas! yourself...

Sounds very much like my everyday job.

Having used multimaster in this setup (every node is both master and slave) but on AVRs rather than STM32. Lesson learned: checksum a lot and be ready to bail out through a timeout.

Btw. on 'F4's I2C, timeout appears to be a must in single-master setup too.

JW