I2C Help

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

Hello , I am a bit confused ...

Assume we have a 2 masters A and B , A wants to read some stuff from B and B wants to Read Some Stuff from A ..... these 2 masters sent a start condition simultaneously , so they are now in an arbitration ..

Let`s assume that A won the arbitration and B lost it so B now has to go in Slave mode . in the datasheet as depicted below the software action should be TWCR |=(1 << TWINT) so far I have no problem , by my problem is when i started reading about the Slave transmitted mode in the datasheet it was written that " Arbitration lost in SLA+R/W as master ; own SLA+R has been received ; ack has been returned " , how could ACK be returned by B if I didn`t enable the TWEA in TWCR when converting B from Master to Slave ??? Should I have set the TWEA also in TWCR while going from Master to Slave mode ??

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I2C does not send data from one master to another. It is only master to slave.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If your talk is true , then why did they talk about Master changing into slave??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, you have to change a master to be a slave. Then the master is not a master. 

 

What you try is rarely done. You may not find anyone who has solved it.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What are you trying to say , that the I2C is used in a straightforward scenarios when Master try to communicate with too many slaves or multi-master system and a number of slaves but also masters will communicate with slaves only .....??? is that what you are trying to tell me? 
There is no complicated scenarios??

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I believe that is the expected operation. The system was originally designed for one master to many slaves. Then they made it multi-master with several masters talking to various slaves ( but always one master at any instant to one slave ). It MAY be possible to have a master turn into a slave, but this is the first attempt that I can recall being discussed here. Thus, you might not find much help. Of course, ask, as you have asked, because maybe someone did it.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Jim is trying to say that multi-master is difficult and is rarely done. UPDATE: never mind

 

The usual way I2C is used is to have a single master talk with multiple slaves. I am about to start on an idea that needs multi-master, but it is going to fail because I don't know enough about what I am doing. After a few fails, I may figure something out or change my plans.

my projects: https://github.com/epccs

Debugging is harder than programming - don’t write code you can’t debug! https://www.avrfreaks.net/forum/help-it-doesnt-work

Last Edited: Wed. Mar 25, 2020 - 08:30 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Do you have this document? https://www.nxp.com/docs/en/user...

Talks about your situation in your OP:

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

Last Edited: Wed. Mar 25, 2020 - 08:38 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think the OP's question is really: HOW do you change a master into a slave when arbitration is lost in an AVR?

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would look at util/twi.h, which has some helpful defines for an I2C state machine.

 

https://www.nongnu.org/avr-libc/user-manual/group__util__twi.html

 

The TW_MT_ARB_LOST  (and TW_MR_ARB_LOST) may be of particular interest.

 

An example of how they can be used may also be of interest.

 

https://github.com/arduino/ArduinoCore-avr/blob/master/libraries/Wire/src/utility/twi.c#L439

 

In that implementation, the ISR operates the I2C state machine; all it does is set an error code and release the bus. There are other examples around if you look.

my projects: https://github.com/epccs

Debugging is harder than programming - don’t write code you can’t debug! https://www.avrfreaks.net/forum/help-it-doesnt-work

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ron_sutherland wrote:
In that implementation, the ISR operates the I2C state machine; all it does is set an error code and release the bus.

I believe that is how the AppNote also handles it.

 

Jim

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"