Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 13:43 29 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : I2C interrupts?

Author Message
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9308
Posted: 02:43am 10 May 2014
Copy link to clipboard 
Print this post

Can I2C use interrupts?

From my other thread on the model elevator:

  Quote  
I need to play with I2C, so this project will help with that, so at this time anyway, I am planning to use I2C. I also need to study I2C a bit more in terms of if you can setup interrupts with it like you can with serial ports or standard pins - I might need some handshaking pins between the chips(as interrupts) to tell the other chip that they want to talk on the I2C bus.


Am I correct in assuming that you cannot have an I2C interrupt by default, as the norm is that if you want to write to or read from an I2C device, this is normally at a known time, so interrupts are not supported natively by the I2C bus by default.

Yes?
No?

Based on the above, I was still planning to use I2C(so that I get some practise with it), but - for example - if the slave wanted to send something to the master, and the master was busy in another loop somewhere, it could first signal the master by way of standard IO pin interrupt(output pin on slave, connected to input pin on master configured to use interrupts) - which would cause the master to immediately process whatever the slave wanted to send to it - and vice versa.

Is this a workable solution, or is there a better way do you think?

I would not need to transfer more then a handful of bytes, so I am planning at this stage, to use 100kHz "I2C SLOW" speed, as it is much more forgiving then the faster speed is.

Not sure you can work things this way, as an I2C slave is PROBABLY a single-purpose device by design. In other words, the I2C slave is forever waiting for instructions from the master, so may not be able to do anything else, if configured as a slave device.

Yes?
No?

EDIT: From the uM manual, page 60:

  Quote  
‘send_int’ is the line number or label of a send interrupt routine to be
invoked when the module has detected that the master is expecting data.

‘rcv_int is the line number or label of a receive interrupt routine to be
invoked when the module has received data from the master.


I'm just trying to get my head around the wording here.

Does this mean that 'send_int' is the interrupt routine in the SLAVE uM code, which will happen whenever the MASTER tries to read anything from the SLAVE?

Does this mean that 'rcv_int' is the interrupt routine in the SLAVE uM code, which will happen whenever the MASTER has sent the SLAVE something on the bus?

Edited by Grogster 2014-05-11
Smoke makes things work. When the smoke gets out, it stops!
 
atmega8

Guru

Joined: 19/11/2013
Location: Germany
Posts: 722
Posted: 03:11am 10 May 2014
Copy link to clipboard 
Print this post

I2C is not Interrupt driven, caus there is no need for Interrupts.

You are the master of desaster and you write or read to the devices when you want to.
I2C was developed by Phillips, now nxp.

you should read and UNDERSTAND the attached PDF (link)

It is not that difficult, you can even drink beer while reading this docu;
how much depends on your Training;-)

how i2c works

Dietmar
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 04:39am 10 May 2014
Copy link to clipboard 
Print this post

Only initiate messages and never receive -> Master

Initiate messages but can also receive messages on unknown times -> Slave and assume Master role only when sending messages and back to slave mode when finished.

Edited by TZAdvantage 2014-05-11
Microblocks. Build with logic.
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3196
Posted: 07:28am 10 May 2014
Copy link to clipboard 
Print this post

The master is not interrupt driven - if you want to send or receive something you have to use the I2C commands in your program.

The slave IS interrupt driven because the master controls what the slave must do, either by sending data to the slave or requesting data from the slave.

  Quote  Does this mean that 'send_int' is the interrupt routine in the SLAVE uM code, which will happen whenever the MASTER tries to read anything from the SLAVE?

Does this mean that 'rcv_int' is the interrupt routine in the SLAVE uM code, which will happen whenever the MASTER has sent the SLAVE something on the bus?


Yes, this is exactly correct. Because the master controls what the slave I2C does there is no way for the slave to signal back to the master. This means that the master would have to poll (which is inefficient) or be interrupted by the slave chip raising an I/O line (exactly as you suggested).

  Quote  Not sure you can work things this way, as an I2C slave is PROBABLY a single-purpose device by design. In other words, the I2C slave is forever waiting for instructions from the master, so may not be able to do anything else, if configured as a slave device.


No, that is not correct. Because all I2C activity in the slave happens in the interrupts the main program is free to do whatever it wants. In your case this includes checking for button presses, turning on lights, etc.

Your best approach would be to implement the master/slave example program in the manual and experiment with that. Then you can expand it to suit your requirements.

Geoff
Geoff Graham - http://geoffg.net
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024