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 ZealandPosts: 9308 |
Can I2C use interrupts? From my other thread on the model elevator: 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: 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? Smoke makes things work. When the smoke gets out, it stops! |
||||
atmega8 Guru Joined: 19/11/2013 Location: GermanyPosts: 722 |
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: ThailandPosts: 2209 |
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. Microblocks. Build with logic. |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3196 |
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. 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). 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 |