2018-01-12 02:12 AM
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.
2018-01-12 04:41 AM
Because of the forum shambles, I can't see the whole of the question:
Hopefully, this will make it appear in my 'inbox' view ...
2018-01-12 04:59 AM
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
2018-01-12 05:52 AM
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:
2018-01-12 06:05 AM
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.
2018-01-12 06:07 AM
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.
2018-01-12 06:11 AM
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?
2018-01-12 06:24 AM
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.
2018-01-12 06:30 AM
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 ...
2018-01-12 06:40 AM
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